-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4880c7
commit 77081a1
Showing
5 changed files
with
116 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,58 @@ | ||
{ | ||
"name": "@weblsp/vscode", | ||
"displayName": "WEBlsp", | ||
"version": "1.0.0", | ||
"description": "A better Language Server for the Web, made with Rust — WORK IN PROGRESS ⚠️", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/web-lsp/weblsp" | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"vscode": "^1.82.0" | ||
}, | ||
"categories": [ | ||
"Programming Languages" | ||
], | ||
"activationEvents": [ | ||
"onLanguage:css" | ||
], | ||
"main": "./dist/extension.js", | ||
"contributes": { | ||
"configuration": { | ||
"type": "object", | ||
"title": "CSS Language Server Settings", | ||
"properties": { | ||
"cssLanguageServer.path": { | ||
"type": "string", | ||
"description": "Path to the CSS language server executable", | ||
"default": "" | ||
} | ||
} | ||
} | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "npm run compile", | ||
"build": "tsc -p ./", | ||
"watch": "tsc -watch -p ./" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.9.1", | ||
"@types/vscode": "^1.95.0", | ||
"typescript": "^5.6.3" | ||
}, | ||
"dependencies": { | ||
"vscode-languageclient": "^9.0.1" | ||
} | ||
"name": "@weblsp/vscode", | ||
"displayName": "WEBlsp", | ||
"version": "1.0.0", | ||
"description": "A better Language Server for the Web, made with Rust — WORK IN PROGRESS ⚠️", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/web-lsp/weblsp" | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"vscode": "^1.82.0" | ||
}, | ||
"categories": [ | ||
"Programming Languages" | ||
], | ||
"activationEvents": [ | ||
"onLanguage:css" | ||
], | ||
"main": "./dist/extension.js", | ||
"contributes": { | ||
"configuration": { | ||
"type": "object", | ||
"title": "WEBlsp configuration", | ||
"properties": { | ||
"weblsp.trace.server": { | ||
"scope": "window", | ||
"type": "string", | ||
"enum": [ | ||
"off", | ||
"messages", | ||
"verbose" | ||
], | ||
"default": "off", | ||
"description": "Traces the communication between VS Code and the language server." | ||
}, | ||
"weblsp.server.path": { | ||
"type": "string", | ||
"description": "Path to the WEBlsp executable", | ||
"default": "" | ||
} | ||
} | ||
} | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "npm run build", | ||
"build": "tsc -p ./", | ||
"watch": "tsc -watch -p ./" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.9.1", | ||
"@types/vscode": "^1.95.0", | ||
"typescript": "^5.6.3" | ||
}, | ||
"dependencies": { | ||
"vscode-languageclient": "^9.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,70 @@ | ||
import * as path from "path" | ||
import * as vscode from "vscode" | ||
import * as lsp from "vscode-languageclient/node" | ||
import * as path from "path"; | ||
import * as vscode from "vscode"; | ||
import * as lsp from "vscode-languageclient/node"; | ||
|
||
let client: lsp.LanguageClient | ||
let client: lsp.LanguageClient; | ||
|
||
/** | ||
* Turn on WEBlsp's vscode extension 🚀 | ||
*/ | ||
export async function activate(context: vscode.ExtensionContext) { | ||
const serverExecutable = getServerExecutablePath(context) | ||
const serverExecutable = getServerExecutablePath(context); | ||
|
||
const serverOptions: lsp.ServerOptions = { | ||
command: serverExecutable, | ||
args: [], | ||
options: { | ||
// vscode.workspace.rootPath is deprecated, so we'll just run on the first workspace folder | ||
cwd: | ||
(vscode.workspace.workspaceFolders && | ||
vscode.workspace.workspaceFolders[0].uri.fsPath) || | ||
process.cwd(), | ||
}, | ||
} | ||
const serverOptions: lsp.ServerOptions = { | ||
command: serverExecutable, | ||
}; | ||
|
||
const clientOptions: lsp.LanguageClientOptions = { | ||
// TODO: We should add the support of HTML later | ||
documentSelector: [{ scheme: "file", language: "css" }], | ||
synchronize: { | ||
fileEvents: vscode.workspace.createFileSystemWatcher("**/*.css"), | ||
}, | ||
} | ||
const clientOptions: lsp.LanguageClientOptions = { | ||
// TODO: We should add the support of HTML later | ||
documentSelector: [{ scheme: "file", language: "css" }], | ||
synchronize: { | ||
fileEvents: vscode.workspace.createFileSystemWatcher("**/*.css"), | ||
}, | ||
}; | ||
|
||
client = new lsp.LanguageClient( | ||
"cssLanguageServer", | ||
"CSS Language Server", | ||
serverOptions, | ||
clientOptions | ||
) | ||
client = new lsp.LanguageClient( | ||
"weblsp", | ||
"WEBlsp Language Server", | ||
serverOptions, | ||
clientOptions | ||
); | ||
|
||
await client.start() | ||
await client.start(); | ||
} | ||
|
||
/** | ||
* Cut off WEBlsp's vscode extension 😢 | ||
*/ | ||
export function deactivate(): Thenable<void> | undefined { | ||
if (!client) { | ||
return undefined | ||
} | ||
return client.stop() | ||
if (!client) { | ||
return undefined; | ||
} | ||
return client.stop(); | ||
} | ||
|
||
/** | ||
* Get the Rust WEBlsp binary path from the configuration. | ||
*/ | ||
function getServerExecutablePath(context: vscode.ExtensionContext): string { | ||
const config = vscode.workspace.getConfiguration("cssLanguageServer") | ||
let serverPath = config.get<string>("path") | ||
const config = vscode.workspace.getConfiguration("weblsp"); | ||
let serverPath = config.get<string>("server.path"); | ||
|
||
if (serverPath) { | ||
if (!path.isAbsolute(serverPath)) { | ||
if ( | ||
vscode.workspace.workspaceFolders && | ||
vscode.workspace.workspaceFolders.length > 0 | ||
) { | ||
const rootPath = vscode.workspace.workspaceFolders[0].uri.fsPath | ||
serverPath = path.join(rootPath, serverPath) | ||
} | ||
} | ||
} else { | ||
serverPath = vscode.Uri.joinPath( | ||
context.extensionUri, | ||
"../../target/debug/weblsp" | ||
).fsPath | ||
} | ||
if (serverPath) { | ||
if (!path.isAbsolute(serverPath)) { | ||
if ( | ||
vscode.workspace.workspaceFolders && | ||
vscode.workspace.workspaceFolders.length > 0 | ||
) { | ||
const rootPath = vscode.workspace.workspaceFolders[0].uri.fsPath; | ||
serverPath = path.join(rootPath, serverPath); | ||
} | ||
} | ||
} else { | ||
serverPath = vscode.Uri.joinPath( | ||
context.extensionUri, | ||
"../../target/debug/weblsp" | ||
).fsPath; | ||
} | ||
|
||
return serverPath | ||
return serverPath; | ||
} |