Skip to content

Commit

Permalink
feat: add diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
tekumara committed Apr 7, 2023
1 parent 342c254 commit a69923e
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 41 deletions.
120 changes: 108 additions & 12 deletions package-lock.json

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

39 changes: 34 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "typos-vscode",
"displayName": "typos-vscode",
"publisher": "tekumara",
"description": "Source code spell checker",
"version": "0.0.1",
"engines": {
Expand All @@ -9,15 +10,40 @@
"categories": [
"Other"
],
"activationEvents": [],
"activationEvents": [
"onStartupFinished"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "typos-vscode.helloWorld",
"title": "Hello World"
}
]
],
"configuration": {
"type": "object",
"title": "Typos",
"properties": {
"typos.path": {
"scope": "machine-overridable",
"type": "string",
"default": null,
"description": "When set to a path to the `typos-lsp` binary, extension will use that."
},
"typos.trace.server": {
"scope": "window",
"type": "string",
"enum": [
"off",
"messages",
"verbose"
],
"default": "off",
"description": "Traces the communication between VS Code and the language server."
}
}
}
},
"scripts": {
"vscode:prepublish": "npm run compile",
Expand All @@ -28,16 +54,19 @@
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/vscode": "^1.77.0",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.1",
"@types/node": "16.x",
"@types/vscode": "^1.77.0",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"@vscode/test-electron": "^2.2.3",
"eslint": "^8.34.0",
"glob": "^8.1.0",
"mocha": "^10.2.0",
"typescript": "^4.9.5",
"@vscode/test-electron": "^2.2.3"
"typescript": "^4.9.5"
},
"dependencies": {
"vscode-languageclient": "^8.1.0"
}
}
83 changes: 59 additions & 24 deletions src/extension.ts
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();
}

0 comments on commit a69923e

Please sign in to comment.