@@ -50,23 +50,38 @@ import { UserWrittenCodeTracker } from '../tracker/userWrittenCodeTracker'
5050 * It does not contain UI/UX related logic
5151 */
5252
53- // below commands override VS Code inline completion commands
54- const prevCommand = Commands . declare ( 'editor.action.inlineSuggest.showPrevious' , ( ) => async ( ) => {
55- await RecommendationHandler . instance . showRecommendation ( - 1 )
56- } )
57- const nextCommand = Commands . declare ( 'editor.action.inlineSuggest.showNext' , ( ) => async ( ) => {
58- await RecommendationHandler . instance . showRecommendation ( 1 )
59- } )
60-
61- const rejectCommand = Commands . declare ( 'aws.amazonq.rejectCodeSuggestion' , ( ) => async ( ) => {
62- telemetry . record ( {
63- traceId : TelemetryHelper . instance . traceId ,
53+ /**
54+ * Commands as a level of indirection so that declare doesn't intercept any registrations for the
55+ * language server implementation.
56+ *
57+ * Otherwise you'll get:
58+ * "Unable to launch amazonq language server: Command "aws.amazonq.rejectCodeSuggestion" has already been declared by the Toolkit"
59+ */
60+ function createCommands ( ) {
61+ // below commands override VS Code inline completion commands
62+ const prevCommand = Commands . declare ( 'editor.action.inlineSuggest.showPrevious' , ( ) => async ( ) => {
63+ await RecommendationHandler . instance . showRecommendation ( - 1 )
64+ } )
65+ const nextCommand = Commands . declare ( 'editor.action.inlineSuggest.showNext' , ( ) => async ( ) => {
66+ await RecommendationHandler . instance . showRecommendation ( 1 )
6467 } )
6568
66- await vscode . commands . executeCommand ( 'editor.action.inlineSuggest.hide' )
67- RecommendationHandler . instance . reportUserDecisions ( - 1 )
68- await Commands . tryExecute ( 'aws.amazonq.refreshAnnotation' )
69- } )
69+ const rejectCommand = Commands . declare ( 'aws.amazonq.rejectCodeSuggestion' , ( ) => async ( ) => {
70+ telemetry . record ( {
71+ traceId : TelemetryHelper . instance . traceId ,
72+ } )
73+
74+ await vscode . commands . executeCommand ( 'editor.action.inlineSuggest.hide' )
75+ RecommendationHandler . instance . reportUserDecisions ( - 1 )
76+ await Commands . tryExecute ( 'aws.amazonq.refreshAnnotation' )
77+ } )
78+
79+ return {
80+ prevCommand,
81+ nextCommand,
82+ rejectCommand,
83+ }
84+ }
7085
7186const lock = new AsyncLock ( { maxPending : 1 } )
7287
@@ -579,6 +594,7 @@ export class RecommendationHandler {
579594 // They are subscribed when suggestion starts and disposed when suggestion is accepted/rejected
580595 // to avoid impacting other plugins or user who uses this API
581596 private registerCommandOverrides ( ) {
597+ const { prevCommand, nextCommand, rejectCommand } = createCommands ( )
582598 this . prev = prevCommand . register ( )
583599 this . next = nextCommand . register ( )
584600 this . reject = rejectCommand . register ( )
0 commit comments