mirror of
https://github.com/ribru17/ts_query_ls.git
synced 2025-12-23 05:36:52 +00:00
feat(client): bare-bones support for vscode (#237)
This commit is contained in:
parent
f66b4f9a3a
commit
b03b7072e4
8 changed files with 5144 additions and 12 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +1,4 @@
|
|||
/target
|
||||
run.lua
|
||||
client/vscode/out
|
||||
***/*.vsix
|
||||
|
|
|
|||
33
README.md
33
README.md
|
|
@ -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
24
client/vscode/.vscode/launch.json
vendored
Normal 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
31
client/vscode/.vscode/tasks.json
vendored
Normal 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
4946
client/vscode/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
49
client/vscode/package.json
Normal file
49
client/vscode/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
52
client/vscode/src/extension.ts
Normal file
52
client/vscode/src/extension.ts
Normal 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();
|
||||
}
|
||||
19
client/vscode/tsconfig.json
Normal file
19
client/vscode/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue