Skip to content
Snippets Groups Projects
Commit b5eadcf8 authored by Stekelenburg, A.V. (Alexander, Student )'s avatar Stekelenburg, A.V. (Alexander, Student )
Browse files

Get language server location from configuration

parent 384ec875
No related branches found
No related tags found
No related merge requests found
......@@ -66,8 +66,7 @@
"properties": {
"modest.executableLocation": {
"type": "string",
"default": "C:\\Program Files\\modest\\modest.exe",
"description": "Location of the Modest executable"
"description": "Location of the Modest toolset executable"
}
}
}
......
import { pathToFileURL } from 'url';
import { provider } from './extension';
import { provider, modestExecutable } from './extension';
import * as vscode from 'vscode';
import * as path from "path";
......@@ -8,24 +8,6 @@ export namespace ModestCommands {
const paramHistory: Map<string, string> = new Map();
function modestExecutable(): string | undefined {
let executable: string | undefined =
vscode.workspace.getConfiguration("modest").get("executableLocation");
if (executable === undefined || executable === "") {
vscode.window.showErrorMessage(
"It looks like you don't have the modest executable located yet.", "Go to settings")
.then(result => {
if (result !== undefined) {
vscode.commands.executeCommand("workbench.action.openSettings", "modest.executableLocation");
}
});
return;
}
// Surround any directory with whitespace in quotes
return executable.split(path.sep).map(value => value.match(/\s/) ? `"${value}"` : value).join(path.sep);
}
export let addParameters = vscode.commands.registerCommand('modest.add-parameters', async () => {
provider.sendMessage({
type: "update",
......
......@@ -16,15 +16,50 @@ import {
TransportKind
} from 'vscode-languageclient/node';
import { ModestCommands } from "./commands";
import * as path from "path";
import { fstat, existsSync } from 'fs';
let client: LanguageClient;
let client: LanguageClient | undefined;
export let provider: ModestSidebarProvider;
export function activate(context: ExtensionContext) {
export function modestExecutable(): string | undefined {
let executable: string | undefined =
vscode.workspace.getConfiguration("modest").get("executableLocation");
if (executable === undefined || executable === "") {
vscode.window.showErrorMessage(
"It looks like you don't have the modest executable located yet.", "Go to settings")
.then(result => {
if (result !== undefined) {
vscode.commands.executeCommand("workbench.action.openSettings", "modest.executableLocation");
}
});
return;
}
return executable;
}
function createClient(): LanguageClient | undefined{
// TODO: Check if path exists for a better user experience(so it doesn't spam the user with errors)
// The server is implemented in node
//let serverExe = "D:\\Desktop\\designproject\\modest-toolset\\Binaries\\Release\\win-x64\\Modest.LanguageServer.exe";
let serverExe = "C:\\Users\\anoni\\Desktop\\University projects\\module 11\\toolset\\Binaries\\Debug\\win-x64\\Modest.LanguageServer.exe";
let serverExe = modestExecutable();
if (serverExe === undefined) {
return;
}
if (!existsSync(serverExe)) {
vscode.window.showErrorMessage(
"The specified modest executable could not be found", "Go to settings")
.then(result => {
if (result !== undefined) {
vscode.commands.executeCommand("workbench.action.openSettings", "modest.executableLocation");
}
});
return;
}
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
......@@ -32,12 +67,14 @@ export function activate(context: ExtensionContext) {
// run: { command: serverExe, args: ['-lsp', '-d'] },
run: {
command: serverExe,
args: ['startlspserver'],
transport: TransportKind.stdio,
},
// debug: { command: serverExe, args: ['-lsp', '-d'] }
debug: {
command: serverExe,
command: "dotnet",
transport: TransportKind.stdio,
args: [serverExe.replace(".exe", "") + ".dll", 'startlspserver'], // Hacky
runtime: "",
},
};
......@@ -58,23 +95,44 @@ export function activate(context: ExtensionContext) {
//},
};
context.subscriptions.push(ModestCommands.simCommand);
context.subscriptions.push(ModestCommands.addParameters);
// Create the language client and start the client.
client = new LanguageClient(
const client = new LanguageClient(
"ModestExtension",
"Modest Extension",
serverOptions,
clientOptions);
client.registerProposedFeatures();
client.trace = Trace.Verbose;
let langClient = client.start();
return client;
}
export function activate(context: ExtensionContext) {
client = createClient();
if (client) {
let langClient = client.start();
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(langClient);
}
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(langClient);
context.subscriptions.push(ModestCommands.simCommand);
context.subscriptions.push(ModestCommands.addParameters);
vscode.workspace.onDidChangeConfiguration(a => {
if (a.affectsConfiguration("modest.executableLocation")) {
if (client) {
client.stop();
client = undefined;
}
client = createClient();
if (client) {
let langClient = client.start();
context.subscriptions.push(langClient);
}
}
});
provider = new ModestSidebarProvider(context.extensionUri);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment