-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
201 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,26 +1,61 @@ | ||
// The module 'vscode' contains the VS Code extensibility API | ||
// Import the module and reference it with the alias vscode in your code below | ||
import * as vscode from 'vscode'; | ||
|
||
// This method is called when your extension is activated | ||
// Your extension is activated the very first time the command is executed | ||
export function activate(context: vscode.ExtensionContext) { | ||
|
||
// Use the console to output diagnostic information (console.log) and errors (console.error) | ||
// This line of code will only be executed once when your extension is activated | ||
console.log('Congratulations, your extension "typos-vscode" is now active!'); | ||
|
||
// The command has been defined in the package.json file | ||
// Now provide the implementation of the command with registerCommand | ||
// The commandId parameter must match the command field in package.json | ||
let disposable = vscode.commands.registerCommand('typos-vscode.helloWorld', () => { | ||
// The code you place here will be executed every time your command is executed | ||
// Display a message box to the user | ||
vscode.window.showInformationMessage('Hello World from typos-vscode!'); | ||
}); | ||
|
||
context.subscriptions.push(disposable); | ||
import { workspace, ExtensionContext } from 'vscode'; | ||
|
||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
Executable | ||
} from 'vscode-languageclient/node'; | ||
|
||
let client: LanguageClient; | ||
|
||
export function activate(context: ExtensionContext) { | ||
|
||
const serverId = "typos"; | ||
const serverName = "Typos Language Server"; | ||
|
||
const env = { ...process.env }; | ||
|
||
// TODO: move into config | ||
env.RUST_LOG = "trace"; | ||
|
||
let config = workspace.getConfiguration(serverId); | ||
let command = config.get<null | string>("path"); | ||
|
||
if (!command) { | ||
throw new Error("Please specify typos.path setting."); | ||
} | ||
|
||
const run: Executable = { | ||
command: command, | ||
options: { env: env }, | ||
}; | ||
|
||
const serverOptions: ServerOptions = { | ||
run: run, | ||
// used when launched in debug mode | ||
debug: run | ||
}; | ||
|
||
const clientOptions: LanguageClientOptions = { | ||
// Register the server for all documents | ||
documentSelector: [{ scheme: 'file', pattern: '**' }], | ||
}; | ||
|
||
client = new LanguageClient( | ||
serverId, | ||
serverName, | ||
serverOptions, | ||
clientOptions | ||
); | ||
|
||
// Start the client. This will also launch the server | ||
client.start(); | ||
} | ||
|
||
// This method is called when your extension is deactivated | ||
export function deactivate() {} | ||
export function deactivate(): Thenable<void> | undefined { | ||
if (!client) { | ||
return undefined; | ||
} | ||
return client.stop(); | ||
} |