Skip to content

Commit

Permalink
feat: run pipeline via code lens (#1068)
Browse files Browse the repository at this point in the history
### Summary of Changes

Pipeline runs are now triggered via a code lens instead of a button.
Unlike the button, these don't show up when the runner is not available.
They also make it more obvious *which* pipeline is being run.
  • Loading branch information
lars-reimann authored Apr 19, 2024
1 parent aa43316 commit 392154d
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CodeLensProvider } from 'langium/lsp';
import { CancellationToken, CodeLens, type CodeLensParams } from 'vscode-languageserver';
import { SafeDsServices } from '../safe-ds-module.js';
import { SafeDsTypeComputer } from '../typing/safe-ds-type-computer.js';
import { AstNodeLocator, AstUtils, interruptAndCheck, LangiumDocument } from 'langium';
import { isSdsModule, isSdsPipeline, SdsModuleMember, SdsPlaceholder } from '../generated/ast.js';
import { AstNode, AstNodeLocator, AstUtils, interruptAndCheck, LangiumDocument } from 'langium';
import { isSdsModule, isSdsPipeline, SdsModuleMember, SdsPipeline, SdsPlaceholder } from '../generated/ast.js';
import { SafeDsRunner } from '../runner/safe-ds-runner.js';
import { getModuleMembers, streamPlaceholders } from '../helpers/nodeProperties.js';
import { SafeDsTypeChecker } from '../typing/safe-ds-type-checker.js';
Expand Down Expand Up @@ -53,13 +53,32 @@ export class SafeDsCodeLensProvider implements CodeLensProvider {
cancelToken: CancellationToken = CancellationToken.None,
): Promise<void> {
if (isSdsPipeline(node)) {
await this.computeCodeLensForPipeline(node, accept);

for (const placeholder of streamPlaceholders(node.body)) {
await interruptAndCheck(cancelToken);
await this.computeCodeLensForPlaceholder(placeholder, accept);
}
}
}

private async computeCodeLensForPipeline(node: SdsPipeline, accept: CodeLensAcceptor): Promise<void> {
const cstNode = node.$cstNode;
if (!cstNode) {
/* c8 ignore next 2 */
return;
}

accept({
range: cstNode.range,
command: {
title: `Run ${node.name}`,
command: 'safe-ds.runPipeline',
arguments: this.computeNodeId(node),
},
});
}

private async computeCodeLensForPlaceholder(node: SdsPlaceholder, accept: CodeLensAcceptor): Promise<void> {
const cstNode = node.$cstNode;
if (!cstNode) {
Expand All @@ -68,19 +87,22 @@ export class SafeDsCodeLensProvider implements CodeLensProvider {
}

if (this.typeChecker.isTabular(this.typeComputer.computeType(node))) {
const documentUri = AstUtils.getDocument(node).uri.toString();
const nodePath = this.astNodeLocator.getAstNodePath(node);

accept({
range: cstNode.range,
command: {
title: `Explore ${node.name}`,
command: 'safe-ds.runEda',
arguments: [documentUri, nodePath],
command: 'safe-ds.exploreTable',
arguments: this.computeNodeId(node),
},
});
}
}

private computeNodeId(node: AstNode): [string, string] {
const documentUri = AstUtils.getDocument(node).uri;
const nodePath = this.astNodeLocator.getAstNodePath(node);
return [documentUri.toString(), nodePath];
}
}

type CodeLensAcceptor = (codeLens: CodeLens) => void;
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ describe('SafeDsCodeLensProvider', () => {
{
testName: 'empty pipeline',
code: 'pipeline myPipeline {}',
expectedCodeLensTitles: [],
expectedCodeLensTitles: ['Run myPipeline'],
},
{
testName: 'pipeline with Int placeholder',
code: `pipeline myPipeline {
val a = 1;
}`,
expectedCodeLensTitles: [],
expectedCodeLensTitles: ['Run myPipeline'],
},
{
testName: 'pipeline with Table placeholder',
code: `pipeline myPipeline {
val a = Table();
}`,
expectedCodeLensTitles: ['Explore a'],
expectedCodeLensTitles: ['Run myPipeline', 'Explore a'],
},
{
testName: 'block lambda with Table placeholder',
Expand All @@ -42,7 +42,7 @@ describe('SafeDsCodeLensProvider', () => {
val a = Table();
};
}`,
expectedCodeLensTitles: [],
expectedCodeLensTitles: ['Run myPipeline'],
},
{
testName: 'segment with Table placeholder',
Expand Down
15 changes: 0 additions & 15 deletions packages/safe-ds-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,6 @@
"files.trimTrailingWhitespace": true
}
},
"menus": {
"editor/title/run": [
{
"command": "safe-ds.runPipelineFile",
"when": "resourceLangId == safe-ds",
"group": "navigation@1"
}
]
},
"commands": [
{
"command": "safe-ds.dumpDiagnostics",
Expand All @@ -269,12 +260,6 @@
"title": "Refresh Webview",
"category": "Safe-DS"
},
{
"command": "safe-ds.runPipelineFile",
"title": "Run Pipeline",
"category": "Safe-DS",
"icon": "$(play)"
},
{
"command": "safe-ds.updateRunner",
"title": "Update the Safe-DS Runner",
Expand Down
Loading

0 comments on commit 392154d

Please sign in to comment.