@@ -31,14 +31,36 @@ enum EditorMethod {
31
31
/// TODO(https://github.com/flutter/devtools/issues/8824): Add tests that these
32
32
/// are in-sync with analysis_server.
33
33
enum LspMethod {
34
+ codeAction (methodName: 'textDocument/codeAction' ),
34
35
editableArguments (methodName: 'dart/textDocument/editableArguments' ),
35
- editArgument (methodName: 'dart/textDocument/editArgument' );
36
+ editArgument (methodName: 'dart/textDocument/editArgument' ),
37
+ executeCommand (methodName: 'workspace/executeCommand' );
36
38
37
39
const LspMethod ({required this .methodName});
38
40
41
+ /// Returns the [LspMethod] for the given [methodName] .
42
+ ///
43
+ /// If the [methodName] does not exist, returns null.
44
+ static LspMethod ? fromMethodName (String methodName) =>
45
+ _methodNameToMethodLookup[methodName];
46
+
39
47
final String methodName;
40
48
41
- String get experimentalMethodName => 'experimental/$methodName ' ;
49
+ static final _methodNameToMethodLookup = < String , LspMethod > {
50
+ for (final method in LspMethod .values) method.methodName: method,
51
+ };
52
+
53
+ static final _registrationStatus = < LspMethod , bool > {
54
+ for (final method in LspMethod .values) method: false ,
55
+ };
56
+
57
+ /// Sets the registration status for this LSP method.
58
+ set isRegistered (bool isRegistered) {
59
+ _registrationStatus[this ] = isRegistered;
60
+ }
61
+
62
+ /// Gets the current registration status of this LSP method.
63
+ bool get isRegistered => _registrationStatus[this ] ?? false ;
42
64
}
43
65
44
66
/// Known kinds of events that may come from the editor.
@@ -82,12 +104,14 @@ enum EditorEventKind {
82
104
/// Constants for all fields used in JSON maps to avoid literal strings that
83
105
/// may have typos sprinkled throughout the API classes.
84
106
abstract class Field {
107
+ static const actions = 'actions' ;
85
108
static const active = 'active' ;
86
109
static const anchor = 'anchor' ;
87
110
static const arguments = 'arguments' ;
88
111
static const backgroundColor = 'backgroundColor' ;
89
112
static const category = 'category' ;
90
113
static const character = 'character' ;
114
+ static const command = 'command' ;
91
115
static const debuggerType = 'debuggerType' ;
92
116
static const debugSession = 'debugSession' ;
93
117
static const debugSessionId = 'debugSessionId' ;
@@ -115,6 +139,7 @@ abstract class Field {
115
139
static const isEditable = 'isEditable' ;
116
140
static const isNullable = 'isNullable' ;
117
141
static const isRequired = 'isRequired' ;
142
+ static const kind = 'kind' ;
118
143
static const line = 'line' ;
119
144
static const name = 'name' ;
120
145
static const options = 'options' ;
@@ -133,6 +158,7 @@ abstract class Field {
133
158
static const supportsForceExternal = 'supportsForceExternal' ;
134
159
static const textDocument = 'textDocument' ;
135
160
static const theme = 'theme' ;
161
+ static const title = 'title' ;
136
162
static const type = 'type' ;
137
163
static const uri = 'uri' ;
138
164
static const value = 'value' ;
@@ -501,6 +527,63 @@ class EditableArgumentsResult with Serializable {
501
527
};
502
528
}
503
529
530
+ /// Constants for [CodeActionCommand] prefixes used to filter the results
531
+ /// returned by an [LspMethod.codeAction] request.
532
+ abstract class CodeActionPrefixes {
533
+ static const flutterWrap = 'refactor.flutter.wrap' ;
534
+ }
535
+
536
+ /// The result of an [LspMethod.codeAction] request to the Analysis Server.
537
+ ///
538
+ /// Contains a list of [CodeActionCommand] s that can be performed.
539
+ class CodeActionResult with Serializable {
540
+ CodeActionResult ({required this .actions});
541
+
542
+ CodeActionResult .fromJson (List <Map <String , Object ?>> list)
543
+ : this (actions: list.map (CodeActionCommand .fromJson).toList ());
544
+
545
+ final List <CodeActionCommand > actions;
546
+
547
+ @override
548
+ Map <String , Object ?> toJson () => {Field .actions: actions};
549
+ }
550
+
551
+ /// A code action (also known as a "Refactor" or "Quick Fix") that can be called
552
+ /// via an [LspMethod.executeCommand] request.
553
+ ///
554
+ /// For example, "Wrap with Center" or "Wrap with Container".
555
+ class CodeActionCommand with Serializable {
556
+ CodeActionCommand ({
557
+ required this .command,
558
+ required this .title,
559
+ required this .args,
560
+ });
561
+
562
+ CodeActionCommand .fromJson (Map <String , Object ?> map)
563
+ : this (
564
+ command: map[Field .command] as String ,
565
+ title: map[Field .title] as String ,
566
+ args: map[Field .arguments] as List <Object ?>? ?? < Object ? > [],
567
+ );
568
+
569
+ /// The command identifier to send to [LspMethod.executeCommand] .
570
+ final String command;
571
+
572
+ /// The human-readable title of the command, e.g., "Wrap with Center".
573
+ final String title;
574
+
575
+ /// Arguments that should be passed to [LspMethod.executeCommand] when
576
+ /// invoking this action.
577
+ final List <Object ?> args;
578
+
579
+ @override
580
+ Map <String , Object ?> toJson () => {
581
+ Field .command: command,
582
+ Field .title: title,
583
+ Field .arguments: args,
584
+ };
585
+ }
586
+
504
587
/// Errors that the Analysis Server returns for failed argument edits.
505
588
///
506
589
/// These should be kept in sync with the error coes defined at
@@ -554,16 +637,17 @@ enum EditArgumentError {
554
637
}
555
638
}
556
639
557
- /// Response to an edit argument request.
558
- class EditArgumentResponse {
559
- EditArgumentResponse ({required this .success, this .errorMessage, errorCode})
560
- : _errorCode = errorCode;
640
+ /// Generic response representing whether a request was a [success] .
641
+ class GenericApiResponse {
642
+ GenericApiResponse ({
643
+ required this .success,
644
+ this .errorMessage,
645
+ this .errorCode,
646
+ });
561
647
562
648
final bool success;
563
649
final String ? errorMessage;
564
- final int ? _errorCode;
565
-
566
- EditArgumentError ? get errorType => EditArgumentError .fromCode (_errorCode);
650
+ final int ? errorCode;
567
651
}
568
652
569
653
/// Information about a single editable argument of a widget.
0 commit comments