From 99356fe90784b24b034c3bfcbe68bf09298f2d9a Mon Sep 17 00:00:00 2001 From: James Pogran Date: Fri, 24 Sep 2021 12:53:59 -0400 Subject: [PATCH] Conditionally activate the Module View Provider (#792) This detects whether the currently installed Language Server supports the module calls command before calling the Language Server command. This prevents the provider from throwing an error with a LS that doesn't have the command. --- package.json | 2 +- src/providers/moduleProvider.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index fb0a76ceb..df5abdae5 100644 --- a/package.json +++ b/package.json @@ -264,7 +264,7 @@ "viewsWelcome": [ { "view": "terraform.modules", - "contents": "The active editor cannot provide information about installed modules. [Learn more about modules](https://www.terraform.io/docs/language/modules/develop/index.html) You may need to run 'terraform get'" + "contents": "The active editor cannot provide information about installed modules. [Learn more about modules](https://www.terraform.io/docs/language/modules/develop/index.html) You may need to run 'terraform get' or update your language server version." } ] }, diff --git a/src/providers/moduleProvider.ts b/src/providers/moduleProvider.ts index 6c184a985..021305bc8 100644 --- a/src/providers/moduleProvider.ts +++ b/src/providers/moduleProvider.ts @@ -106,6 +106,14 @@ export class ModuleProvider implements vscode.TreeDataProvider { const handler = this.handler.getClient(editor); return await handler.client.onReady().then(async () => { + const moduleCallsSupported = this.handler.clientSupportsCommand( + `${handler.commandPrefix}.terraform-ls.module.calls`, + editor, + ); + if (!moduleCallsSupported) { + return Promise.resolve([]); + } + const params: ExecuteCommandParams = { command: `${handler.commandPrefix}.terraform-ls.module.calls`, arguments: [`uri=${documentURI}`],