Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat(vscode-plugin): support `harper-ls.path` setting

Matthew Espinoc6d4b5d0dc18
diff --git a/packages/vscode-plugin/package.json b/packages/vscode-plugin/package.json
index 3c1c42315..cb0bc02dc 100644
--- a/packages/vscode-plugin/package.json
+++ b/packages/vscode-plugin/package.json
@@ -66,6 +66,11 @@
"type": "object",
"title": "Harper",
"properties": {
+ "harper-ls.path": {
+ "scope": "resource",
+ "type": "string",
+ "description": "Optional path to a harper-ls executable to use."
+ },
"harper-ls.linters.spell_check": {
"scope": "resource",
"type": "boolean",
diff --git a/packages/vscode-plugin/src/extension.ts b/packages/vscode-plugin/src/extension.ts
index 9984021aa..363887dc3 100644
--- a/packages/vscode-plugin/src/extension.ts
+++ b/packages/vscode-plugin/src/extension.ts
@@ -17,11 +17,7 @@ const serverOptions: Executable = { command: '', transport: TransportKind.stdio
const clientOptions: LanguageClientOptions = {};
export async function activate(context: ExtensionContext): Promise<void> {
- serverOptions.command = Uri.joinPath(
- context.extensionUri,
- 'bin',
- `harper-ls${process.platform === 'win32' ? '.exe' : ''}`
- ).fsPath;
+ serverOptions.command = getExecutablePath(context);
let manifest: ExtensionManifest;
try {
@@ -43,6 +39,12 @@ export async function activate(context: ExtensionContext): Promise<void> {
const configs = Object.keys(manifest.contributes.configuration.properties);
context.subscriptions.push(
workspace.onDidChangeConfiguration(async (event) => {
+ if (event.affectsConfiguration('harper-ls.path')) {
+ serverOptions.command = getExecutablePath(context);
+ await startLanguageServer();
+ return;
+ }
+
if (configs.find((c) => event.affectsConfiguration(c))) {
await client?.sendNotification('workspace/didChangeConfiguration', {
settings: { 'harper-ls': workspace.getConfiguration('harper-ls') }
@@ -58,6 +60,20 @@ export async function activate(context: ExtensionContext): Promise<void> {
await startLanguageServer();
}
+function getExecutablePath(context: ExtensionContext): string {
+ const path = workspace.getConfiguration('harper-ls').get<string>('path', '');
+
+ if (path !== '') {
+ return path;
+ }
+
+ return Uri.joinPath(
+ context.extensionUri,
+ 'bin',
+ `harper-ls${process.platform === 'win32' ? '.exe' : ''}`
+ ).fsPath;
+}
+
async function startLanguageServer(): Promise<void> {
if (client && client.needsStop()) {
if (client.diagnostics) {