feat(client): bare-bones support for vscode (#237)
Some checks failed
CI / Lint (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Corpus test (push) Has been cancelled
CI / Generate schema (push) Has been cancelled

This commit is contained in:
Riley Bruins 2025-09-12 21:43:05 -07:00 committed by GitHub
parent f66b4f9a3a
commit b03b7072e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 5144 additions and 12 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
/target
run.lua
client/vscode/out
***/*.vsix

View file

@ -186,6 +186,20 @@ If both properties are `true`, then there will be a predicate of the form
Same as `valid_predicates`, but for directives (e.g. `#foo!`).
#### `supported_abi_versions`
An inclusive range of ABI versions supported by your tool. The end of the range
must be greater than or equal to the start.
```json
{
"supported_abi_versions": {
"start": 13,
"end": 15
}
}
```
### Example setup (for Neovim):
```lua
@ -226,19 +240,14 @@ vim.api.nvim_create_autocmd('FileType', {
})
```
#### `supported_abi_versions`
### Run in VSCode
An inclusive range of ABI versions supported by your tool. The end of the range
must be greater than or equal to the start.
```json
{
"supported_abi_versions": {
"start": 13,
"end": 15
}
}
```
This repo provides a very minimal extension for usage within VSCode. First,
ensure you have a `scheme` extension installed for VSCode to recognize `.scm`
files as the `scheme` file type. Next, enter the `client/vscode` directory and
install dependencies with `npm i`. From that directory, start VSCode (`code .`).
Then you can press `F5`, or go into the debug menu and click `Run Extension`,
and this will activate the extension, building and starting the language server.
## Features

24
client/vscode/.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "Build Server and Extension",
"env": {
"SERVER_PATH": "${workspaceRoot}/../../target/release/ts_query_ls"
},
"skipFiles": [
"<node_internals>/**/*.js"
]
}
]
}

31
client/vscode/.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,31 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Extension",
"group": "build",
"type": "npm",
"script": "build",
"problemMatcher": {
"base": "$tsc",
"fileLocation": [
"relative",
"${workspaceFolder}"
]
}
},
{
"label": "Build Server",
"group": "build",
"type": "shell",
"command": "cargo build -r"
},
{
"label": "Build Server and Extension",
"dependsOn": [
"Build Server",
"Build Extension"
]
}
]
}

4946
client/vscode/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,49 @@
{
"name": "ts_query_ls",
"description": "LSP implementation for Tree-sitter's query files",
"author": "Riley Bruins",
"license": "MIT",
"version": "3.11.1",
"publisher": "ribru17",
"repository": {
"type": "git",
"url": "git+https://github.com/ribru17/ts_query_ls.git"
},
"scripts": {
"vscode:prepublish": "npm run build-base -- --minify",
"package": "vsce package -o ts-query-ls.vsix",
"build-base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node --target=node16",
"build": "npm run build-base -- --sourcemap",
"watch": "npm run build-base -- --sourcemap --watch",
"lint:check": "eslint ./src --ext .ts,.tsx",
"lint:fix": "npm run lint -- --fix",
"format:check": "prettier --check .",
"format:fix": "prettier --write .",
"typecheck": "tsc"
},
"keywords": [
"treesitter"
],
"engines": {
"vscode": "^1.75.0"
},
"activationEvents": [
"onLanguage:scheme"
],
"main": "./out/extension",
"devDependencies": {
"@types/node": "^18.14.6",
"@types/vscode": "^1.75.1",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"@vscode/test-electron": "^2.3.9",
"@vscode/vsce": "^2.29.0",
"esbuild": "^0.23.0",
"eslint": "^8.57.0",
"typescript": "^5.3.3",
"prettier": "^3.0.0"
},
"dependencies": {
"vscode-languageclient": "^9.0.1"
}
}

View file

@ -0,0 +1,52 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import path = require('node:path');
import os = require('node:os');
import { ExtensionContext, window } from 'vscode';
import {
Executable,
LanguageClient,
LanguageClientOptions,
ServerOptions,
} from 'vscode-languageclient/node';
let client: LanguageClient;
export async function activate(_context: ExtensionContext) {
const command = process.env.SERVER_PATH || 'ts_query_ls';
const run: Executable = {
command,
options: {
env: {
...process.env,
RUST_LOG: 'debug',
},
},
};
const serverOptions: ServerOptions = {
run,
debug: run,
};
let clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'scheme' }],
};
client = new LanguageClient(
'ts_query_ls',
"LSP implementation for Tree-sitter's query files",
serverOptions,
clientOptions,
);
client.start();
}
export function deactivate(): Promise<void> | undefined {
if (!client) {
return undefined;
}
return client.stop();
}

View file

@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"lib": [
"es2020"
],
"outDir": "out",
"rootDir": "src",
"sourceMap": true
},
"include": [
"src"
],
"exclude": [
"node_modules",
".vscode-test"
]
}