Skip to content

Commit

Permalink
Add the ability to restart the server (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz authored May 10, 2023
1 parent 222256f commit dd84ea5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 39 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
"scopeName": "source.smithy",
"path": "./smithy.tmGrammar.json"
}
],
"commands": [
{
"command": "smithyLsp.restart",
"title": "Smithy LSP: Restart server"
}
]
},
"scripts": {
Expand All @@ -97,7 +103,7 @@
},
"dependencies": {
"follow-redirects": "^1.14.9",
"vscode-languageclient": "^7.0.0"
"vscode-languageclient": "^8.0.0"
},
"devDependencies": {
"@types/follow-redirects": "^1.14.1",
Expand Down
28 changes: 15 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ interface SmithyBuild {
languageServer?: MavenCoordinate;
}

let client: LanguageClient;

export function activate(context: ExtensionContext) {
// Options to control the language client
let clientOptions: LanguageClientOptions = {
Expand Down Expand Up @@ -70,7 +68,7 @@ export function activate(context: ExtensionContext) {
return Promise.all([
getCoursierExecutable(context.globalStoragePath),
parseSmithyBuild(),
]).then(([csBinaryPath, smithyBuild]) => {
]).then(async ([csBinaryPath, smithyBuild]) => {
console.info(`Resolved coursier's binary at ${csBinaryPath}`);

const projectLanguageServerArtifact = smithyBuild?.languageServer;
Expand All @@ -90,32 +88,36 @@ export function activate(context: ExtensionContext) {

const startServer = { command: csBinaryPath, args };

client = new LanguageClient(
let client = new LanguageClient(
"smithyLsp",
"Smithy LSP",
startServer,
clientOptions
);

// Start the client. This will also launch the server.
await client.start();

const smithyContentProvider = createSmithyContentProvider(client);

const registerRestartCommand = vscode.commands.registerCommand(
"smithyLsp.restart",
() => {
client.restart();
}
);

context.subscriptions.push(
workspace.registerTextDocumentContentProvider(
"smithyjar",
smithyContentProvider
),
// Start the client. This will also launch the server
client.start()
client,
registerRestartCommand
);
});
}

export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
}
return client.stop();
}

function parseSmithyBuild(): Thenable<SmithyBuild | null> {
const folders = vscode.workspace.workspaceFolders;
if (!folders || folders.length != 1) {
Expand Down
64 changes: 39 additions & 25 deletions yarn.lock

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

0 comments on commit dd84ea5

Please sign in to comment.