File tree Expand file tree Collapse file tree 2 files changed +47
-5
lines changed Expand file tree Collapse file tree 2 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -329,11 +329,13 @@ base mixin DartAnalyzerSupport
329329 if (errorResult != null ) return errorResult;
330330
331331 final uri = Uri .parse (request.arguments! [ParameterNames .uri] as String );
332- final result = await _lspConnection! .sendRequest (
333- 'dart/textDocument/summary' ,
334- lsp.TextDocumentIdentifier (uri: uri).toJson (),
335- );
336- return CallToolResult (content: [TextContent (text: jsonEncode (result))]);
332+ final result =
333+ (await _lspConnection! .sendRequest (
334+ 'dart/textDocument/summary' ,
335+ lsp.TextDocumentIdentifier (uri: uri).toJson (),
336+ ))
337+ as String ;
338+ return CallToolResult (content: [TextContent (text: result)]);
337339 }
338340
339341 /// Ensures that all prerequisites for any analysis task are met.
Original file line number Diff line number Diff line change @@ -187,6 +187,46 @@ void printIt({required int x}) {
187187 );
188188 });
189189
190+ test ('can get dart library summary information' , () async {
191+ final example = d.dir ('example' , [
192+ d.file ('main.dart' , '''
193+ int x = 1;
194+
195+ void foo() {};
196+
197+ class A {
198+ String get y => 'hello';
199+ }
200+ ''' ),
201+ ]);
202+ await example.create ();
203+ final exampleRoot = testHarness.rootForPath (example.io.path);
204+ testHarness.mcpClient.addRoot (exampleRoot);
205+ await pumpEventQueue ();
206+
207+ final result = await testHarness.callToolWithRetry (
208+ CallToolRequest (
209+ name: DartAnalyzerSupport .readSummaryTool.name,
210+ arguments: {ParameterNames .uri: p.join (exampleRoot.uri, 'main.dart' )},
211+ ),
212+ );
213+ expect (result.isError, isNot (true ));
214+
215+ expect (
216+ result.content.single,
217+ isA <TextContent >().having (
218+ (t) => t.text, // decode it to remove escapes
219+ 'text' ,
220+ equalsIgnoringWhitespace ('''
221+ int x;
222+ void foo() {}
223+ class A {
224+ String get y {}
225+ }''' ),
226+ ),
227+ );
228+ });
229+
190230 test ('cannot analyze without roots set' , () async {
191231 final result = await testHarness.callTool (
192232 CallToolRequest (name: DartAnalyzerSupport .analyzeFilesTool.name),
You can’t perform that action at this time.
0 commit comments