From 7e818239d9f37cc9846b7de899c6d9f71e770547 Mon Sep 17 00:00:00 2001 From: Daniel Brice Date: Thu, 1 Feb 2024 14:16:18 -0800 Subject: [PATCH 1/2] debug language server startup --- CHANGELOG.md | 5 +++ README.md | 75 ++++++++++++++++++++++++++++----------------- package-lock.json | 4 +-- package.json | 2 +- src/client.ts | 78 ++++++++++++++++++++++------------------------- 5 files changed, 92 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b81f05..f07fa8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to the "alloglot" extension will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). This project adhere's to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.0.2] - 2024-02-01 + +- Debug language server startup. +- Fix error in example confiuration in README.md + ## [2.0.1] - 2024-01-30 - Move to a new repository. diff --git a/README.md b/README.md index b5b9998..cdda330 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,53 @@ Language agnostic IDE for VS Code. ## Configuration +A workspace-level configuration would look something like this. + +```json +{ + "alloglot.languages": [ + { + "languageId": "haskell", + "serverCommand": "static-ls", + "formatCommand": "fourmolu --mode stdout --stdin-input-file ${file}", + "apiSearchUrl": "https://hoogle.haskell.org/?hoogle=${query}", + "annotations": [ + { + "file": "ghcid.out", + "format": "jsonl", + "mapping": { + "file": ["span", "file"], + "startLine": ["span", "startLine"], + "startColumn": ["span", "startCol"], + "endLine": ["span", "endLine"], + "endColumn": ["span", "endCol"], + "message": ["doc"], + "severity": ["messageClass"] + } + }, + { + "file": "hlint-out.json", + "format": "json", + "mapping": { + "file": ["file"], + "startLine": ["startLine"], + "startColumn": ["startColumn"], + "endLine": ["endLine"], + "endColumn": ["endColumn"], + "message": ["hint"], + "severity": ["severity"], + "replacements": ["to"] + } + } + ] + } + ] +} +``` + +The configuration schema is defined by the following typescript. +Configuration is highly flexible, with most fields being optional. + ```typescript /** * Extension configuration. @@ -113,31 +160,3 @@ export type AnnotationsMapping = { referenceCode?: Array } ``` - -An example configuration follows. - -```json -{ - "alloglot.languages": [ - { - "languageId": "haskell", - "serverCommand": "static-ls", - "formatCommand": "fourmolu --mode stdout --stdin-input-file ${file}", - "apiSearchUrl": "https://hoogle.haskell.org/?hoogle=${query}", - "annotations": { - "file": "ghcid.out", - "format": "jsonl", - "mapping": { - "file": ["span", "file"], - "startLine": ["span", "startLine"], - "startColumn": ["span", "startCol"], - "endLine": ["span", "endLine"], - "endColumn": ["span", "endCol"], - "message": ["doc"], - "severity": ["messageClass"] - } - } - } - ] -} -``` diff --git a/package-lock.json b/package-lock.json index 85d2696..dbcdeb0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "alloglot", - "version": "2.0.1", + "version": "2.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "alloglot", - "version": "2.0.1", + "version": "2.0.2", "license": "SEE LICENSE IN LICENSE.md", "dependencies": { "vscode-languageclient": "^9.0.1" diff --git a/package.json b/package.json index f02a130..0a9a7ff 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "alloglot", "displayName": "Alloglot", "description": "Language agnostic IDE for VS Code", - "version": "2.0.1", + "version": "2.0.2", "publisher": "friedbrice", "license": "SEE LICENSE IN LICENSE.md", "repository": { diff --git a/src/client.ts b/src/client.ts index 6a186a4..eac093c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -12,6 +12,21 @@ export function makeClient(config: LanguageConfig): vscode.Disposable { const { languageId, serverCommand } = config if (!languageId || !serverCommand) return vscode.Disposable.from() + const serverExecutable = { + command: serverCommand, + options: { + cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath, + env: process.env + }, + args: [], + transport: lsp.TransportKind.stdio + } + + const serverOptions = { + run: serverExecutable, + debug: serverExecutable + } + const clientId = `${alloglot.root}-${languageId}` const output = vscode.window.createOutputChannel(clientId) @@ -24,46 +39,27 @@ export function makeClient(config: LanguageConfig): vscode.Disposable { workspaceFolder: vscode.workspace.workspaceFolders?.[0] } - return utils.bracket({ - open: () => child_process.spawn(serverCommand, [], { env: process.env }), - close: server => server.kill(), - use: server => { - return utils.bracket({ - open: () => { - let client = new lsp.LanguageClient( - clientId, - `${alloglot.root} language client for ${languageId}`, - () => Promise.resolve(server), - clientOptions, - false - ) - client.start() - return client - }, - close: client => client.stop(), - use: client => { - return vscode.Disposable.from({ - dispose: () => { - client.stop() - server.kill() - output.dispose() - } - }) - } - }) - } - }) -} + output.append(`${alloglot.root} debug: Starting language client...\n`) -namespace utils { - export function bracket(args: { open: () => T, close: (t: T) => void, use: (t: T) => U }): U { - let t: T | undefined = undefined - try { - t = args.open() - return args.use(t) - } - finally { - if (t) args.close(t) - } - } + let client = new lsp.LanguageClient( + clientId, + `${alloglot.root} language client for ${languageId}`, + serverOptions, + clientOptions, + false + ) + + client.start() + output.append(`${alloglot.root} debug: Language client started.\n`) + + return vscode.Disposable.from( + { + dispose: () => { + output.append(`${alloglot.root} debug: Stopping language client...\n`) + client.stop() + output.append(`${alloglot.root} debug: Language client stopped.\n`) + } + }, + output + ) } From 54c8d1166b0d19edb266ec749548142bf4c798f8 Mon Sep 17 00:00:00 2001 From: "Daniel P. Brice" Date: Thu, 1 Feb 2024 14:18:41 -0800 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f07fa8e..c51d9b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ This project adhere's to [Semantic Versioning](https://semver.org/spec/v2.0.0.ht ## [2.0.2] - 2024-02-01 - Debug language server startup. -- Fix error in example confiuration in README.md +- Fix error in example configuration in README.md ## [2.0.1] - 2024-01-30