From a781b0047b35a02d92f4394cb7732a2d0e23cc51 Mon Sep 17 00:00:00 2001 From: Audrey Eschright Date: Fri, 26 Jun 2020 12:37:47 -0700 Subject: [PATCH] Add setting for workspace root modules --- out/extension.js | 26 +++++++++++++++++--------- out/extension.js.map | 2 +- package.json | 5 +++++ src/extension.ts | 26 +++++++++++++++++--------- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/out/extension.js b/out/extension.js index 1ff172671..cb0684a1e 100644 --- a/out/extension.js +++ b/out/extension.js @@ -46,15 +46,17 @@ function activate(context) { stopLsClient(); })); context.subscriptions.push(vscode.workspace.onDidChangeConfiguration((event) => { - if (!event.affectsConfiguration('terraform.languageServer')) { + if (event.affectsConfiguration("terraform")) { + const reloadMsg = "Reload VSCode window to apply language server changes"; + vscode.window.showInformationMessage(reloadMsg, "Reload").then((selected) => { + if (selected === "Reload") { + vscode.commands.executeCommand("workbench.action.reloadWindow"); + } + }); + } + else { return; } - const reloadMsg = 'Reload VSCode window to apply language server changes'; - vscode.window.showInformationMessage(reloadMsg, 'Reload').then((selected) => { - if (selected === 'Reload') { - vscode.commands.executeCommand('workbench.action.reloadWindow'); - } - }); })); if (useLs) { return installThenStart(context, config); @@ -92,11 +94,17 @@ function startLsClient(cmd, config) { const binaryName = cmd.split("/").pop(); let serverOptions; let serverArgs = config.get("languageServer.args"); + let additionalArgs; + if (config.has("rootModules")) { + const rootModules = config.get("rootModules"); + additionalArgs = rootModules.map(module => `-root-module=${module}`); + } + const args = serverArgs.concat(additionalArgs); const setup = vscode.window.createOutputChannel(binaryName); - setup.appendLine(`Launching language server: ${cmd} ${serverArgs}`); + setup.appendLine(`Launching language server: ${cmd} ${args.join(" ")}`); const executable = { command: cmd, - args: serverArgs, + args: args, options: {} }; serverOptions = { diff --git a/out/extension.js.map b/out/extension.js.map index 0278536ad..a6fb20b38 100644 --- a/out/extension.js.map +++ b/out/extension.js.map @@ -1 +1 @@ -{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.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AC;aAC/D;YACD,aAAa,EAAE,KAAK;YACpB,qBAAqB,EAAE,CAAC,CAAC,cAAc;SACvC,CAAC;QAEF,MAAM,GAAG,IAAI,sCAAc,CAC1B,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,aAAa,CACb,CAAC;QAEF,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CAAA;AAED,SAAS,YAAY;IACpB,IAAI,CAAC,MAAM,EAAE;QACZ,OAAO;KACP;IACD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC"} \ No newline at end of file +{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAAiC;AACjC,iEAK+B;AAE/B,uEAAoE;AAGpE,IAAI,MAAsB,CAAC;AAE3B,SAAgB,QAAQ,CAAC,OAAgC;IACxD,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACrE,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAE9D,gCAAgC;IAChC,IAAI,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,EAAE;QACzC,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAC7B,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,EAC7D,IAAI,CACJ,CAAA;KACD;IACD,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAElD,qBAAqB;IAErB,yDAAyD;IACzD,sHAAsH;IACtH,kEAAkE;IAClE,8BAA8B;IAC9B,6DAA6D;IAC7D,iDAAiD;IACjD,OAAO;IACP,6DAA6D;IAC7D,iDAAiD;IACjD,OAAO;IACP,iEAAiE;IACjE,qDAAqD;IACrD,MAAM;IACN,KAAK;IAEL,kBAAk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C,aAAa,CAAC,CAAC;YACxD,cAAc,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,gBAAgB,MAAM,EAAE,CAAC,CAAC;SACrE;QACD,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QAE/C,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QAC5D,KAAK,CAAC,UAAU,CAAC,8BAA8B,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAExE,MAAM,UAAU,GAAe;YAC9B,OAAO,EAAE,GAAG;YACZ,IAAI,EAAE,IAAI;YACV,OAAO,EAAE,EAAE;SACX,CAAA;QACD,aAAa,GAAG;YACf,GAAG,EAAE,UAAU;YACf,KAAK,EAAE,UAAU;SACjB,CAAC;QAEF,MAAM,aAAa,GAA0B;YAC5C,gBAAgB,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;YAC7D,WAAW,EAAE;gBACZ,UAAU,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,CAAC,SAAS,CAAC;aAC/D;YACD,aAAa,EAAE,KAAK;YACpB,qBAAqB,EAAE,CAAC,CAAC,cAAc;SACvC,CAAC;QAEF,MAAM,GAAG,IAAI,sCAAc,CAC1B,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,aAAa,CACb,CAAC;QAEF,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CAAA;AAED,SAAS,YAAY;IACpB,IAAI,CAAC,MAAM,EAAE;QACZ,OAAO;KACP;IACD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index bc730618c..bc1f6ae39 100644 --- a/package.json +++ b/package.json @@ -134,6 +134,11 @@ "maxNumberOfProblems": 100, "trace.server": "off" } + }, + "terraform.rootModules": { + "scope": "resource", + "type": "array", + "description": "Per-workspace list of module directories for the language server to read" } } }, diff --git a/src/extension.ts b/src/extension.ts index 633f4f406..d46f5f70f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -58,15 +58,16 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.workspace.onDidChangeConfiguration( (event: vscode.ConfigurationChangeEvent) => { - if (!event.affectsConfiguration('terraform.languageServer')) { + if (event.affectsConfiguration("terraform")) { + const reloadMsg = "Reload VSCode window to apply language server changes"; + vscode.window.showInformationMessage(reloadMsg, "Reload").then((selected) => { + if (selected === "Reload") { + vscode.commands.executeCommand("workbench.action.reloadWindow"); + } + }); + } else { return; } - const reloadMsg = 'Reload VSCode window to apply language server changes'; - vscode.window.showInformationMessage(reloadMsg, 'Reload').then((selected) => { - if (selected === 'Reload') { - vscode.commands.executeCommand('workbench.action.reloadWindow'); - } - }); } ) ); @@ -104,13 +105,20 @@ async function startLsClient(cmd: string, config: vscode.WorkspaceConfiguration) const binaryName = cmd.split("/").pop(); let serverOptions: ServerOptions; let serverArgs: string[] = config.get("languageServer.args"); + let additionalArgs: string[]; + + if (config.has("rootModules")) { + const rootModules: string[] = config.get("rootModules"); + additionalArgs = rootModules.map(module => `-root-module=${module}`); + } + const args = serverArgs.concat(additionalArgs); const setup = vscode.window.createOutputChannel(binaryName); - setup.appendLine(`Launching language server: ${cmd} ${serverArgs}`) + setup.appendLine(`Launching language server: ${cmd} ${args.join(" ")}`); const executable: Executable = { command: cmd, - args: serverArgs, + args: args, options: {} } serverOptions = {