Skip to content

Commit 64b9e07

Browse files
WinPlay02megalinter-botlars-reimann
authored
feat: Source Maps for Code Generation (#714)
Closes #30 ### Summary of Changes - changed code generation to return traced nodes instead of text - add option to generate source maps by providing an optional path --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Co-authored-by: Lars Reimann <mail@larsreimann.com>
1 parent ac6d42a commit 64b9e07

File tree

38 files changed

+407
-154
lines changed

38 files changed

+407
-154
lines changed

package-lock.json

+23-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/safe-ds-cli/src/cli/generate.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import fs from 'node:fs';
66
import path from 'node:path';
77
import { extractDocument } from './cli-util.js';
88

9-
export const generate = async (fileName: string, opts: GenerateOptions): Promise<void> => {
9+
export const generate = async (fileName: string, opts: CliGenerateOptions): Promise<void> => {
1010
const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
1111
const document = await extractDocument(fileName, services);
1212
const destination = opts.destination ?? path.join(path.dirname(fileName), 'generated');
13-
const generatedFiles = services.generation.PythonGenerator.generate(document, URI.file(path.resolve(destination)));
13+
const generatedFiles = services.generation.PythonGenerator.generate(document, {
14+
destination: URI.file(path.resolve(destination)),
15+
createSourceMaps: opts.sourcemaps,
16+
});
1417

1518
for (const file of generatedFiles) {
1619
const fsPath = URI.parse(file.uri).fsPath;
@@ -25,6 +28,8 @@ export const generate = async (fileName: string, opts: GenerateOptions): Promise
2528
console.log(chalk.green(`Python code generated successfully.`));
2629
};
2730

28-
export interface GenerateOptions {
31+
export interface CliGenerateOptions {
2932
destination?: string;
33+
sourcemaps: boolean;
34+
quiet: boolean;
3035
}

packages/safe-ds-cli/src/cli/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ program
2222
.option('-d, --destination <dir>', 'destination directory of generation')
2323
.option('-r, --root <dir>', 'source root folder')
2424
.option('-q, --quiet', 'whether the program should print something', false)
25+
.option('-s, --sourcemaps', 'whether source maps should be generated', false)
2526
.description('generate Python code')
2627
.action(generate);
2728

packages/safe-ds-lang/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"chevrotain": "^11.0.3",
4848
"glob": "^10.3.10",
4949
"langium": "^2.1.0",
50+
"source-map": "^0.7.4",
5051
"vscode-languageserver": "^9.0.1",
5152
"vscode-languageserver-textdocument": "^1.0.11"
5253
},

0 commit comments

Comments
 (0)