@@ -6,10 +6,10 @@ import 'dart:async';
6
6
7
7
import 'package:analysis_server/lsp_protocol/protocol.dart' ;
8
8
import 'package:analysis_server/src/analysis_server.dart' ;
9
- import 'package:analysis_server/src/lsp/client_capabilities.dart' ;
10
9
import 'package:analysis_server/src/lsp/error_or.dart' ;
11
10
import 'package:analysis_server/src/lsp/handlers/handler_states.dart' ;
12
11
import 'package:analysis_server/src/lsp/handlers/handlers.dart' ;
12
+ import 'package:analysis_server/src/server/message_scheduler.dart' ;
13
13
import 'package:analysis_server/src/server/performance.dart' ;
14
14
import 'package:analyzer/src/util/performance/operation_performance.dart' ;
15
15
import 'package:dtd/dtd.dart' ;
@@ -63,6 +63,54 @@ class DtdServices {
63
63
64
64
DtdConnectionState get state => _state;
65
65
66
+ /// Executes the LSP handler [messageHandler] with [params] and returns the
67
+ /// results as a map to provide back to DTD.
68
+ ///
69
+ /// If the handler fails, throws an [RpcException] to be propagated to the
70
+ /// client.
71
+ void processMessage (
72
+ IncomingMessage message,
73
+ OperationPerformanceImpl performance,
74
+ Completer <Map <String , Object ?>> completer) async {
75
+ // (TODO:keertip) Lookup the right handler, execute and return results.
76
+ // For now, complete with exception.
77
+ completer.completeError (RpcException (
78
+ ErrorCodes .InvalidRequest .toJson (),
79
+ 'DTD requests are not yet supported' ,
80
+ ));
81
+
82
+ // (TODO:keertip) Uncomment when lookup has been implemented
83
+ // var info = MessageInfo(
84
+ // performance: performance,
85
+ // // DTD clients requests are always executed with a fixed set of
86
+ // // capabilities so that the responses don't change in format based on the
87
+ // // owning editor.
88
+ // clientCapabilities: fixedBasicLspClientCapabilities,
89
+ // );
90
+ // var token = NotCancelableToken(); // We don't currently support cancel.
91
+
92
+ // // Execute the handler.
93
+ // var result = await messageHandler.handleMessage(message, info, token);
94
+
95
+ // // Map the result (or error) on to what a DTD handler needs to return.
96
+ // return result.map(
97
+ // // Map LSP errors on to equiv JSON-RPC errors for DTD.
98
+ // (error) => throw RpcException(
99
+ // error.code.toJson(),
100
+ // error.message,
101
+ // data: error.data,
102
+ // ),
103
+ // // DTD requires that all results are a Map and that they contain a
104
+ // // 'type' field. This differs slightly from LSP where we could return a
105
+ // // boolean (for example). This means we need to put the result in a
106
+ // // field, which we're calling 'result'.
107
+ // (result) => {
108
+ // 'type': result?.runtimeType.toString(),
109
+ // 'result': result,
110
+ // },
111
+ // );
112
+ }
113
+
66
114
/// Closes the connection to DTD and cleans up.
67
115
void _close ([DtdConnectionState state = DtdConnectionState .Disconnected ]) {
68
116
_state = state;
@@ -122,54 +170,26 @@ class DtdServices {
122
170
}
123
171
}
124
172
125
- /// Executes the LSP handler [messageHandler] with [params] and returns the
126
- /// results as a map to provide back to DTD.
127
- ///
128
- /// If the handler fails, throws an [RpcException] to be propagated to the
129
- /// client.
173
+ /// The incoming request is sent to the [MessageScheduler] for execution.
174
+ /// A completer is returned which will be completed with the result of the
175
+ /// execution of the request by the corresponding [MessageHandler] .
130
176
Future <Map <String , Object ?>> _executeLspHandler (
131
177
MessageHandler <Object ?, Object ?, AnalysisServer > messageHandler,
132
178
Parameters params,
133
179
OperationPerformanceImpl performance,
134
180
) async {
135
- // TODO(dantup): Currently the handler just runs immediately, but this
136
- // should interact with the scheduler in future.
137
-
138
181
// Map the incoming request into types we use for LSP request handling.
139
182
var message = IncomingMessage (
140
183
jsonrpc: jsonRpcVersion,
141
184
method: messageHandler.handlesMessage,
142
185
params: params.asMap,
143
186
);
144
- var info = MessageInfo (
145
- performance: performance,
146
- // DTD clients requests are always executed with a fixed set of
147
- // capabilities so that the responses don't change in format based on the
148
- // owning editor.
149
- clientCapabilities: fixedBasicLspClientCapabilities,
150
- );
151
- var token = NotCancelableToken (); // We don't currently support cancel.
152
-
153
- // Execute the handler.
154
- var result = await messageHandler.handleMessage (message, info, token);
155
-
156
- // Map the result (or error) on to what a DTD handler needs to return.
157
- return result.map (
158
- // Map LSP errors on to equiv JSON-RPC errors for DTD.
159
- (error) => throw RpcException (
160
- error.code.toJson (),
161
- error.message,
162
- data: error.data,
163
- ),
164
- // DTD requires that all results are a Map and that they contain a
165
- // 'type' field. This differs slightly from LSP where we could return a
166
- // boolean (for example). This means we need to put the result in a
167
- // field, which we're calling 'result'.
168
- (result) => {
169
- 'type' : result? .runtimeType.toString (),
170
- 'result' : result,
171
- },
172
- );
187
+ var scheduler = _server.messageScheduler;
188
+ var completer = Completer <Map <String , Object ?>>();
189
+ scheduler.add (DtdMessage (
190
+ message: message, performance: performance, completer: completer));
191
+ scheduler.notify ();
192
+ return completer.future;
173
193
}
174
194
175
195
/// Handles an unexpected error occurring on the DTD connection by logging and
0 commit comments