Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting for workspace root module configuration #423

Merged
merged 5 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
aeschright marked this conversation as resolved.
Show resolved Hide resolved
"items": {
"type": "string"
},
"default": [],
"description": "Per-workspace list of module directories for the language server to read"
paultyng marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to restart, why can't we just use the configuration RPC hook?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just read the LS issue, this is fine if its just the initial implementation and we can improve it over time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radeksimko and I talked through it this morning, this is the simplest option to start with. We'll have to stagger the language server and extension releases to deploy this, so it makes the most sense to do something we know we can ship on the language server quickly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reload will still be necessary with the latest proposed solution (which involves initializationOptions), there's some context here to explain why:
hashicorp/terraform-ls#189 (comment)

}
});
} 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