Skip to content
Merged
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/json-language-service-completions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openworkflowspec/language-service": minor
---

Add JSON language service plugins foundation for Open Workflow Spec
34 changes: 30 additions & 4 deletions packages/language-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,41 @@ The package provides the common infrastructure for Open Workflow language featur

## Architecture

Volar-specific code is isolated under `src/volar/`. Imports from `@volar/*` outside this directory are prevented by Oxlint.
Volar-specific code is isolated under `src/volar/`. Imports from `@volar/*` and `volar-service-*` outside this directory are prevented by Oxlint.

```text
src/
├── index.ts
── volar/
└── index.ts
├── samples/ (OWS sample documents)
── utils.ts (shared OWS utilities)
└── volar/ (Volar adapters)
```

## API

### `createJsonLanguageServicePlugins()`

Creates the default set of Volar `LanguageServicePlugin`s for Open Workflow JSON support.

It combines the schema, completion, and CodeLens plugins provided by this package.

```ts
import { createJsonLanguageServicePlugins } from "@openworkflowspec/language-service";

const plugins = createJsonLanguageServicePlugins();
```

### `createJsonSchemaLanguageServicePlugin()`

Creates the JSON language service plugin based on `volar-service-json` and the Open Workflow schema.

### `createJsonCompletionsPlugin()`

Creates the Open Workflow-specific JSON completion plugin.

### `createJsonCodeLensesPlugin()`

Creates the Open Workflow JSON CodeLens plugin.

## Development

```bash
Expand Down
7 changes: 5 additions & 2 deletions packages/language-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"test": "vitest run"
},
"dependencies": {
"@volar/language-service": "catalog:"
"@openworkflowspec/sdk": "catalog:",
"@volar/language-service": "catalog:",
"volar-service-json": "catalog:"
},
"devDependencies": {
"@types/node": "catalog:",
Expand All @@ -45,6 +47,7 @@
"rimraf": "catalog:",
"typescript": "catalog:",
"vite": "catalog:",
"vitest": "catalog:"
"vitest": "catalog:",
"vscode-languageserver-textdocument": "catalog:"
}
}
35 changes: 35 additions & 0 deletions packages/language-service/src/samples/hello-world.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021-Present The Open Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export const HELLO_WORLD_SAMPLE = `{
"document": {
"dsl": "1.0.3",
"namespace": "examples",
"name": "hello-world",
"version": "0.1.0"
},
"do": [
{
"greet": {
"call": "http",
"with": {
"method": "GET",
"endpoint": "https://httpbin.org/get"
}
}
}
]
}`;
24 changes: 24 additions & 0 deletions packages/language-service/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2021-Present The Open Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Returns true if the document content is considered an empty Open Workflow —
* i.e. the trimmed content is an empty string.
* Any other content, including bare `{}`, returns false.
*/
export function isEmptyWorkflow(text: string): boolean {
return text.trim().length === 0;
Comment thread
lornakelly marked this conversation as resolved.
}
20 changes: 20 additions & 0 deletions packages/language-service/src/volar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,27 @@ export { createLanguageService } from "@volar/language-service";

export type {
LanguageService,
LanguageServiceContext,
LanguageServiceEnvironment,
LanguageServicePlugin,
LanguageServicePluginInstance,
ProjectContext,
} from "@volar/language-service";

import { createJsonSchemaLanguageServicePlugin } from "./json/schema";
import { createJsonCompletionsPlugin } from "./json/completions";
import { createJsonCodeLensesPlugin } from "./json/code-lenses";

export {
createJsonSchemaLanguageServicePlugin,
createJsonCompletionsPlugin,
createJsonCodeLensesPlugin,
};

export function createJsonLanguageServicePlugins() {
return [
createJsonSchemaLanguageServicePlugin(),
createJsonCompletionsPlugin(),
createJsonCodeLensesPlugin(),
];
}
48 changes: 48 additions & 0 deletions packages/language-service/src/volar/json/code-lenses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2021-Present The Open Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { LanguageServicePlugin } from "@volar/language-service";
import { isEmptyWorkflow } from "../../utils";

export function createJsonCodeLensesPlugin(): LanguageServicePlugin {
return {
capabilities: {
codeLensProvider: {},
},
create() {
return {
provideCodeLenses(document) {
if (document.languageId !== "json" || !isEmptyWorkflow(document.getText())) {
Comment thread
lornakelly marked this conversation as resolved.
return null;
}

return [
{
range: {
start: { line: 0, character: 0 },
end: { line: 0, character: 0 },
},
command: {
title: "Create an Open Workflow",
command: "openworkflow.insertHelloWorld",
},
},
];
},
};
},
};
}
57 changes: 57 additions & 0 deletions packages/language-service/src/volar/json/completions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2021-Present The Open Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { LanguageServicePlugin, LanguageServicePluginInstance } from "@volar/language-service";
import { HELLO_WORLD_SAMPLE } from "../../samples/hello-world";
import { isEmptyWorkflow } from "../../utils";

// CompletionItemKind.Snippet = 15 (LSP spec, cast needed because kind is a const enum)
const SNIPPET_KIND = 15;

const EMPTY_RANGE = {
start: { line: 0, character: 0 },
end: { line: 0, character: 0 },
};

export function createJsonCompletionsPlugin(): LanguageServicePlugin {
return {
capabilities: {
completionProvider: {},
},
create(): LanguageServicePluginInstance {
return {
isAdditionalCompletion: true,
provideCompletionItems(document) {
if (document.languageId !== "json" || !isEmptyWorkflow(document.getText())) {
return null;
}

return {
isIncomplete: false,
items: [
{
label: "Insert Hello World workflow",
kind: SNIPPET_KIND as 15,
detail: "Insert a Hello World Open Workflow document",
Comment thread
lornakelly marked this conversation as resolved.
textEdit: { range: EMPTY_RANGE, newText: HELLO_WORLD_SAMPLE },
},
],
};
},
};
},
};
}
37 changes: 37 additions & 0 deletions packages/language-service/src/volar/json/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2021-Present The Open Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { LanguageServicePlugin } from "@volar/language-service";
import { create } from "volar-service-json";
import { workflowSchema } from "@openworkflowspec/sdk";

const DEFAULT_SCHEMA_URI = "urn:open-workflow-specification:workflow-schema";

export function createJsonSchemaLanguageServicePlugin(): LanguageServicePlugin {
return create({
getLanguageSettings() {
return {
schemas: [
{
uri: workflowSchema.$id || DEFAULT_SCHEMA_URI,
fileMatch: ["*.json"],
Comment thread
fantonangeli marked this conversation as resolved.
schema: workflowSchema,
Comment thread
fantonangeli marked this conversation as resolved.
Comment thread
fantonangeli marked this conversation as resolved.
},
],
};
},
});
}
Loading