Skip to content

Commit

Permalink
Add setting for workspace root module configuration (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschright authored Jul 14, 2020
1 parent 5469e4c commit 698158f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 19 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ The HashiCorp Terraform Visual Studio Code (VS Code) extension adds syntax highl
- Closes braces and quotes
- Includes `for_each` and `variable` syntax shortcuts (`fore`, `vare`, `varm`)

## Configuration

If you have multiple root modules in your workspace, you can configure the language server settings to identify them. Edit this through the VSCode Settings UI or add a `.vscode/settings.json` file using the following template:
```
{
"terraform-ls.rootModules": [
"/module1",
"/module2"
]
}
```

## Release History

**v2.0.0** is the first official release from HashiCorp, prior releases were by [Mikael Olenfalk](https://github.com/mauve).
Expand Down
23 changes: 14 additions & 9 deletions out/extension.js

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

2 changes: 1 addition & 1 deletion out/extension.js.map

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

9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@
"maxNumberOfProblems": 100,
"trace.server": "off"
}
},
"terraform-ls.rootModules": {
"scope": "resource",
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "Per-workspace list of module directories for the language server to read"
}
}
},
Expand Down
22 changes: 13 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") || event.affectsConfiguration("terraform-ls")) {
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');
}
});
}
)
);
Expand Down Expand Up @@ -102,11 +103,13 @@ async function installThenStart(context: vscode.ExtensionContext, config: vscode

async function startLsClient(cmd: string, config: vscode.WorkspaceConfiguration) {
const binaryName = cmd.split("/").pop();
const lsConfig = vscode.workspace.getConfiguration("terraform-ls");
const serverArgs: string[] = config.get("languageServer.args");
let serverOptions: ServerOptions;
let serverArgs: string[] = config.get("languageServer.args");
let initializationOptions = { rootModulePaths: lsConfig.get("rootModules") };

const setup = vscode.window.createOutputChannel(binaryName);
setup.appendLine(`Launching language server: ${cmd} ${serverArgs}`)
setup.appendLine(`Launching language server: ${cmd} ${serverArgs.join(" ")}`);

const executable: Executable = {
command: cmd,
Expand All @@ -123,6 +126,7 @@ async function startLsClient(cmd: string, config: vscode.WorkspaceConfiguration)
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.tf')
},
initializationOptions: initializationOptions,
outputChannel: setup,
revealOutputChannelOn: 4 // hide always
};
Expand Down

0 comments on commit 698158f

Please sign in to comment.