-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat(lsp): support using new language server implementations #162
Draft
jokeyrhyme
wants to merge
17
commits into
nushell:main
Choose a base branch
from
jokeyrhyme:117-use-language-server
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
39e53c1
feat(lsp): use standalone language server implementation
jokeyrhyme 26cd391
feat: new "implementation" setting to switch language servers
jokeyrhyme 4a4c66c
chore: deduplicate LanguageClientOptions
jokeyrhyme aec2b16
fix: `nu --lsp` uses "nushellExecutablePath" setting
jokeyrhyme e932a35
fix: restart language server when user changes "implementation"
jokeyrhyme 2fe5f61
fix(lsp): await the `client.stop()` Promise
jokeyrhyme eb01a1c
fix(lsp): unique labels in Output pane, no pop-up for `.stop()` errors
jokeyrhyme e7154fb
Merge branch 'main' into 117-use-language-server
AucaCoyan 1927b55
remove `nuls`
AucaCoyan 860fb9f
Merge pull request #1 from jokeyrhyme/remove-nuls
AucaCoyan 64bb6d9
:twisted_rightwards_arrows: merge `main`
AucaCoyan 5b0dc2f
:package: update the `package.lock` file
AucaCoyan 0d2c974
Merge branch 'main' into 117-use-language-server
AucaCoyan 98ba7cb
:coffin: remove unused definitions
AucaCoyan 59df2a3
:recycle: replace import * with import <map>
AucaCoyan 5b5bde8
:recycle: replace import * from which
AucaCoyan 5e8b571
Merge branch 'main' into 117-use-language-server
AucaCoyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as path from "path"; | ||
import { ExtensionContext, window } from "vscode"; | ||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
TransportKind, | ||
} from "vscode-languageclient/node"; | ||
|
||
let client: LanguageClient | null = null; | ||
|
||
async function startClient( | ||
context: ExtensionContext, | ||
clientOptions: LanguageClientOptions, | ||
) { | ||
// The server is implemented in node | ||
const serverModule = context.asAbsolutePath( | ||
path.join("out", "server", "src", "server.js"), | ||
); | ||
|
||
// The debug options for the server | ||
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging | ||
const debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] }; | ||
|
||
// If the extension is launched in debug mode then the debug server options are used | ||
// Otherwise the run options are used | ||
const serverOptions: ServerOptions = { | ||
run: { module: serverModule, transport: TransportKind.ipc }, | ||
debug: { | ||
module: serverModule, | ||
transport: TransportKind.ipc, | ||
options: debugOptions, | ||
}, | ||
}; | ||
|
||
// Create the language client and start the client. | ||
client = new LanguageClient( | ||
"nushellLanguageServer", | ||
"Nushell Language Server", | ||
serverOptions, | ||
clientOptions, | ||
); | ||
|
||
return client.start().catch((reason) => { | ||
window.showWarningMessage( | ||
`Failed to run Nushell Language Server (extension): ${reason}`, | ||
); | ||
client = null; | ||
}); | ||
} | ||
|
||
async function stopClient(): Promise<void> { | ||
if (client) { | ||
client.stop(); | ||
} | ||
client = null; | ||
} | ||
|
||
export async function activate( | ||
context: ExtensionContext, | ||
clientOptions: LanguageClientOptions, | ||
) { | ||
await startClient(context, clientOptions); | ||
} | ||
|
||
export function deactivate(): Thenable<void> { | ||
return stopClient(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { ExtensionContext, window } from "vscode"; | ||
import * as vscode from "vscode"; | ||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
} from "vscode-languageclient/node"; | ||
|
||
let client: LanguageClient | null = null; | ||
|
||
async function startClient( | ||
_context: ExtensionContext, | ||
clientOptions: LanguageClientOptions, | ||
) { | ||
const configuration = vscode.workspace.getConfiguration( | ||
"nushellLanguageServer", | ||
null, | ||
); | ||
|
||
const serverOptions: ServerOptions = { | ||
command: configuration.nushellExecutablePath, | ||
args: ["--lsp"], | ||
}; | ||
|
||
// Create the language client and start the client. | ||
client = new LanguageClient( | ||
"nushellLanguageServer", | ||
"Nushell Language Server", | ||
serverOptions, | ||
clientOptions, | ||
); | ||
|
||
return client.start().catch((reason) => { | ||
window.showWarningMessage( | ||
`Failed to run Nushell Language Server (nu --lsp): ${reason}`, | ||
); | ||
client = null; | ||
}); | ||
} | ||
|
||
async function stopClient(): Promise<void> { | ||
if (client) { | ||
client.stop(); | ||
} | ||
client = null; | ||
} | ||
|
||
export async function activate( | ||
context: ExtensionContext, | ||
clientOptions: LanguageClientOptions, | ||
) { | ||
// TODO: use configuration | ||
// const configuration = workspace.getConfiguration("nushellLanguageServer", null); | ||
|
||
await startClient(context, clientOptions); | ||
} | ||
|
||
export function deactivate(): Thenable<void> { | ||
return stopClient(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { ExtensionContext, window } from "vscode"; | ||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
} from "vscode-languageclient/node"; | ||
|
||
let client: LanguageClient | null = null; | ||
|
||
async function startClient( | ||
_context: ExtensionContext, | ||
clientOptions: LanguageClientOptions, | ||
) { | ||
const serverOptions: ServerOptions = { | ||
command: "nuls", | ||
args: [], | ||
}; | ||
|
||
// Create the language client and start the client. | ||
client = new LanguageClient( | ||
"nushellLanguageServer", | ||
"Nushell Language Server", | ||
serverOptions, | ||
clientOptions, | ||
); | ||
|
||
return client.start().catch((reason) => { | ||
window.showWarningMessage( | ||
`Failed to run Nushell Language Server (nuls): ${reason}`, | ||
); | ||
client = null; | ||
}); | ||
} | ||
|
||
async function stopClient(): Promise<void> { | ||
if (client) { | ||
client.stop(); | ||
} | ||
client = null; | ||
} | ||
|
||
export async function activate( | ||
context: ExtensionContext, | ||
clientOptions: LanguageClientOptions, | ||
) { | ||
await startClient(context, clientOptions); | ||
} | ||
|
||
export function deactivate(): Thenable<void> { | ||
return stopClient(); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bah, this is the only deliberate change here
The rest is auto-
prettier
, which I can revert if necessaryThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're using vscode to edit these files, one thing that I've just learned is you can do ctrl/cmd-shift-p and choose
File:Save without formatting
and it stops things like prettier or other formatters from running on save.