Skip to content

Commit

Permalink
extension: first cut of lsp-aware extension
Browse files Browse the repository at this point in the history
This gives the vscode-cue extension the basic capabilities to start an
instance of 'cue lsp'. The code is heavily commented to:

* caveat my poor handle on TypeScript;
* explain the code structure of the extension;
* capture my understanding and assumptions about the behaviour of VSCode
  and an extension instance in relation to a running LSP server;
* state opinions/assumptions about error handling style in code.
* state understanding about the best method of handling runtime errors,
  and how/when to report those to the user.

The bulk of the changes sit within src/main.ts:

* The extension creates a LanguageClient instance which is the bridge
  between a running 'cue lsp' instance (which it, the LanguageClient
  starts) and a VSCode window.
* We use output channels for more clear logging of info and errors.
* We establish a clearer policy on when to notify the end user of errors
  via showErrorMessage.
* We handle runtime configuration changes of an extension instance.

There are various other helper functions, types etc in support of these
changes.

At an extension configuration level this change:

* Exposes two additional commands: start CUE LSP, stop CUE LSP;
* aligns the engine version required by the extension with the npm
  dependency on the VSCode types;
* sets an explicit activation event of 'onLanguage:cue', so an instance
  of the extension is created whenever a CUE file is opened. Note the
  comment 'Extension instances and configuration' on caveats in this
  space;
* exposes the extension's configuration schema as a JSON Schema. A TODO
  captures moving this to CUE when we can (noting that we also need to
  code generate TypeScript ultimately, as well as runtime unifying a
  configuration value with some documented defaults).

We also add various npm dependencies required by the code changes
described above.

Note that this change does not include any tests. This is intentional
however undesirable. Adding end-to-end tests will follow later. For now,
testing is limited to offline running through various scenarios using
VSCode. The scenarios covered are documented in testing.md.

Signed-off-by: Paul Jolly <[email protected]>
Change-Id: I6a1879a603ff2db693f045d26fe14018c01c6332
Reviewed-on: https://review.gerrithub.io/c/cue-lang/vscode-cue/+/1201041
Reviewed-by: Matthew Sackman <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
myitcv committed Dec 4, 2024
1 parent ffd124d commit 944ec28
Show file tree
Hide file tree
Showing 9 changed files with 950 additions and 45 deletions.
1 change: 1 addition & 0 deletions extension/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ launch.json
src/test
esbuild.js
tsconfig.json
testing.md

# Legacy files generated as part of skeleton - useful for reference only.
_generated
50 changes: 44 additions & 6 deletions extension/extension.cue
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ extension: npm: {
icon: "media/white_circle_128.png"
license: "MIT"
publisher: "cuelangorg"
engines: vscode: ">=1.63.0"
engines: vscode: ">=\(devDependencies["@types/vscode"])"
categories: [
"Programming Languages",
]
activationEvents: []
activationEvents: [
"onLanguage:cue",
]
main: "./dist/main.js"
contributes: {
languages: [{
Expand All @@ -30,10 +32,46 @@ extension: npm: {
path: "./syntaxes/cue.tmLanguage.json"
embeddedLanguages: "source.cue.embedded": "source.cue"
}]
commands: [{
command: "vscode-cue.welcome"
title: "CUE: Welcome"
}]
commands: [
{
command: "vscode-cue.welcome"
title: "CUE: Welcome"
},
{
command: "vscode-cue.startlsp"
title: "CUE: Start CUE LSP"
},
{
command: "vscode-cue.stoplsp"
title: "CUE: Stop CUE LSP"
},
]

// TODO(myitcv): maintain this schema as CUE, and export to JSON Schema
// when generating package.json when CUE can do this. Doing so will also
// require a more complete understanding of the dot-separated field names
// used below; for example, are these top-level only?
configuration: {
type: "object"
title: "CUE"
properties: {
"cue.useLanguageServer": {
type: "boolean"
default: true
description: "Enable cue lsp, the language server for CUE."
}
"cue.languageServerCommand": {
type: "array"
default: []
description: "The command to run to launch the language server."
}
"cue.languageServerFlags": {
type: "array"
default: []
description: "Flags like -rpc.trace and -logfile to be used while running the language server."
}
}
}
}
scripts: {
"vscode:prepublish": "cue cmd genPackageJSON && npm run clean && npm run buildpackage"
Expand Down
1 change: 1 addition & 0 deletions extension/manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ dist/main.js
language-configuration.json
media/white_circle_128.png
package.json
src/extension.ts
src/main.ts
syntaxes/cue.tmLanguage.json
5 changes: 4 additions & 1 deletion extension/npm.cue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package extension
extension: npm: devDependencies: {
"@types/mocha": "10.0.7"
"@types/node": "22.9.1"
"@types/vscode": "1.63.0"
"@types/vscode": "1.85.0"
"@typescript-eslint/eslint-plugin": "7.14.1"
"@typescript-eslint/parser": "7.11.0"
"@vscode/test-cli": "0.0.9"
Expand All @@ -13,4 +13,7 @@ extension: npm: devDependencies: {
eslint: "8.57.0"
"npm-run-all": "4.1.5"
typescript: "5.4.5"
"@types/which": "3.0.4"
"vscode-languageclient": "9.0.1"
which: "5.0.0"
}
116 changes: 104 additions & 12 deletions extension/package-lock.json

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

44 changes: 39 additions & 5 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"license": "MIT",
"publisher": "cuelangorg",
"engines": {
"vscode": ">=1.63.0"
"vscode": ">=1.85.0"
},
"categories": [
"Programming Languages"
],
"activationEvents": [],
"activationEvents": [
"onLanguage:cue"
],
"main": "./dist/main.js",
"contributes": {
"languages": [
Expand Down Expand Up @@ -43,8 +45,37 @@
{
"command": "vscode-cue.welcome",
"title": "CUE: Welcome"
},
{
"command": "vscode-cue.startlsp",
"title": "CUE: Start CUE LSP"
},
{
"command": "vscode-cue.stoplsp",
"title": "CUE: Stop CUE LSP"
}
],
"configuration": {
"type": "object",
"title": "CUE",
"properties": {
"cue.useLanguageServer": {
"type": "boolean",
"default": true,
"description": "Enable cue lsp, the language server for CUE."
},
"cue.languageServerCommand": {
"type": "array",
"default": [],
"description": "The command to run to launch the language server."
},
"cue.languageServerFlags": {
"type": "array",
"default": [],
"description": "Flags like -rpc.trace and -logfile to be used while running the language server."
}
}
]
}
},
"scripts": {
"vscode:prepublish": "cue cmd genPackageJSON && npm run clean && npm run buildpackage",
Expand All @@ -67,7 +98,7 @@
"devDependencies": {
"@types/mocha": "10.0.7",
"@types/node": "22.9.1",
"@types/vscode": "1.63.0",
"@types/vscode": "1.85.0",
"@typescript-eslint/eslint-plugin": "7.14.1",
"@typescript-eslint/parser": "7.11.0",
"@vscode/test-cli": "0.0.9",
Expand All @@ -76,6 +107,9 @@
"esbuild": "0.21.5",
"eslint": "8.57.0",
"npm-run-all": "4.1.5",
"typescript": "5.4.5"
"typescript": "5.4.5",
"@types/which": "3.0.4",
"vscode-languageclient": "9.0.1",
"which": "5.0.0"
}
}
Loading

0 comments on commit 944ec28

Please sign in to comment.