Skip to content

Adding support for VSCode command suffix's per extension#588

Open
vzhan00 wants to merge 1 commit into
mainfrom
feature/vscode-command-suffix
Open

Adding support for VSCode command suffix's per extension#588
vzhan00 wants to merge 1 commit into
mainfrom
feature/vscode-command-suffix

Conversation

@vzhan00

@vzhan00 vzhan00 commented May 21, 2026

Copy link
Copy Markdown
Contributor

Description of changes:

Fixes duplicate command registration crash when multiple VS Code extensions (e.g., AWS Toolkit and CloudFormation standalone) run the same language server simultaneously.

Problem: vscode-languageclient registers commands from executeCommandProvider in VS Code's global command registry, which doesn't allow duplicates. The second extension to activate crashes with Error: command '/command/template/clear-diagnostic' already exists.

Fix: The server now derives a unique command suffix from initializationOptions.aws.clientInfo.extension.name (already sent by all clients). Each client gets uniquely-suffixed commands (e.g., /command/template/clear-diagnostic.aws.cloudformation), eliminating the collision.

Changes:

  • ExecutionHandler.ts — createCommands(suffix) factory, module-level singleton with initCommands()/getCommands()
  • LspCapabilities.ts — converted from static const to buildCapabilities(commands) function
  • CodeActionService.ts — replaced hardcoded command strings with getCommands() calls
  • standalone.ts — reads extension name from init params, calls initCommands()
  • LspConnection.ts — updated default handler to use buildCapabilities()

Backward compatible: If no extension name is provided, commands remain unsuffixed (original behavior). Currently since we're using the extension name, the existing toolkit suffix will be amazonwebservices.aws-toolkit-vscode and for the standalone it will be aws.cloudformation.

Testing:

  • 3328 unit tests pass
  • Manually verified both Toolkit and standalone extension running simultaneously without crash
  • Verified code actions fire correctly with suffixed commands

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@vzhan00 vzhan00 requested a review from a team as a code owner May 21, 2026 17:35
@vzhan00 vzhan00 changed the title Adding support for command suffix's per extension Adding support for VSCode command suffix's per extension May 21, 2026
Comment thread src/app/standalone.ts
staticInitialize(params.clientInfo, params.initializationOptions?.['aws']);

const name = params.initializationOptions?.aws?.clientInfo?.extension?.name;
const suffix = typeof name === 'string' ? name : undefined;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should only allow this if its a string, otherwise throw

import { TelemetryService } from '../telemetry/TelemetryService';
import { getRegion } from '../utils/Region';

export const CLEAR_DIAGNOSTIC = '/command/template/clear-diagnostic';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Instead of this singleton pattern, can the suffix be used to directly create LspCapabilities + LspConnection. Then just send the capabilities which has the set of commands directly to CfnServer creation and pass the commands down to execution handler and code action handler?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants