Skip to content

Commit a733fa3

Browse files
committed
(#70) Add current Language Server code
This code has been taken from the develop branch, so that we can continue the development of the language server portion of the extension without preventing other ongoing work from going out the door. We will get to this at some point, but for now, this should be regarded as a nice have.
1 parent c6938f4 commit a733fa3

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

package-lock.json

+43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+24
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,29 @@
8484
}
8585
}
8686
}
87+
},
88+
"chocolatey.language": {
89+
"type": "object",
90+
"properties": {
91+
"allowSuppressionOfRequirements": {
92+
"title": "Allow requirements suppression",
93+
"type": "boolean",
94+
"default": false,
95+
"description": "Allow the suppression of rules that are marked as requirements"
96+
},
97+
"disableLanguageService": {
98+
"title": "Disable language service",
99+
"type": "boolean",
100+
"default": false,
101+
"description": "Prevent the Chocolatey Language Service from starting up"
102+
},
103+
"suppressedRules": {
104+
"title": "Suppress Rules",
105+
"type": "array",
106+
"description": "The codes for the Chocolatey Language Service rules that should be suppressed",
107+
"default": []
108+
}
109+
}
87110
}
88111
}
89112
}
@@ -153,6 +176,7 @@
153176
"typescript": "^3.8.3"
154177
},
155178
"dependencies": {
179+
"vscode-languageclient": "^6.1.3",
156180
"xml2js": "^0.4.23"
157181
},
158182
"extensionPack": [

src/extension.ts

+68
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { window, commands, workspace, QuickPickItem, ExtensionContext, Uri } from "vscode";
2+
import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient';
3+
import { Trace } from 'vscode-jsonrpc';
24
import * as chocolateyCli from "./ChocolateyCliManager";
35
import * as chocolateyOps from "./ChocolateyOperation";
46
import * as path from "path";
@@ -7,6 +9,13 @@ import * as fs from "fs";
79
var chocolateyManager : chocolateyCli.ChocolateyCliManager;
810
var installed : boolean = false;
911

12+
const languageServerPaths = [
13+
// TODO: Change path to the actually expected location of the language server
14+
"out/.server/Chocolatey.Language.Server.dll",
15+
"./src/Chocolatey.Language.Server/bin/Release/netcoreapp2.1/Chocolatey.Language.Server.dll",
16+
"./src/Chocolatey.Language.Server/bin/Debug/netcoreapp2.1/Chocolatey.Language.Server.dll"
17+
];
18+
1019
export function activate(context: ExtensionContext): void {
1120
// register Commands
1221
context.subscriptions.push(
@@ -18,6 +27,65 @@ export function activate(context: ExtensionContext): void {
1827
commands.registerCommand("chocolatey.apikey", () => execute("apikey")),
1928
commands.registerCommand("chocolatey.open", async (uri: string) => await commands.executeCommand('vscode.open', Uri.parse(uri)))
2029
);
30+
31+
let config = workspace.getConfiguration("chocolatey.language");
32+
let disableLanguageService: boolean | undefined = false;
33+
34+
if(config !== undefined) {
35+
disableLanguageService = config.get("disableLanguageService")
36+
}
37+
38+
// Only start the Language Service if configured to do so
39+
if(!disableLanguageService) {
40+
let serverExe = 'dotnet';
41+
let serverModule: string | null = null;
42+
for (let p of languageServerPaths) {
43+
p = context.asAbsolutePath(p);
44+
// console.log/p);
45+
if (fs.existsSync(p)) {
46+
serverModule = p;
47+
break;
48+
}
49+
}
50+
51+
// TODO: Decision need to be made if the Language Server should
52+
// be packed inside the vsix file, or downloaded during runtime.
53+
54+
if (!serverModule) { throw new URIError("Cannot find the language server module."); }
55+
let workPath = path.dirname(serverModule);
56+
console.log(`Use ${serverModule} as server module.`);
57+
console.log(`Work path: ${workPath}`);
58+
59+
// If the extension is launched in debug mode then the debug server options are used
60+
// Otherwise the run options are used
61+
let serverOptions: ServerOptions = {
62+
run: { command: serverExe, args: [serverModule], options: { cwd: workPath } },
63+
debug: { command: serverExe, args: [serverModule, "--debug"], options: { cwd: workPath } }
64+
};
65+
66+
// Options to control the language client
67+
let clientOptions: LanguageClientOptions = {
68+
// Register the server for plain text documents
69+
documentSelector: [
70+
{
71+
pattern: '**/*.nuspec',
72+
}
73+
],
74+
synchronize: {
75+
configurationSection: 'chocolatey',
76+
fileEvents: workspace.createFileSystemWatcher('**/*.nuspec')
77+
},
78+
}
79+
80+
// Create the language client and start the client.
81+
const client = new LanguageClient('chocolatey', 'Chocolatey Language Server', serverOptions, clientOptions);
82+
client.trace = Trace.Verbose;
83+
let disposable = client.start();
84+
85+
// Push the disposable to the context's subscriptions so that the
86+
// client can be deactivated on extension deactivation
87+
context.subscriptions.push(disposable);
88+
}
2189
}
2290

2391
function deleteNupkgs():void {

0 commit comments

Comments
 (0)