Skip to content

Commit

Permalink
refactor: turn Python generator into a service
Browse files Browse the repository at this point in the history
Co-authored-by: WinPlay02 <[email protected]>
  • Loading branch information
lars-reimann and WinPlay02 committed Oct 25, 2023
1 parent 60112bf commit ef77107
Show file tree
Hide file tree
Showing 8 changed files with 664 additions and 648 deletions.
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"langium": "^2.0.2",
"true-myth": "^7.1.0",
"vscode-languageclient": "^9.0.1",
"vscode-languageserver": "^9.0.1"
"vscode-languageserver": "^9.0.1",
"vscode-languageserver-textdocument": "^1.0.11"
},
"devDependencies": {
"@lars-reimann/eslint-config": "^5.1.4",
Expand Down
24 changes: 2 additions & 22 deletions src/cli/cli-util.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import chalk from 'chalk';
import path from 'path';
import fs from 'fs';
import { AstNode, LangiumDocument, LangiumServices, URI } from 'langium';
import { LangiumDocument, LangiumServices, URI } from 'langium';

/* c8 ignore start */
export const extractAstNode = async function <T extends AstNode>(
fileName: string,
services: LangiumServices,
): Promise<T> {
return (await extractDocument(fileName, services)).parseResult?.value as T;
};

export const extractDocument = async function (fileName: string, services: LangiumServices): Promise<LangiumDocument> {
const extensions = services.LanguageMetaData.fileExtensions;
if (!extensions.includes(path.extname(fileName))) {
Expand Down Expand Up @@ -45,19 +38,6 @@ export const extractDocument = async function (fileName: string, services: Langi
process.exit(1);
}

return document;
return document as LangiumDocument;
};
/* c8 ignore stop */

interface FilePathData {
destination: string;
name: string;
}

export const extractDestinationAndName = function (filePath: string, destination: string | undefined): FilePathData {
const baseFilePath = path.basename(filePath, path.extname(filePath)).replace(/[.-]/gu, '');
return {
destination: destination ?? path.join(path.dirname(baseFilePath), 'generated'),
name: path.basename(baseFilePath),
};
};
Loading

0 comments on commit ef77107

Please sign in to comment.