Skip to content

feat: add lsp extension #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
- name: Install deps
run: pnpm install

# - name: Build
# run: pnpm run build
- name: Build
run: pnpm run build

# - name: Lint
# run: pnpm run lint
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
client/out
node_modules
*.vsix
*.vsix
tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"esbenp.prettier-vscode",
"github.vscode-github-actions",
"kravets.vscode-publint",
"ms-vscode.extension-test-runner",
"pflannery.vscode-versionlens",
"redhat.vscode-yaml"
]
Expand Down
9 changes: 6 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// A launch configuration that launches the extension inside a new window
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"]
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/client/out/**/*.js"],
"autoAttachChildProcesses": true
}
]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@
"files.associations": {
"*.json5": "jsonc"
},
"files.exclude": {
"out": false,
"dist": false
},
"search.exclude": {
"out": true,
"dist": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}
8 changes: 8 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
.vscode/**
.vscode-test/**
out/**
node_modules/**
src/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/*.map
**/*.ts
**/.vscode-test.*
34 changes: 34 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@hsml/lsp-client",
Copy link
Member Author

Choose a reason for hiding this comment

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

todo (blocking): Before merging this PR, we should find out if language support and LSP-Client extension can be merged into one package

"version": "0.1.0",
"description": "HSML Language Server Client",
"scripts": {
"build": "run-s build:clean build:code",
"build:clean": "rimraf out",
"build:code": "tsup-node",
"ts-check": "tsc",
"vscode:prepublish": "tsc -p ./"
},
"repository": {
"type": "git",
"url": "https://github.com/Shinigami92/vscode-hsml"
},
"license": "MIT",
"author": {
"name": "Christopher Quadflieg",
"email": "chrissi92@hotmail.de",
"url": "https://github.com/Shinigami92"
},
"publisher": "hsml-lab",
"activationEvents": [],
"dependencies": {
"vscode-languageclient": "9.0.1"
},
"devDependencies": {
"@types/vscode": "1.98.0",
"tsup": "8.4.0"
},
"engines": {
"vscode": "^1.98.0"
}
}
53 changes: 53 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { ExtensionContext } from 'vscode';
import { workspace } from 'vscode';
import type {
Executable,
LanguageClientOptions,
ServerOptions,
} from 'vscode-languageclient/node';
import { LanguageClient } from 'vscode-languageclient/node';

let client: LanguageClient | undefined;

export function activate(context: ExtensionContext) {
console.debug('[@hsml/lsp-client:activate]', context);

const run: Executable = {
command: '/Users/shinigami/OpenSource/Shinigami92/hsml/target/debug/hsml',
args: ['lsp'],
};

const serverOptions: ServerOptions = {
run,
debug: {
...run,
},
};

const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'hsml' }],
synchronize: {
fileEvents: workspace.createFileSystemWatcher('**/*.hsml'),
},
};

client = new LanguageClient(
'languageServerHsml',
'HSML Language Server',
serverOptions,
clientOptions
);

console.debug('[@hsml/lsp-client:activate]', 'starting client');
client.start();
}

export function deactivate(): Promise<void> | undefined {
console.debug('[@hsml/lsp-client:deactivate]');
if (!client) {
return undefined;
}

console.debug('[@hsml/lsp-client:deactivate]', 'stopping client');
return client.stop();
}
11 changes: 11 additions & 0 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022"],
"noEmit": true,
"rootDir": "src",
"strict": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
13 changes: 13 additions & 0 deletions client/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/extension.ts'],
external: ['vscode'],
outDir: 'out',
clean: true,
format: 'cjs',
target: ['es2022', 'node20'],
platform: 'node',
minify: false,
bundle: true,
});
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
"version": "0.1.0",
"description": "hsml support for Visual Studio Code",
"scripts": {
"build": "pnpm --recursive run build",
"format": "prettier --cache --write .",
"preflight": "pnpm install && run-s format"
"preflight": "pnpm install && run-s format build"
},
"displayName": "hsml",
"categories": [
"Programming Languages"
],
"type": "commonjs",
"main": "./client/out/extension",
"contributes": {
"configuration": {
"type": "object",
"title": "HSML configuration",
"properties": {}
},
"grammars": [
{
"language": "hsml",
Expand All @@ -38,7 +45,8 @@
"npm-run-all2": "~7.0.2",
"prettier": "~3.5.3",
"prettier-plugin-organize-imports": "~4.1.0",
"prettier-plugin-packagejson": "~2.5.10"
"prettier-plugin-packagejson": "~2.5.10",
"rimraf": "~6.0.1"
},
"packageManager": "pnpm@10.6.4",
"engines": {
Expand Down
Loading