Skip to content

Commit

Permalink
(#70) Add current Language Server code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gep13 committed Sep 6, 2023
1 parent c6938f4 commit a733fa3
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
43 changes: 43 additions & 0 deletions package-lock.json

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

24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@
}
}
}
},
"chocolatey.language": {
"type": "object",
"properties": {
"allowSuppressionOfRequirements": {
"title": "Allow requirements suppression",
"type": "boolean",
"default": false,
"description": "Allow the suppression of rules that are marked as requirements"
},
"disableLanguageService": {
"title": "Disable language service",
"type": "boolean",
"default": false,
"description": "Prevent the Chocolatey Language Service from starting up"
},
"suppressedRules": {
"title": "Suppress Rules",
"type": "array",
"description": "The codes for the Chocolatey Language Service rules that should be suppressed",
"default": []
}
}
}
}
}
Expand Down Expand Up @@ -153,6 +176,7 @@
"typescript": "^3.8.3"
},
"dependencies": {
"vscode-languageclient": "^6.1.3",
"xml2js": "^0.4.23"
},
"extensionPack": [
Expand Down
68 changes: 68 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { window, commands, workspace, QuickPickItem, ExtensionContext, Uri } from "vscode";
import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient';
import { Trace } from 'vscode-jsonrpc';
import * as chocolateyCli from "./ChocolateyCliManager";
import * as chocolateyOps from "./ChocolateyOperation";
import * as path from "path";
Expand All @@ -7,6 +9,13 @@ import * as fs from "fs";
var chocolateyManager : chocolateyCli.ChocolateyCliManager;
var installed : boolean = false;

const languageServerPaths = [
// TODO: Change path to the actually expected location of the language server
"out/.server/Chocolatey.Language.Server.dll",
"./src/Chocolatey.Language.Server/bin/Release/netcoreapp2.1/Chocolatey.Language.Server.dll",
"./src/Chocolatey.Language.Server/bin/Debug/netcoreapp2.1/Chocolatey.Language.Server.dll"
];

export function activate(context: ExtensionContext): void {
// register Commands
context.subscriptions.push(
Expand All @@ -18,6 +27,65 @@ export function activate(context: ExtensionContext): void {
commands.registerCommand("chocolatey.apikey", () => execute("apikey")),
commands.registerCommand("chocolatey.open", async (uri: string) => await commands.executeCommand('vscode.open', Uri.parse(uri)))
);

let config = workspace.getConfiguration("chocolatey.language");
let disableLanguageService: boolean | undefined = false;

if(config !== undefined) {
disableLanguageService = config.get("disableLanguageService")
}

// Only start the Language Service if configured to do so
if(!disableLanguageService) {
let serverExe = 'dotnet';
let serverModule: string | null = null;
for (let p of languageServerPaths) {
p = context.asAbsolutePath(p);
// console.log/p);
if (fs.existsSync(p)) {
serverModule = p;
break;
}
}

// TODO: Decision need to be made if the Language Server should
// be packed inside the vsix file, or downloaded during runtime.

if (!serverModule) { throw new URIError("Cannot find the language server module."); }
let workPath = path.dirname(serverModule);
console.log(`Use ${serverModule} as server module.`);
console.log(`Work path: ${workPath}`);

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { command: serverExe, args: [serverModule], options: { cwd: workPath } },
debug: { command: serverExe, args: [serverModule, "--debug"], options: { cwd: workPath } }
};

// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [
{
pattern: '**/*.nuspec',
}
],
synchronize: {
configurationSection: 'chocolatey',
fileEvents: workspace.createFileSystemWatcher('**/*.nuspec')
},
}

// Create the language client and start the client.
const client = new LanguageClient('chocolatey', 'Chocolatey Language Server', serverOptions, clientOptions);
client.trace = Trace.Verbose;
let disposable = client.start();

// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
}
}

function deleteNupkgs():void {
Expand Down

0 comments on commit a733fa3

Please sign in to comment.