Skip to content

Commit ec831cf

Browse files
jensjohaCommit Queue
authored andcommitted
[analyzer] createPlainWorkspaceEdit can use passes line info
``` out/ReleaseX64/dart-sdk/bin/dart \ pkg/analysis_server/tool/benchmark_tools/single_benchmarks/lsp_many_prefer_single_quotes_violations_benchmark.dart \ --sizes=3200 ``` goes from ``` Select all code action call: 10.684823 ``` to ``` Select all code action call: 8.838016 ``` Change-Id: Icbc08aaa8f6f4ac677afea6072d5af3590bd378c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426120 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent d6ef495 commit ec831cf

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

pkg/analysis_server/lib/src/lsp/mapping.dart

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,36 @@ lsp.WorkspaceEdit createPlainWorkspaceEdit(
172172
LspClientCapabilities clientCapabilities,
173173
List<server.SourceFileEdit> edits, {
174174
ChangeAnnotations annotateChanges = ChangeAnnotations.none,
175+
String? filePath,
176+
LineInfo? lineInfo,
175177
}) {
176178
return toWorkspaceEdit(
177179
annotateChanges: annotateChanges,
178180
clientCapabilities,
179-
edits
180-
.map(
181-
(e) => FileEditInformation(
182-
analysisServer.getVersionedDocumentIdentifier(e.file),
183-
// If we expect to create the file, `server.getLineInfo()` won't
184-
// provide a LineInfo so create one from empty contents.
185-
e.fileStamp == -1
186-
? LineInfo.fromContent('')
187-
: analysisServer.getLineInfo(e.file)!,
188-
e.edits,
189-
// `fileStamp == 1` is used by the server to indicate the file needs
190-
// creating.
191-
newFile: e.fileStamp == -1,
192-
),
193-
)
194-
.toList(),
181+
edits.map((e) {
182+
// If we don't expet to create the file use the passed line info if any
183+
// and it matches the given file.
184+
// If we expect to create the file, `server.getLineInfo()` won't
185+
// provide a LineInfo so create one from empty contents.
186+
LineInfo pickedLineInfo;
187+
if (e.fileStamp == -1) {
188+
pickedLineInfo = LineInfo.fromContent('');
189+
} else {
190+
if (filePath != null && lineInfo != null && filePath == e.file) {
191+
pickedLineInfo = lineInfo;
192+
} else {
193+
pickedLineInfo = analysisServer.getLineInfo(e.file)!;
194+
}
195+
}
196+
return FileEditInformation(
197+
analysisServer.getVersionedDocumentIdentifier(e.file),
198+
pickedLineInfo,
199+
e.edits,
200+
// `fileStamp == 1` is used by the server to indicate the file needs
201+
// creating.
202+
newFile: e.fileStamp == -1,
203+
);
204+
}).toList(),
195205
);
196206
}
197207

@@ -263,6 +273,8 @@ lsp.WorkspaceEdit createWorkspaceEdit(
263273
clientCapabilities,
264274
change.edits,
265275
annotateChanges: annotateChanges,
276+
filePath: filePath,
277+
lineInfo: lineInfo,
266278
);
267279
}
268280

0 commit comments

Comments
 (0)