Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/vast-actors-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow/typescript-plugin": patch
---

suggest "use workflow" and "use step" in directive autocomplete
1 change: 1 addition & 0 deletions packages/typescript-plugin/src/code-fixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function getCodeFixes(

fixes.push({
fixName: 'fix-directive-typo',
fixId: 'workflow--fix-directive-typo',
description: `Replace with '${expectedDirective}'`,
changes: [change],
});
Expand Down
44 changes: 42 additions & 2 deletions packages/typescript-plugin/src/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,55 @@ export function enhanceCompletions(
program: ts.Program,
ts: typeof import('typescript/lib/tsserverlibrary')
): ts.WithMetadata<ts.CompletionInfo> | undefined {
if (!prior) return prior;

const sourceFile = program.getSourceFile(fileName);
if (!sourceFile) return prior;

// Find the enclosing function
const node = findNodeAtPosition(sourceFile, position);

if (!node) return prior;

if (
node.parent.getChildAt(0) === node &&
node.kind === ts.SyntaxKind.StringLiteral
Comment on lines +20 to +21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we validate if we are in a function declaration or arrow expression?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct

) {
// return `"use workflow"` or `"use step"` completions
return {
...prior,
entries: [
{
name: '"use workflow"',
kind: ts.ScriptElementKind.string,
kindModifiers: '',
sortText: '0',
labelDetails: {
description: 'Marks the function as a workflow',
},
source: 'Workflow Development Kit',
insertText: '"use workflow";',
replacementSpan: { start: node.getStart(), length: node.getWidth() },
isRecommended: true,
},
{
name: '"use step"',
kind: ts.ScriptElementKind.string,
kindModifiers: '',
sortText: '0',
insertText: '"use step";',
labelDetails: {
description: 'Marks the function as a step',
},
source: 'Workflow Development Kit',
replacementSpan: { start: node.getStart(), length: node.getWidth() },
isRecommended: true,
},
...(prior ? prior.entries : []),
],
};
}

if (!prior) return prior;

const enclosingFunction = findEnclosingFunction(node);
if (!enclosingFunction) return prior;

Expand Down
1 change: 1 addition & 0 deletions packages/world-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@types/node": "catalog:",
"@types/jsonlines": "^0.1.5",
"@workflow/tsconfig": "workspace:*",
"@workflow/typescript-plugin": "workspace:*",
"vitest": "catalog:"
},
"peerDependencies": {
Expand Down
9 changes: 7 additions & 2 deletions packages/world-testing/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
"moduleResolution": "NodeNext",
"allowJs": true,
"module": "NodeNext",
"outDir": "dist"
"outDir": "dist",
"plugins": [
{
"name": "workflow"
}
]
},
"include": ["src", ".well-known"],
"include": ["src", ".well-known", "workflows"],
"exclude": ["node_modules", "**/*.test.ts"]
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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