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

Automatically refresh Terraform Module Calls View #1088

Merged
merged 5 commits into from
May 9, 2022
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
11 changes: 7 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { TelemetryFeature } from './features/telemetry';
import { ShowReferencesFeature } from './features/showReferences';
import { CustomSemanticTokens } from './features/semanticTokens';
import { ModuleProvidersFeature } from './features/moduleProviders';
import { ModuleCallsFeature } from './features/moduleCalls';

const id = 'terraform';
const brand = `HashiCorp Terraform`;
Expand Down Expand Up @@ -133,11 +134,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
}
});

const moduleDataProvider = new ModuleProvidersDataProvider(context, client);
const moduleProvidersDataProvider = new ModuleProvidersDataProvider(context, client);
const moduleCallsDataProvider = new ModuleCallsDataProvider(context, client);

const features: StaticFeature[] = [
new CustomSemanticTokens(client, manifest),
new ModuleProvidersFeature(client, moduleDataProvider),
new ModuleProvidersFeature(client, moduleProvidersDataProvider),
new ModuleCallsFeature(client, moduleCallsDataProvider),
];
if (vscode.env.isTelemetryEnabled) {
features.push(new TelemetryFeature(client, reporter));
Expand Down Expand Up @@ -171,8 +174,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
await execWorkspaceCommand(client, requestParams);
}
}),
vscode.window.registerTreeDataProvider('terraform.modules', new ModuleCallsDataProvider(context, client)),
vscode.window.registerTreeDataProvider('terraform.providers', moduleDataProvider),
vscode.window.registerTreeDataProvider('terraform.modules', moduleCallsDataProvider),
vscode.window.registerTreeDataProvider('terraform.providers', moduleProvidersDataProvider),
vscode.window.onDidChangeVisibleTextEditors(async (editors: readonly vscode.TextEditor[]) => {
const textEditor = editors.find((ed) => !!ed.viewColumn);
if (textEditor?.document === undefined) {
Expand Down
37 changes: 37 additions & 0 deletions src/features/moduleCalls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as vscode from 'vscode';
import { BaseLanguageClient, ClientCapabilities, ServerCapabilities, StaticFeature } from 'vscode-languageclient';
import { ModuleCallsDataProvider } from '../providers/moduleCalls';
import { ExperimentalClientCapabilities } from './types';

const CLIENT_MODULE_CALLS_CMD_ID = 'client.refreshModuleCalls';

export class ModuleCallsFeature implements StaticFeature {
private disposables: vscode.Disposable[] = [];

constructor(private client: BaseLanguageClient, private view: ModuleCallsDataProvider) {}

public fillClientCapabilities(capabilities: ClientCapabilities & ExperimentalClientCapabilities): void {
if (!capabilities['experimental']) {
capabilities['experimental'] = {};
}
capabilities['experimental']['refreshModuleCallsCommandId'] = CLIENT_MODULE_CALLS_CMD_ID;
}

public async initialize(capabilities: ServerCapabilities): Promise<void> {
if (!capabilities.experimental?.refreshModuleCalls) {
console.log('Server does not support client.refreshModuleCalls');
return;
}

await this.client.onReady();

const d = this.client.onRequest(CLIENT_MODULE_CALLS_CMD_ID, () => {
this.view?.refresh();
});
this.disposables.push(d);
}

public dispose(): void {
this.disposables.forEach((d: vscode.Disposable) => d.dispose());
}
}
2 changes: 1 addition & 1 deletion src/features/moduleProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ModuleProvidersFeature implements StaticFeature {
if (!capabilities['experimental']) {
capabilities['experimental'] = {};
}
capabilities['experimental']['refereshModuleProvidersCommandId'] = CLIENT_MODULE_PROVIDERS_CMD_ID;
capabilities['experimental']['refreshModuleProvidersCommandId'] = CLIENT_MODULE_PROVIDERS_CMD_ID;
}

public async initialize(capabilities: ServerCapabilities): Promise<void> {
Expand Down
3 changes: 2 additions & 1 deletion src/features/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ExperimentalClientCapabilities {
experimental: {
telemetryVersion?: number;
showReferencesCommandId?: string;
refereshModuleProvidersCommandId?: string;
refreshModuleProvidersCommandId?: string;
refreshModuleCallsCommandId?: string;
};
}