Skip to content

Commit 2cf3afd

Browse files
committed
feat: add lsp extension
1 parent 72ac825 commit 2cf3afd

File tree

13 files changed

+1219
-8
lines changed

13 files changed

+1219
-8
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
- name: Install deps
3333
run: pnpm install
3434

35-
# - name: Build
36-
# run: pnpm run build
35+
- name: Build
36+
run: pnpm run build
3737

3838
# - name: Lint
3939
# run: pnpm run lint

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
client/out
12
node_modules
2-
*.vsix
3+
*.vsix
4+
tsconfig.tsbuildinfo

.vscode/extensions.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"recommendations": [
3+
"connor4312.esbuild-problem-matchers",
34
"dbaeumer.vscode-eslint",
45
"editorconfig.editorconfig",
56
"esbenp.prettier-vscode",
67
"github.vscode-github-actions",
78
"kravets.vscode-publint",
9+
"ms-vscode.extension-test-runner",
810
"pflannery.vscode-versionlens",
911
"redhat.vscode-yaml"
1012
]

.vscode/launch.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
// A launch configuration that launches the extension inside a new window
1+
// A launch configuration that compiles the extension and then opens it inside a new window
22
// Use IntelliSense to learn about possible attributes.
33
// Hover to view descriptions of existing attributes.
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
{
66
"version": "0.2.0",
77
"configurations": [
88
{
9-
"name": "Extension",
9+
"name": "Run Extension",
1010
"type": "extensionHost",
1111
"request": "launch",
12-
"args": ["--extensionDevelopmentPath=${workspaceFolder}"]
12+
"runtimeExecutable": "${execPath}",
13+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
14+
"outFiles": ["${workspaceFolder}/client/out/**/*.js"],
15+
"autoAttachChildProcesses": true
1316
}
1417
]
1518
}

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@
33
"files.associations": {
44
"*.json5": "jsonc"
55
},
6+
"files.exclude": {
7+
"out": false,
8+
"dist": false
9+
},
10+
"search.exclude": {
11+
"out": true,
12+
"dist": true
13+
},
614
"typescript.tsdk": "node_modules/typescript/lib"
715
}

.vscodeignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
.vscode/**
22
.vscode-test/**
3+
out/**
4+
node_modules/**
5+
src/**
36
.gitignore
7+
.yarnrc
48
vsc-extension-quickstart.md
9+
**/tsconfig.json
10+
**/*.map
11+
**/*.ts
12+
**/.vscode-test.*

client/package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@hsml/lsp-client",
3+
"version": "0.1.0",
4+
"description": "HSML Language Server Client",
5+
"scripts": {
6+
"build": "run-s build:clean build:code",
7+
"build:clean": "rimraf out",
8+
"build:code": "tsup-node",
9+
"ts-check": "tsc",
10+
"vscode:prepublish": "tsc -p ./"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/Shinigami92/vscode-hsml"
15+
},
16+
"license": "MIT",
17+
"author": {
18+
"name": "Christopher Quadflieg",
19+
"email": "chrissi92@hotmail.de",
20+
"url": "https://github.com/Shinigami92"
21+
},
22+
"publisher": "hsml-lab",
23+
"activationEvents": [],
24+
"dependencies": {
25+
"vscode-languageclient": "9.0.1"
26+
},
27+
"devDependencies": {
28+
"@types/vscode": "1.98.0",
29+
"tsup": "8.4.0"
30+
},
31+
"engines": {
32+
"vscode": "^1.98.0"
33+
}
34+
}

client/src/extension.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type { ExtensionContext } from 'vscode';
2+
import { workspace } from 'vscode';
3+
import type {
4+
Executable,
5+
LanguageClientOptions,
6+
ServerOptions,
7+
} from 'vscode-languageclient/node';
8+
import { LanguageClient } from 'vscode-languageclient/node';
9+
10+
let client: LanguageClient | undefined;
11+
12+
export function activate(context: ExtensionContext) {
13+
console.debug('[@hsml/lsp-client:activate]', context);
14+
15+
const run: Executable = {
16+
command: '/Users/shinigami/OpenSource/Shinigami92/hsml/target/debug/hsml',
17+
args: ['lsp'],
18+
};
19+
20+
const serverOptions: ServerOptions = {
21+
run,
22+
debug: {
23+
...run,
24+
},
25+
};
26+
27+
const clientOptions: LanguageClientOptions = {
28+
documentSelector: [{ scheme: 'file', language: 'hsml' }],
29+
synchronize: {
30+
fileEvents: workspace.createFileSystemWatcher('**/*.hsml'),
31+
},
32+
};
33+
34+
client = new LanguageClient(
35+
'languageServerHsml',
36+
'HSML Language Server',
37+
serverOptions,
38+
clientOptions
39+
);
40+
41+
console.debug('[@hsml/lsp-client:activate]', 'starting client');
42+
client.start();
43+
}
44+
45+
export function deactivate(): Promise<void> | undefined {
46+
console.debug('[@hsml/lsp-client:deactivate]');
47+
if (!client) {
48+
return undefined;
49+
}
50+
51+
console.debug('[@hsml/lsp-client:deactivate]', 'stopping client');
52+
return client.stop();
53+
}

client/tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"lib": ["ES2022"],
5+
"noEmit": true,
6+
"rootDir": "src",
7+
"strict": true
8+
},
9+
"include": ["src"],
10+
"exclude": ["node_modules"]
11+
}

client/tsup.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from 'tsup';
2+
3+
export default defineConfig({
4+
entry: ['src/extension.ts'],
5+
external: ['vscode'],
6+
outDir: 'out',
7+
clean: true,
8+
format: 'cjs',
9+
target: ['es2022', 'node20'],
10+
platform: 'node',
11+
minify: false,
12+
bundle: true,
13+
});

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33
"version": "0.1.0",
44
"description": "hsml support for Visual Studio Code",
55
"scripts": {
6+
"build": "pnpm --recursive run build",
67
"format": "prettier --cache --write .",
7-
"preflight": "pnpm install && run-s format"
8+
"preflight": "pnpm install && run-s format build"
89
},
910
"displayName": "hsml",
1011
"categories": [
1112
"Programming Languages"
1213
],
1314
"type": "commonjs",
15+
"main": "./client/out/extension",
1416
"contributes": {
17+
"configuration": {
18+
"type": "object",
19+
"title": "HSML configuration",
20+
"properties": {}
21+
},
1522
"grammars": [
1623
{
1724
"language": "hsml",
@@ -38,7 +45,8 @@
3845
"npm-run-all2": "~7.0.2",
3946
"prettier": "~3.5.3",
4047
"prettier-plugin-organize-imports": "~4.1.0",
41-
"prettier-plugin-packagejson": "~2.5.10"
48+
"prettier-plugin-packagejson": "~2.5.10",
49+
"rimraf": "~6.0.1"
4250
},
4351
"packageManager": "pnpm@10.6.4",
4452
"engines": {

0 commit comments

Comments
 (0)