Skip to content

Commit

Permalink
fix: check server init command presence before use
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Sep 14, 2021
1 parent 6ad18a4 commit cdfc81f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/clientHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ export class ClientHandler {
return clients.get(this.clientName(document.toString()));
}

public clientSupportsCommand(cmdName: string, document?: vscode.Uri): boolean {
const commands = this.getClient(document).client.initializeResult.capabilities.executeCommandProvider?.commands;
return commands.includes(cmdName);
}

private clientName(folderName: string, workspaceFolders: readonly string[] = sortedWorkspaceFolders()): string {
folderName = normalizeFolderName(folderName);
const outerFolder = workspaceFolders.find((element) => folderName.startsWith(element));
Expand Down
10 changes: 4 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
}),
vscode.window.onDidChangeVisibleTextEditors(async () => {
const textEditor = getActiveTextEditor();
await updateTerraformStatusBar(textEditor.document.uri, lsPath);
await updateTerraformStatusBar(textEditor.document.uri);
}),
);

Expand All @@ -143,11 +143,9 @@ export function deactivate(): Promise<void[]> {
return clientHandler.stopClients();
}

async function updateTerraformStatusBar(documentUri: vscode.Uri, lsPath: ServerPath) {
// Make sure there's an open document in a folder
// Also check whether they're running a different language server
// TODO: Check initializationOptions for command presence instead of pathToBinary
if (!lsPath.hasCustomBinPath()) {
async function updateTerraformStatusBar(documentUri: vscode.Uri) {
const initSupported = clientHandler.clientSupportsCommand('terraform-ls.terraform.init', documentUri);
if (initSupported) {
const client = clientHandler.getClient(documentUri);
const moduleUri = Utils.dirname(documentUri);

Expand Down

0 comments on commit cdfc81f

Please sign in to comment.