Add configuration option for adl-server path (#395)
This commit is contained in:
Родитель
72afcd17ba
Коммит
0a344db306
|
@ -1,40 +1,55 @@
|
|||
import { ExtensionContext } from "vscode";
|
||||
import { ExtensionContext, workspace } from "vscode";
|
||||
import { LanguageClient, LanguageClientOptions, Executable } from "vscode-languageclient/node.js";
|
||||
|
||||
let client: LanguageClient | undefined;
|
||||
|
||||
export function activate(context: ExtensionContext) {
|
||||
const id = "adlLanguageServer";
|
||||
const name = "ADL Language Server";
|
||||
const exe = resolveADLServer(context);
|
||||
|
||||
const options: LanguageClientOptions = {
|
||||
documentSelector: [{ scheme: "file", language: "adl" }],
|
||||
};
|
||||
|
||||
const name = "ADL";
|
||||
const id = "adlLanguageServer";
|
||||
client = new LanguageClient(id, name, { run: exe, debug: exe }, options);
|
||||
client.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* In development, resolve to the locally built server.js, and when installed
|
||||
* from VSIX, resolve to the globally installed `@azure-tools/adl` package using
|
||||
* adl-server on PATH.
|
||||
*
|
||||
* Eventually, we'll want to prefer a local install of the adl package to the
|
||||
* user's project location, but that isn't implemented yet.
|
||||
*/
|
||||
function resolveADLServer(context: ExtensionContext): Executable {
|
||||
const nodeOptions = process.env.ADL_SERVER_NODE_OPTIONS;
|
||||
const args = ["--stdio"];
|
||||
|
||||
// In development mode (F5 launch from source), resolve to locally built adl-server.js.
|
||||
if (process.env.ADL_DEVELOPMENT_MODE) {
|
||||
const script = context.asAbsolutePath("../adl/cmd/adl-server.js");
|
||||
// we use CLI instead of NODE_OPTIONS environment variable in this case
|
||||
// because --nolazy is not supported by NODE_OPTIONS.
|
||||
const options = nodeOptions?.split(" ") ?? [];
|
||||
return { command: "node", args: [...options, script, ...args] };
|
||||
}
|
||||
|
||||
const command = process.platform === "win32" ? "adl-server.cmd" : "adl-server";
|
||||
// In production, first try VS Code configuration, which allows a global machine
|
||||
// location that is not on PATH, or a workspace-specific installation.
|
||||
let command = workspace.getConfiguration().get("adl.adl-server.path") as string;
|
||||
if (command && typeof command !== "string") {
|
||||
throw new Error("VS Code configuration option 'adl.adl-server.path' must be a string");
|
||||
}
|
||||
|
||||
if (command?.includes("${workspaceRoot}")) {
|
||||
const workspaceRoot = workspace.workspaceFolders?.[0]?.uri?.fsPath ?? "";
|
||||
command = command.replace("${workspaceRoot}", workspaceRoot);
|
||||
}
|
||||
|
||||
// Default to adl-server on PATH, which would come from `npm install -g
|
||||
// @azure-tools/adl` in a vanilla setup.
|
||||
if (!command) {
|
||||
command = "adl-server";
|
||||
}
|
||||
|
||||
if (process.platform === "win32" && !command.endsWith(".cmd")) {
|
||||
command += ".cmd";
|
||||
}
|
||||
|
||||
return { command, args, options: { env: { NODE_OPTIONS: nodeOptions } } };
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,19 @@
|
|||
"configuration": "./language-configuration.json"
|
||||
}
|
||||
],
|
||||
"configuration": [
|
||||
{
|
||||
"title": "ADL Language Server Path",
|
||||
"properties": {
|
||||
"adl.adl-server.path": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "Path to `adl-server` command that runs the ADL language server.\n\nIf not specified, then `adl-server` found on PATH is used.\n\nExample (User): /usr/local/bin/adl-server\nExample (Workspace): ${workspaceRoot}/node_modules/.bin/adl-server",
|
||||
"scope": "machine-overridable"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"grammars": [
|
||||
{
|
||||
"language": "adl",
|
||||
|
|
Загрузка…
Ссылка в новой задаче