Skip to content

Commit a9feb25

Browse files
srawlinsCommit Queue
authored andcommitted
DAS plugins: Make the fix offset a range over the diagnostic
Fixes #61491 Change-Id: I2616006b7ac1ba645e4bed3caeb0781f04864feb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449362 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 131ee3e commit a9feb25

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

pkg/analysis_server_plugin/lib/src/plugin_server.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,13 @@ class PluginServer {
195195
return protocol.EditGetFixesResult(const []);
196196
}
197197

198-
var lintAtOffset = errors.where(
199-
(error) => error.diagnostic.offset == offset,
200-
);
198+
var lineInfo = unitResult.lineInfo;
199+
var requestLine = lineInfo.getLocation(offset).lineNumber;
200+
201+
var lintAtOffset = errors.where((error) {
202+
var errorLine = lineInfo.getLocation(error.diagnostic.offset).lineNumber;
203+
return errorLine == requestLine;
204+
});
201205
if (lintAtOffset.isEmpty) return protocol.EditGetFixesResult(const []);
202206

203207
var errorFixesList = <protocol.AnalysisErrorFixes>[];

pkg/analysis_server_plugin/test/src/plugin_server_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ bool b = false;
149149
expect(fixes.fixes, hasLength(4));
150150
}
151151

152+
Future<void> test_handleEditGetFixes_afterLine() async {
153+
writeAnalysisOptionsWithPlugin();
154+
newFile(filePath, 'bool b = false;\n\n');
155+
await channel.sendRequest(
156+
protocol.AnalysisSetContextRootsParams([contextRoot]),
157+
);
158+
159+
var result = await pluginServer.handleEditGetFixes(
160+
protocol.EditGetFixesParams(filePath, 'bool b = false;\n'.length),
161+
);
162+
expect(result.fixes, isEmpty);
163+
}
164+
165+
Future<void> test_handleEditGetFixes_onSameLine() async {
166+
writeAnalysisOptionsWithPlugin();
167+
newFile(filePath, 'bool b = false;');
168+
await channel.sendRequest(
169+
protocol.AnalysisSetContextRootsParams([contextRoot]),
170+
);
171+
172+
var result = await pluginServer.handleEditGetFixes(
173+
protocol.EditGetFixesParams(filePath, 'bool b = fa'.length),
174+
);
175+
var fixes = result.fixes.single;
176+
// The WrapInQuotes fix plus three "ignore diagnostic" fixes.
177+
expect(fixes.fixes, hasLength(4));
178+
}
179+
152180
Future<void> test_handleEditGetFixes_viaSendRequest() async {
153181
writeAnalysisOptionsWithPlugin();
154182
newFile(filePath, 'bool b = false;');

0 commit comments

Comments
 (0)