Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug language server startup #21

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 configuration in README.md

## [2.0.1] - 2024-01-30

- Move to a new repository.
Expand Down
75 changes: 47 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -113,31 +160,3 @@ export type AnnotationsMapping = {
referenceCode?: Array<string>
}
```

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"]
}
}
}
]
}
```
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
78 changes: 37 additions & 41 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ export function makeClient(config: LanguageConfig): vscode.Disposable {
const { languageId, serverCommand } = config
if (!languageId || !serverCommand) return vscode.Disposable.from()

const serverExecutable = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LSP client library will manage the child process for you if you just give it a process spec.

This is how the official Haskell extension launches HLS.

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)

Expand All @@ -24,46 +39,27 @@ export function makeClient(config: LanguageConfig): vscode.Disposable {
workspaceFolder: vscode.workspace.workspaceFolders?.[0]
}

return utils.bracket<child_process.ChildProcessWithoutNullStreams, vscode.Disposable>({
open: () => child_process.spawn(serverCommand, [], { env: process.env }),
close: server => server.kill(),
use: server => {
return utils.bracket<lsp.LanguageClient, vscode.Disposable>({
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<T, U>(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)
}
Comment on lines -65 to -67
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it turns out i was closing the server just as soon as i was opening it, i think. actually, i'm not sure what the problem was.

}
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
)
}
Loading