-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #10 adapted code from #16 thanks to @JamieMagee
- Loading branch information
1 parent
718deed
commit ec3dee3
Showing
5 changed files
with
169 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// from PR of https://github.com/nix-community/vscode-nix-ide/pull/16/ | ||
|
||
import { env, ExtensionContext, Uri, window, workspace } from "vscode"; | ||
import { | ||
Executable, | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
} from "vscode-languageclient"; | ||
import { config, UriMessageItem } from "./configuration"; | ||
|
||
let client: LanguageClient; | ||
|
||
export async function activate(context: ExtensionContext): Promise<void> { | ||
if (config.serverPath === undefined || config.serverPath === "") { | ||
const selection = await window.showErrorMessage<UriMessageItem>( | ||
"Unable to find Nix language server", | ||
{ | ||
title: "Install language server", | ||
uri: Uri.parse("https://github.com/nix-community/rnix-lsp"), | ||
} | ||
); | ||
if (selection?.uri !== undefined) { | ||
await env.openExternal(selection?.uri); | ||
return; | ||
} | ||
} | ||
const serverExecutable: Executable = { | ||
command: config.serverPath, | ||
}; | ||
const serverOptions: ServerOptions = serverExecutable; | ||
|
||
const nixDocumentSelector: { scheme: string; language: string }[] = [ | ||
{ scheme: "file", language: "nix" }, | ||
{ scheme: "untitled", language: "nix" }, | ||
]; | ||
|
||
const clientOptions: LanguageClientOptions = { | ||
documentSelector: nixDocumentSelector, | ||
synchronize: { | ||
fileEvents: workspace.createFileSystemWatcher("**/*.nix"), | ||
}, | ||
outputChannel: window.createOutputChannel("Nix"), | ||
}; | ||
|
||
client = new LanguageClient("nix", "Nix", serverOptions, clientOptions); | ||
client.registerProposedFeatures(); | ||
context.subscriptions.push(client.start()); | ||
} | ||
|
||
export function deactivate(): Thenable<void> | undefined { | ||
return client ? client.stop() : undefined; | ||
} |
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,28 @@ | ||
import * as vscode from "vscode"; | ||
|
||
import { MessageItem, Uri } from "vscode"; | ||
|
||
export interface UriMessageItem extends MessageItem { | ||
uri: Uri; | ||
} | ||
|
||
export class Config { | ||
readonly rootSection = "nix"; | ||
|
||
private get cfg(): vscode.WorkspaceConfiguration { | ||
return vscode.workspace.getConfiguration(this.rootSection); | ||
} | ||
|
||
private get<T>(path: string): T { | ||
return this.cfg.get<T>(path)!; | ||
} | ||
|
||
get serverPath(): string { | ||
return this.get<string>("serverPath"); | ||
} | ||
|
||
get LSPEnabled(): boolean { | ||
return this.get<boolean>("enableLanguageServer"); | ||
} | ||
} | ||
export const config = new Config(); |
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