-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add terraform version change notification
- Loading branch information
Showing
4 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as terraform from '../terraform'; | ||
import * as vscode from 'vscode'; | ||
import { ClientCapabilities, ServerCapabilities, StaticFeature } from 'vscode-languageclient'; | ||
import { ExperimentalClientCapabilities } from './types'; | ||
import TelemetryReporter from '@vscode/extension-telemetry'; | ||
import { LanguageClient } from 'vscode-languageclient/node'; | ||
import { getActiveTextEditor } from '../utils/vscode'; | ||
|
||
export const CLIENT_TERRAFORM_VERSION_CMD_ID = 'client.refreshTerraformVersion'; | ||
|
||
export class TerraformVersionFeature implements StaticFeature { | ||
private disposables: vscode.Disposable[] = []; | ||
|
||
constructor(private client: LanguageClient, private reporter: TelemetryReporter) {} | ||
|
||
public fillClientCapabilities(capabilities: ClientCapabilities & ExperimentalClientCapabilities): void { | ||
if (!capabilities['experimental']) { | ||
capabilities['experimental'] = {}; | ||
} | ||
capabilities['experimental']['refreshTerraformVersionCommandId'] = CLIENT_TERRAFORM_VERSION_CMD_ID; | ||
} | ||
|
||
public async initialize(capabilities: ServerCapabilities): Promise<void> { | ||
if (!capabilities.experimental?.refreshTerraformVersion) { | ||
console.log("Server doesn't support client.refreshTerraformVersion"); | ||
return; | ||
} | ||
|
||
await this.client.onReady(); | ||
|
||
const d = this.client.onRequest(CLIENT_TERRAFORM_VERSION_CMD_ID, async () => { | ||
const editor = getActiveTextEditor(); | ||
if (editor === undefined) { | ||
return; | ||
} | ||
|
||
terraform.getTerraformVersion(editor.document.uri, this.client, this.reporter); | ||
}); | ||
|
||
this.disposables.push(d); | ||
} | ||
|
||
public dispose(): void { | ||
this.disposables.forEach((d: vscode.Disposable) => d.dispose()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters