forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 72493a7 into dev
- Loading branch information
Showing
30 changed files
with
3,109 additions
and
720 deletions.
There are no files selected for viewing
This file contains 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
97 changes: 97 additions & 0 deletions
97
pkg/analysis_server/lib/src/lsp/handlers/code_actions/abstract_code_actions_producer.dart
This file contains 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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:analysis_server/lsp_protocol/protocol.dart'; | ||
import 'package:analysis_server/src/lsp/client_capabilities.dart'; | ||
import 'package:analysis_server/src/lsp/lsp_analysis_server.dart'; | ||
import 'package:analysis_server/src/lsp/mapping.dart'; | ||
import 'package:analysis_server/src/protocol_server.dart' hide Position; | ||
import 'package:analysis_server/src/request_handler_mixin.dart'; | ||
import 'package:analyzer/source/line_info.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
/// A base for classes that produce [CodeAction]s for the LSP handler. | ||
abstract class AbstractCodeActionsProducer | ||
with RequestHandlerMixin<LspAnalysisServer> { | ||
final String path; | ||
final LineInfo lineInfo; | ||
final int offset; | ||
final int length; | ||
final bool Function(CodeActionKind?) shouldIncludeKind; | ||
final LspClientCapabilities capabilities; | ||
|
||
@override | ||
final LspAnalysisServer server; | ||
|
||
AbstractCodeActionsProducer( | ||
this.server, | ||
this.path, | ||
this.lineInfo, { | ||
required this.offset, | ||
required this.length, | ||
required this.shouldIncludeKind, | ||
required this.capabilities, | ||
}); | ||
|
||
String get name; | ||
|
||
Set<DiagnosticTag> get supportedDiagnosticTags => capabilities.diagnosticTags; | ||
|
||
bool get supportsApplyEdit => capabilities.applyEdit; | ||
|
||
bool get supportsCodeDescription => capabilities.diagnosticCodeDescription; | ||
|
||
bool get supportsLiterals => capabilities.literalCodeActions; | ||
|
||
/// Creates a CodeAction to apply this assist. Note: This code will fetch the | ||
/// version of each document being modified so it's important to call this | ||
/// immediately after computing edits to ensure the document is not modified | ||
/// before the version number is read. | ||
@protected | ||
CodeAction createAssistAction( | ||
SourceChange change, String path, LineInfo lineInfo) { | ||
return CodeAction( | ||
title: change.message, | ||
kind: toCodeActionKind(change.id, CodeActionKind.Refactor), | ||
diagnostics: const [], | ||
edit: createWorkspaceEdit(server, change, | ||
allowSnippets: true, filePath: path, lineInfo: lineInfo), | ||
); | ||
} | ||
|
||
/// Creates a CodeAction to apply this fix. Note: This code will fetch the | ||
/// version of each document being modified so it's important to call this | ||
/// immediately after computing edits to ensure the document is not modified | ||
/// before the version number is read. | ||
@protected | ||
CodeAction createFixAction(SourceChange change, Diagnostic diagnostic, | ||
String path, LineInfo lineInfo) { | ||
return CodeAction( | ||
title: change.message, | ||
kind: toCodeActionKind(change.id, CodeActionKind.QuickFix), | ||
diagnostics: [diagnostic], | ||
edit: createWorkspaceEdit(server, change, | ||
allowSnippets: true, filePath: path, lineInfo: lineInfo), | ||
); | ||
} | ||
|
||
Future<List<CodeActionWithPriority>> getAssistActions(); | ||
|
||
Future<List<CodeActionWithPriority>> getFixActions(); | ||
|
||
Future<List<Either2<CodeAction, Command>>> getRefactorActions(); | ||
|
||
Future<List<Either2<CodeAction, Command>>> getSourceActions(); | ||
} | ||
|
||
/// A wrapper that contains an LSP [CodeAction] and a server-supplied priority | ||
/// used for sorting before sending to the client. | ||
class CodeActionWithPriority { | ||
final CodeAction action; | ||
final int priority; | ||
|
||
CodeActionWithPriority(this.action, this.priority); | ||
} |
Oops, something went wrong.