Skip to content

Commit 72d7f1b

Browse files
committed
ts plugin: Suggest 'use workflow' and 'use step' autocomplete
also: add a fix id for the typo code fix so it won't be repeated.
1 parent e20b4ff commit 72d7f1b

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

packages/typescript-plugin/src/code-fixes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export function getCodeFixes(
7777

7878
fixes.push({
7979
fixName: 'fix-directive-typo',
80+
fixId: 'workflow--fix-directive-typo',
8081
description: `Replace with '${expectedDirective}'`,
8182
changes: [change],
8283
});

packages/typescript-plugin/src/completions.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,55 @@ export function enhanceCompletions(
88
program: ts.Program,
99
ts: typeof import('typescript/lib/tsserverlibrary')
1010
): ts.WithMetadata<ts.CompletionInfo> | undefined {
11-
if (!prior) return prior;
12-
1311
const sourceFile = program.getSourceFile(fileName);
1412
if (!sourceFile) return prior;
1513

1614
// Find the enclosing function
1715
const node = findNodeAtPosition(sourceFile, position);
16+
1817
if (!node) return prior;
1918

19+
if (
20+
node.parent.getChildAt(0) === node &&
21+
node.kind === ts.SyntaxKind.StringLiteral
22+
) {
23+
// return `"use workflow"` or `"use step"` completions
24+
return {
25+
...prior,
26+
entries: [
27+
{
28+
name: '"use workflow"',
29+
kind: ts.ScriptElementKind.string,
30+
kindModifiers: '',
31+
sortText: '0',
32+
labelDetails: {
33+
description: 'Marks the function as a workflow',
34+
},
35+
source: 'Workflow Development Kit',
36+
insertText: '"use workflow";',
37+
replacementSpan: { start: node.getStart(), length: node.getWidth() },
38+
isRecommended: true,
39+
},
40+
{
41+
name: '"use step"',
42+
kind: ts.ScriptElementKind.string,
43+
kindModifiers: '',
44+
sortText: '0',
45+
insertText: '"use step";',
46+
labelDetails: {
47+
description: 'Marks the function as a step',
48+
},
49+
source: 'Workflow Development Kit',
50+
replacementSpan: { start: node.getStart(), length: node.getWidth() },
51+
isRecommended: true,
52+
},
53+
...(prior ? prior.entries : []),
54+
],
55+
};
56+
}
57+
58+
if (!prior) return prior;
59+
2060
const enclosingFunction = findEnclosingFunction(node);
2161
if (!enclosingFunction) return prior;
2262

packages/world-testing/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@types/node": "catalog:",
3333
"@types/jsonlines": "^0.1.5",
3434
"@workflow/tsconfig": "workspace:*",
35+
"@workflow/typescript-plugin": "workspace:*",
3536
"vitest": "catalog:"
3637
},
3738
"peerDependencies": {

packages/world-testing/tsconfig.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
"moduleResolution": "NodeNext",
55
"allowJs": true,
66
"module": "NodeNext",
7-
"outDir": "dist"
7+
"outDir": "dist",
8+
"plugins": [
9+
{
10+
"name": "workflow"
11+
}
12+
]
813
},
9-
"include": ["src", ".well-known"],
14+
"include": ["src", ".well-known", "workflows"],
1015
"exclude": ["node_modules", "**/*.test.ts"]
1116
}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)