diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_code_actions.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_code_actions.dart index a7ccb51183b8..93248df5b21b 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_code_actions.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_code_actions.dart @@ -87,6 +87,11 @@ class CodeActionHandler extends MessageHandler - kind == wanted || kind.toString().startsWith('${wanted.toString()}.'); + kind == wanted || kind.toString().startsWith('$wanted.'); // If the client wants only a specific set, use only that filter. final only = params.context.only; @@ -112,6 +117,30 @@ class CodeActionHandler extends MessageHandler + kind == wanted || wanted.toString().startsWith('$kind.'); + + final only = params.context.only; + if (only != null) { + return only.any(isMatch); + } + + return true; + } + return unit.mapResult((unit) { final startOffset = toOffset(unit.lineInfo, params.range.start); final endOffset = toOffset(unit.lineInfo, params.range.end); @@ -124,6 +153,7 @@ class CodeActionHandler extends MessageHandler _getCodeActions( performance, shouldIncludeKind, + shouldIncludeAnyOfKind, supportsLiteralCodeActions, supportsApplyEdit, supportedDiagnosticTags, @@ -306,6 +336,7 @@ class CodeActionHandler extends MessageHandler>>> _getCodeActions( OperationPerformanceImpl performance, bool Function(CodeActionKind?) shouldIncludeKind, + bool Function(CodeActionKind?) shouldIncludeAnyOfKind, bool supportsLiterals, bool supportsWorkspaceApplyEdit, Set supportedDiagnosticTags, @@ -316,26 +347,31 @@ class CodeActionHandler extends MessageHandler _getSourceActions(shouldIncludeKind, supportsLiterals, - supportsWorkspaceApplyEdit, path), - ), - performance.runAsync( - '_getAssistActions', - (_) => _getAssistActions(shouldIncludeKind, supportsLiterals, path, - range, offset, length, unit), - ), - performance.runAsync( - '_getRefactorActions', - (_) => _getRefactorActions( - shouldIncludeKind, supportsLiterals, path, offset, length, unit), - ), - performance.runAsync( - '_getFixActions', - (_) => _getFixActions(shouldIncludeKind, supportsLiterals, path, offset, - supportedDiagnosticTags, range, unit), - ), + if (shouldIncludeAnyOfKind(CodeActionKind.Source)) + performance.runAsync( + '_getSourceActions', + (_) => _getSourceActions(shouldIncludeKind, supportsLiterals, + supportsWorkspaceApplyEdit, path), + ), + // Assists go under the Refactor CodeActionKind so check that here. + if (shouldIncludeAnyOfKind(CodeActionKind.Refactor)) + performance.runAsync( + '_getAssistActions', + (_) => _getAssistActions(shouldIncludeKind, supportsLiterals, path, + range, offset, length, unit), + ), + if (shouldIncludeAnyOfKind(CodeActionKind.Refactor)) + performance.runAsync( + '_getRefactorActions', + (_) => _getRefactorActions( + shouldIncludeKind, supportsLiterals, path, offset, length, unit), + ), + if (shouldIncludeAnyOfKind(CodeActionKind.QuickFix)) + performance.runAsync( + '_getFixActions', + (_) => _getFixActions(shouldIncludeKind, supportsLiterals, path, + offset, supportedDiagnosticTags, range, unit), + ), ]); final flatResults = results.expand((x) => x).toList();