diff --git a/packages/language-server/src/server.ts b/packages/language-server/src/server.ts index 6c93ab8f6..57fb3e246 100644 --- a/packages/language-server/src/server.ts +++ b/packages/language-server/src/server.ts @@ -161,6 +161,9 @@ export function startServer(options?: LSOptions) { ); const clientSupportApplyEditCommand = !!evt.capabilities.workspace?.applyEdit; + const clientCodeActionCapabilities = evt.capabilities.textDocument?.codeAction; + const clientSupportedCodeActionKinds = + clientCodeActionCapabilities?.codeActionLiteralSupport?.codeActionKind.valueSet; return { capabilities: { @@ -207,15 +210,19 @@ export function startServer(options?: LSOptions) { colorProvider: true, documentSymbolProvider: true, definitionProvider: true, - codeActionProvider: evt.capabilities.textDocument?.codeAction - ?.codeActionLiteralSupport + codeActionProvider: clientCodeActionCapabilities?.codeActionLiteralSupport ? { codeActionKinds: [ CodeActionKind.QuickFix, CodeActionKind.SourceOrganizeImports, SORT_IMPORT_CODE_ACTION_KIND, ...(clientSupportApplyEditCommand ? [CodeActionKind.Refactor] : []) - ] + ].filter( + clientSupportedCodeActionKinds && + evt.initializationOptions.shouldFilterCodeActionKind + ? (kind) => clientSupportedCodeActionKinds.includes(kind) + : () => true + ) } : true, executeCommandProvider: clientSupportApplyEditCommand