From 3e625b81cd36ef6cd5a1cedf2fd914e5bcbd7b87 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Wed, 28 Feb 2024 10:26:47 +0100 Subject: [PATCH 1/4] feat: change categories of existing commands --- packages/safe-ds-vscode/package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/safe-ds-vscode/package.json b/packages/safe-ds-vscode/package.json index b2ac82208..6bfed5e76 100644 --- a/packages/safe-ds-vscode/package.json +++ b/packages/safe-ds-vscode/package.json @@ -132,21 +132,21 @@ ] }, "commands": [ - { - "command": "safe-ds.runPipelineFile", - "title": "Run Pipeline", - "category": "Safe-DS", - "icon": "$(play)" - }, { "command": "safe-ds.refreshWebview", "title": "Refresh Webview", - "category": "EDA" + "category": "Safe-DS" }, { "command": "safe-ds.runEdaFromContext", "title": "Explore Table", - "category": "EDA" + "category": "Safe-DS" + }, + { + "command": "safe-ds.runPipelineFile", + "title": "Run Pipeline", + "category": "Safe-DS", + "icon": "$(play)" } ], "snippets": [ From 905e3592c32d0f104e33067e35023be5b1f729a0 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Wed, 28 Feb 2024 13:37:08 +0100 Subject: [PATCH 2/4] feat: VS Code command to dump diagnostics of active file to JSON --- packages/safe-ds-vscode/package.json | 5 ++ .../src/extension/commands/dumpDiagnostics.ts | 48 +++++++++++++++++++ .../src/extension/mainClient.ts | 3 ++ 3 files changed, 56 insertions(+) create mode 100644 packages/safe-ds-vscode/src/extension/commands/dumpDiagnostics.ts diff --git a/packages/safe-ds-vscode/package.json b/packages/safe-ds-vscode/package.json index 6bfed5e76..84f11f861 100644 --- a/packages/safe-ds-vscode/package.json +++ b/packages/safe-ds-vscode/package.json @@ -132,6 +132,11 @@ ] }, "commands": [ + { + "command": "safe-ds.dumpDiagnostics", + "title": "Dump Diagnostics to JSON", + "category": "Safe-DS" + }, { "command": "safe-ds.refreshWebview", "title": "Refresh Webview", diff --git a/packages/safe-ds-vscode/src/extension/commands/dumpDiagnostics.ts b/packages/safe-ds-vscode/src/extension/commands/dumpDiagnostics.ts new file mode 100644 index 000000000..46c65dbc0 --- /dev/null +++ b/packages/safe-ds-vscode/src/extension/commands/dumpDiagnostics.ts @@ -0,0 +1,48 @@ +import vscode, { ExtensionContext, Uri } from 'vscode'; + +export const dumpDiagnostics = (context: ExtensionContext) => async () => { + // Get the current document + const currentDocument = vscode.window.activeTextEditor?.document; + if (!currentDocument) { + vscode.window.showErrorMessage('No active document.'); + return; + } else if (currentDocument.languageId !== 'safe-ds') { + vscode.window.showErrorMessage('The active document is not a Safe-DS document.'); + return; + } + + // Get diagnostics for the current document + const diagnostics = vscode.languages.getDiagnostics(currentDocument.uri); + if (diagnostics.length === 0) { + vscode.window.showErrorMessage('The active document has no diagnostics.'); + return; + } + + // Dump diagnostics to a file + const uri = vscode.Uri.joinPath(diagnosticsDumpsUri(context), `${basicISOTimestamp()}.json`); + const content = JSON.stringify( + { + text: currentDocument.getText(), + diagnostics, + }, + null, + 2, + ); + + await vscode.workspace.fs.writeFile(uri, Buffer.from(content)); + + // Inform the user and ask for further action + const item = await vscode.window.showInformationMessage(`Diagnostics successfully dumped.`, 'Open file', 'Close'); + + if (item === 'Open file') { + vscode.window.showTextDocument(uri); + } +}; + +export const diagnosticsDumpsUri = (context: ExtensionContext): Uri => { + return vscode.Uri.joinPath(context.globalStorageUri, 'diagnosticsDumps'); +}; + +const basicISOTimestamp = (): string => { + return new Date().toISOString().replaceAll(/[-:]/gu, ''); +}; diff --git a/packages/safe-ds-vscode/src/extension/mainClient.ts b/packages/safe-ds-vscode/src/extension/mainClient.ts index 801985e29..6f04d7477 100644 --- a/packages/safe-ds-vscode/src/extension/mainClient.ts +++ b/packages/safe-ds-vscode/src/extension/mainClient.ts @@ -8,6 +8,7 @@ import { getSafeDSOutputChannel, initializeLog, logError, logOutput, printOutput import crypto from 'crypto'; import { LangiumDocument, URI } from 'langium'; import { EDAPanel, undefinedPanelIdentifier } from './eda/edaPanel.ts'; +import { dumpDiagnostics } from './commands/dumpDiagnostics.js'; let client: LanguageClient; let services: SafeDsServices; @@ -153,6 +154,8 @@ const registerVSCodeCommands = function (context: vscode.ExtensionContext) { }); }; + context.subscriptions.push(vscode.commands.registerCommand('safe-ds.dumpDiagnostics', dumpDiagnostics(context))); + context.subscriptions.push(vscode.commands.registerCommand('safe-ds.runPipelineFile', commandRunPipelineFile)); context.subscriptions.push( From a6998b0091ad084925673a310884ab21569a6dd9 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Wed, 28 Feb 2024 14:05:00 +0100 Subject: [PATCH 3/4] feat: VS Code command to open diagnostic dumps in new window --- packages/safe-ds-vscode/package.json | 5 +++++ .../src/extension/commands/openDiagnosticsDumps.ts | 7 +++++++ packages/safe-ds-vscode/src/extension/mainClient.ts | 4 ++++ 3 files changed, 16 insertions(+) create mode 100644 packages/safe-ds-vscode/src/extension/commands/openDiagnosticsDumps.ts diff --git a/packages/safe-ds-vscode/package.json b/packages/safe-ds-vscode/package.json index 84f11f861..44b3d9217 100644 --- a/packages/safe-ds-vscode/package.json +++ b/packages/safe-ds-vscode/package.json @@ -137,6 +137,11 @@ "title": "Dump Diagnostics to JSON", "category": "Safe-DS" }, + { + "command": "safe-ds.openDiagnosticsDumps", + "title": "Open Diagnostics Dumps in New VS Code Window", + "category": "Safe-DS" + }, { "command": "safe-ds.refreshWebview", "title": "Refresh Webview", diff --git a/packages/safe-ds-vscode/src/extension/commands/openDiagnosticsDumps.ts b/packages/safe-ds-vscode/src/extension/commands/openDiagnosticsDumps.ts new file mode 100644 index 000000000..df049af46 --- /dev/null +++ b/packages/safe-ds-vscode/src/extension/commands/openDiagnosticsDumps.ts @@ -0,0 +1,7 @@ +import vscode, { ExtensionContext } from 'vscode'; +import { diagnosticsDumpsUri } from './dumpDiagnostics.js'; + +export const openDiagnosticsDumps = (context: ExtensionContext) => async () => { + const uri = diagnosticsDumpsUri(context); + vscode.commands.executeCommand('vscode.openFolder', uri, { forceNewWindow: true }); +}; diff --git a/packages/safe-ds-vscode/src/extension/mainClient.ts b/packages/safe-ds-vscode/src/extension/mainClient.ts index 6f04d7477..1b3e54d43 100644 --- a/packages/safe-ds-vscode/src/extension/mainClient.ts +++ b/packages/safe-ds-vscode/src/extension/mainClient.ts @@ -9,6 +9,7 @@ import crypto from 'crypto'; import { LangiumDocument, URI } from 'langium'; import { EDAPanel, undefinedPanelIdentifier } from './eda/edaPanel.ts'; import { dumpDiagnostics } from './commands/dumpDiagnostics.js'; +import { openDiagnosticsDumps } from './commands/openDiagnosticsDumps.js'; let client: LanguageClient; let services: SafeDsServices; @@ -155,6 +156,9 @@ const registerVSCodeCommands = function (context: vscode.ExtensionContext) { }; context.subscriptions.push(vscode.commands.registerCommand('safe-ds.dumpDiagnostics', dumpDiagnostics(context))); + context.subscriptions.push( + vscode.commands.registerCommand('safe-ds.openDiagnosticsDumps', openDiagnosticsDumps(context)), + ); context.subscriptions.push(vscode.commands.registerCommand('safe-ds.runPipelineFile', commandRunPipelineFile)); From ea111fdcd9636cf9e3a11492e25deda42986a694 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Wed, 28 Feb 2024 14:11:13 +0100 Subject: [PATCH 4/4] feat: also store timestamp and machine id --- .../src/extension/commands/dumpDiagnostics.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/safe-ds-vscode/src/extension/commands/dumpDiagnostics.ts b/packages/safe-ds-vscode/src/extension/commands/dumpDiagnostics.ts index 46c65dbc0..b39d89ae1 100644 --- a/packages/safe-ds-vscode/src/extension/commands/dumpDiagnostics.ts +++ b/packages/safe-ds-vscode/src/extension/commands/dumpDiagnostics.ts @@ -19,9 +19,14 @@ export const dumpDiagnostics = (context: ExtensionContext) => async () => { } // Dump diagnostics to a file - const uri = vscode.Uri.joinPath(diagnosticsDumpsUri(context), `${basicISOTimestamp()}.json`); + const machineId = vscode.env.machineId; + const timestamp = new Date(); + const fileName = `${machineId}-${toBasicISOString(timestamp)}.json`; + const uri = vscode.Uri.joinPath(diagnosticsDumpsUri(context), fileName); const content = JSON.stringify( { + machineId, + timestamp: timestamp.toISOString(), text: currentDocument.getText(), diagnostics, }, @@ -43,6 +48,6 @@ export const diagnosticsDumpsUri = (context: ExtensionContext): Uri => { return vscode.Uri.joinPath(context.globalStorageUri, 'diagnosticsDumps'); }; -const basicISOTimestamp = (): string => { - return new Date().toISOString().replaceAll(/[-:]/gu, ''); +const toBasicISOString = (date: Date): string => { + return date.toISOString().replaceAll(/[-:]/gu, ''); };