-
Notifications
You must be signed in to change notification settings - Fork 8
Adding support for VSCode command suffix's per extension #588
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
Open
vzhan00
wants to merge
1
commit into
main
Choose a base branch
from
feature/vscode-command-suffix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,6 +4,34 @@ import { LoggerFactory } from '../telemetry/LoggerFactory'; | |
| import { TelemetryService } from '../telemetry/TelemetryService'; | ||
| import { getRegion } from '../utils/Region'; | ||
|
|
||
| export const CLEAR_DIAGNOSTIC = '/command/template/clear-diagnostic'; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| export const TRACK_CODE_ACTION_ACCEPTED = '/command/codeAction/track'; | ||
| export const UPDATE_REGION = '/command/region/update'; | ||
|
|
||
| export function createCommands(suffix?: string) { | ||
| const s = suffix ? `.${suffix}` : ''; | ||
| return { | ||
| clearDiagnostic: `${CLEAR_DIAGNOSTIC}${s}`, | ||
| trackCodeAction: `${TRACK_CODE_ACTION_ACCEPTED}${s}`, | ||
| updateRegion: `${UPDATE_REGION}${s}`, | ||
| }; | ||
| } | ||
|
|
||
| export type Commands = ReturnType<typeof createCommands>; | ||
|
|
||
| // Module-level singleton. initCommands() must be called during onInitialize | ||
| // before any workspace/executeCommand requests arrive. This is safe because | ||
| // LSP guarantees no requests are sent until after the initialize handshake. | ||
| let resolvedCommands: Commands = createCommands(); | ||
|
|
||
| export function initCommands(suffix?: string) { | ||
| resolvedCommands = createCommands(suffix); | ||
| } | ||
|
|
||
| export function getCommands(): Commands { | ||
| return resolvedCommands; | ||
| } | ||
|
|
||
| export function executionHandler( | ||
| components: ServerComponents, | ||
| ): ServerRequestHandler<ExecuteCommandParams, unknown, never, void> { | ||
|
|
@@ -12,7 +40,7 @@ export function executionHandler( | |
| TelemetryService.instance.get('ExecutionHandler').count(`count.${params.command}`, 1); | ||
|
|
||
| switch (params.command) { | ||
| case CLEAR_DIAGNOSTIC: { | ||
| case resolvedCommands.clearDiagnostic: { | ||
| const args = params.arguments ?? []; | ||
| if (args.length >= 2) { | ||
| const uri = args[0] as string; | ||
|
|
@@ -26,15 +54,15 @@ export function executionHandler( | |
| } | ||
| break; | ||
| } | ||
| case TRACK_CODE_ACTION_ACCEPTED: { | ||
| case resolvedCommands.trackCodeAction: { | ||
| const args = params.arguments ?? []; | ||
| if (args.length > 0) { | ||
| const actionType = args[0] as string; | ||
| TelemetryService.instance.get('CodeAction').count(`accepted.${actionType}`, 1); | ||
| } | ||
| break; | ||
| } | ||
| case UPDATE_REGION: { | ||
| case resolvedCommands.updateRegion: { | ||
| const args = params.arguments ?? []; | ||
| if (args.length > 0) { | ||
| components.awsCredentials.handleIamCredentialsDelete(); | ||
|
|
@@ -49,7 +77,3 @@ export function executionHandler( | |
| } | ||
| }; | ||
| } | ||
|
|
||
| export const CLEAR_DIAGNOSTIC = '/command/template/clear-diagnostic'; | ||
| export const TRACK_CODE_ACTION_ACCEPTED = '/command/codeAction/track'; | ||
| export const UPDATE_REGION = '/command/region/update'; | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,43 +1,45 @@ | ||
| import { InitializeResult, TextDocumentSyncKind, CodeActionKind } from 'vscode-languageserver'; | ||
| import { CLEAR_DIAGNOSTIC, TRACK_CODE_ACTION_ACCEPTED, UPDATE_REGION } from '../handlers/ExecutionHandler'; | ||
| import { Commands } from '../handlers/ExecutionHandler'; | ||
| import { ExtensionName, ExtensionVersion } from '../utils/ExtensionConfig'; | ||
|
|
||
| export const LspCapabilities: InitializeResult = { | ||
| capabilities: { | ||
| textDocumentSync: { | ||
| openClose: true, | ||
| change: TextDocumentSyncKind.Incremental, | ||
| willSave: false, | ||
| willSaveWaitUntil: false, | ||
| save: { | ||
| includeText: true, | ||
| export function buildCapabilities(commands: Commands): InitializeResult { | ||
| return { | ||
| capabilities: { | ||
| textDocumentSync: { | ||
| openClose: true, | ||
| change: TextDocumentSyncKind.Incremental, | ||
| willSave: false, | ||
| willSaveWaitUntil: false, | ||
| save: { | ||
| includeText: true, | ||
| }, | ||
| }, | ||
| }, | ||
| hoverProvider: true, | ||
| codeActionProvider: { | ||
| resolveProvider: false, | ||
| codeActionKinds: [CodeActionKind.RefactorExtract], | ||
| }, | ||
| completionProvider: { | ||
| triggerCharacters: ['.', '!', ':', '\n', '\t', '"'], | ||
| completionItem: { | ||
| labelDetailsSupport: true, | ||
| hoverProvider: true, | ||
| codeActionProvider: { | ||
| resolveProvider: false, | ||
| codeActionKinds: [CodeActionKind.RefactorExtract], | ||
| }, | ||
| }, | ||
| definitionProvider: true, | ||
| documentSymbolProvider: true, | ||
| executeCommandProvider: { | ||
| commands: [CLEAR_DIAGNOSTIC, TRACK_CODE_ACTION_ACCEPTED, UPDATE_REGION], | ||
| }, | ||
| workspace: { | ||
| workspaceFolders: { | ||
| supported: true, | ||
| changeNotifications: true, | ||
| completionProvider: { | ||
| triggerCharacters: ['.', '!', ':', '\n', '\t', '"'], | ||
| completionItem: { | ||
| labelDetailsSupport: true, | ||
| }, | ||
| }, | ||
| definitionProvider: true, | ||
| documentSymbolProvider: true, | ||
| executeCommandProvider: { | ||
| commands: [commands.clearDiagnostic, commands.trackCodeAction, commands.updateRegion], | ||
| }, | ||
| workspace: { | ||
| workspaceFolders: { | ||
| supported: true, | ||
| changeNotifications: true, | ||
| }, | ||
| }, | ||
| }, | ||
| serverInfo: { | ||
| name: ExtensionName, | ||
| version: ExtensionVersion, | ||
| }, | ||
| }, | ||
| serverInfo: { | ||
| name: ExtensionName, | ||
| version: ExtensionVersion, | ||
| }, | ||
| }; | ||
| }; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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