Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
feat: add deno.restart_server command to restart `Deno Language Ser…
Browse files Browse the repository at this point in the history
…ver`. close #28
  • Loading branch information
axetroy committed Feb 4, 2020
1 parent 6fb83c4 commit 9a66f86
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 79 deletions.
153 changes: 86 additions & 67 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,81 +180,96 @@ class Extension {
}
// start Deno Language Server
private async StartDenoLanguageServer() {
// create server connection
const port = await getport({ port: 9523 });

// The server is implemented in node
const serverModule = this.context.asAbsolutePath(
path.join("server", "out", "server.js")
);
if (this.client) {
await this.client.stop();
this.client = null;
}
const statusbar = window.createStatusBarItem(StatusBarAlignment.Left, -100);
statusbar.text = "$(loading) Initializing Deno Language Server";
statusbar.show();

// 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,
options: { cwd: process.cwd() }
},
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: {
cwd: process.cwd(),
execArgv: ["--nolazy", `--inspect=${port}`]
}
}
};

// Options to control the language client
const clientOptions: LanguageClientOptions = {
documentSelector: [
{ scheme: "file", language: "javascript" },
{ scheme: "file", language: "javascriptreact" },
{ scheme: "file", language: "typescript" },
{ scheme: "file", language: "typescriptreact" },
{ scheme: "file", language: "markdown" },
{ scheme: "file", language: "json" }
],
diagnosticCollectionName: this.configurationSection,
synchronize: {
configurationSection: this.configurationSection
},
progressOnInitialization: true
};

// Create the language client and start the client.
const client = (this.client = new LanguageClient(
"Deno Language Server",
"Deno Language Server",
serverOptions,
clientOptions
));

client.onReady().then(() => {
console.log("Deno Language Server is ready!");
client.onNotification("init", (info: DenoInfo) => {
this.denoInfo = { ...this.denoInfo, ...info };
this.updateStatusBarVisibility(window.activeTextEditor);
});
client.onNotification("error", window.showErrorMessage);
try {
// create server connection
const port = await getport({ port: 9523 });

client.onRequest("getWorkspaceFolder", async (uri: string) =>
workspace.getWorkspaceFolder(Uri.parse(uri))
// The server is implemented in node
const serverModule = this.context.asAbsolutePath(
path.join("server", "out", "server.js")
);

client.onRequest("getWorkspaceConfig", async (uri: string) => {
const workspaceFolder = workspace.getWorkspaceFolder(Uri.parse(uri));
// 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,
options: { cwd: process.cwd() }
},
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: {
cwd: process.cwd(),
execArgv: ["--nolazy", `--inspect=${port}`]
}
}
};

// Options to control the language client
const clientOptions: LanguageClientOptions = {
documentSelector: [
{ scheme: "file", language: "javascript" },
{ scheme: "file", language: "javascriptreact" },
{ scheme: "file", language: "typescript" },
{ scheme: "file", language: "typescriptreact" },
{ scheme: "file", language: "markdown" },
{ scheme: "file", language: "json" }
],
diagnosticCollectionName: this.configurationSection,
synchronize: {
configurationSection: this.configurationSection
},
progressOnInitialization: true
};

const config = this.getConfiguration(
workspaceFolder?.uri || Uri.parse(uri)
// Create the language client and start the client.
const client = (this.client = new LanguageClient(
"Deno Language Server",
"Deno Language Server",
serverOptions,
clientOptions
));

this.context.subscriptions.push(client.start());

await client.onReady().then(() => {
console.log("Deno Language Server is ready!");
client.onNotification("init", (info: DenoInfo) => {
this.denoInfo = { ...this.denoInfo, ...info };
this.updateStatusBarVisibility(window.activeTextEditor);
});
client.onNotification("error", window.showErrorMessage);

client.onRequest("getWorkspaceFolder", async (uri: string) =>
workspace.getWorkspaceFolder(Uri.parse(uri))
);

return config;
});
});
client.onRequest("getWorkspaceConfig", async (uri: string) => {
const workspaceFolder = workspace.getWorkspaceFolder(Uri.parse(uri));

this.context.subscriptions.push(client.start());
const config = this.getConfiguration(
workspaceFolder?.uri || Uri.parse(uri)
);

return config;
});
});
} catch (err) {
throw err;
} finally {
statusbar.hide();
statusbar.dispose();
}
}
// update status bar visibility
private updateStatusBarVisibility(
Expand Down Expand Up @@ -397,6 +412,10 @@ Executable ${this.denoInfo.executablePath}

this.registerCommand("enable", this.enable.bind(this));
this.registerCommand("disable", this.disable.bind(this));
this.registerCommand(
"restart_server",
this.StartDenoLanguageServer.bind(this)
);
this.watchConfiguration(() => {
const uri = window.activeTextEditor?.document.uri;
if (uri) {
Expand Down
22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@
"engines": {
"vscode": "^1.41.0"
},
"categories": [
"Programming Languages",
"Other"
],
"keywords": [
"deno"
],
"categories": ["Programming Languages", "Other"],
"keywords": ["deno"],
"activationEvents": [
"onLanguage:typescript",
"onLanguage:typescriptreact",
"onCommand:deno.enable",
"onCommand:deno.disable"
"onCommand:deno.disable",
"onCommand:deno.restart_server"
],
"main": "./client/out/extension.js",
"contributes": {
Expand All @@ -50,6 +46,11 @@
"command": "deno.disable",
"title": "%deno.command.disable%",
"category": "deno"
},
{
"command": "deno.restart_server",
"title": "%deno.command.restart_server%",
"category": "deno"
}
],
"configuration": {
Expand Down Expand Up @@ -89,10 +90,7 @@
}
},
"lint-staged": {
"**/*.{js,ts,json,md}": [
"yarn format",
"git add"
]
"**/*.{js,ts,json,md}": ["yarn format", "git add"]
},
"devDependencies": {
"@types/node": "12.12.26",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deno.description": "Deno support for VSCode",
"deno.command.enable": "Enable Deno",
"deno.command.disable": "Disable Deno",
"deno.command.restart_server": "Restart Deno Language Server",
"deno.config.enabled": "Controls whether deno is enabled or not.",
"deno.config.dtsFilepaths": "The file paths of the TypeScript declaration file(.d.ts). It can be a relative which path relative to the project directory or an absolute path."
}
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deno.description": "Deno support for VSCode",
"deno.command.enable": "启用 Deno",
"deno.command.disable": "禁用 Deno",
"deno.command.restart_server": "重启 Deno 服务器",
"deno.config.enabled": "是否启用 Deno。",
"deno.config.dtsFilepaths": "Typescript 的声明文件(.d.ts)路径。它可以是相对于项目目录的相对路径或者是绝对路径"
}

0 comments on commit 9a66f86

Please sign in to comment.