Skip to content

Commit 343ffd1

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Fix URI/path comparisons for Windows in the Scheduler
We can't use `uri.path` to get a file path from a `file:///` URI because on Windows it will be incorrect. Instead, we should use `toFilePath()`... however, it's possible in future we'll have non-file URIs here (macros etc.), so it's better to compare URIs directly. Fixes #59615 Change-Id: I9b4badb96edc9f7dae57b1fa399d0e4fef8bb86a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397620 Reviewed-by: Keerti Parthasarathy <[email protected]> Reviewed-by: Jaime Wren <[email protected]> Commit-Queue: Keerti Parthasarathy <[email protected]>
1 parent baef07c commit 343ffd1

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pkg/analysis_server/lib/src/lsp/handlers/commands/abstract_refactor.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ abstract class AbstractRefactorCommandHandler extends SimpleEditCommandHandler
178178
}
179179

180180
if (parameters['kind'] is! String ||
181+
// TODO(dantup): We should migrate this to URIs.
181182
parameters['path'] is! String ||
182183
(parameters['docVersion'] is! int?) ||
183184
parameters['offset'] is! int ||

pkg/analysis_server/lib/src/server/message_scheduler.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,18 +383,19 @@ final class MessageScheduler {
383383
if (params == null) {
384384
return;
385385
}
386-
var uri = params.textDocument.uri;
386+
var documentChangeUri = params.textDocument.uri;
387387

388-
String? getDocumentPath(List<lsp.LSPAny?> args) {
388+
Uri? getRefactorUri(List<lsp.LSPAny?> args) {
389389
// TODO(keertip): extract method in AbstractRefactorCommandHandler
390390
// and use that instead.
391391
String? path;
392392
if (args.length == 6) {
393393
path = args[1] as String?;
394394
} else if (args.length == 1 && args[0] is Map<String, Object?>) {
395-
path = (args.single as Map<String, Object?>).values.first as String;
395+
path = (args.single as Map<String, Object?>)['path'] as String?;
396396
}
397-
return path;
397+
398+
return path != null ? Uri.file(path) : null;
398399
}
399400

400401
void checkAndCancelRefactor(LspMessage lspMessage) {
@@ -403,8 +404,8 @@ final class MessageScheduler {
403404
if (execParams != null &&
404405
execParams.command == Commands.performRefactor) {
405406
var args = execParams.arguments ?? [];
406-
String? path = getDocumentPath(args);
407-
if (path == uri.path) {
407+
var refactorUri = getRefactorUri(args);
408+
if (refactorUri == documentChangeUri) {
408409
lspMessage.cancellationToken?.cancel(
409410
code: lsp.ErrorCodes.ContentModified.toJson(),
410411
);
@@ -419,8 +420,8 @@ final class MessageScheduler {
419420
var request = lspMessage.message as lsp.RequestMessage;
420421
var renameParams = _getRenameParams(request);
421422
if (renameParams != null) {
422-
var path = renameParams.textDocument.uri.path;
423-
if (path == uri.path) {
423+
var renameUri = renameParams.textDocument.uri;
424+
if (renameUri == documentChangeUri) {
424425
lspMessage.cancellationToken?.cancel(
425426
code: lsp.ErrorCodes.ContentModified.toJson(),
426427
);

0 commit comments

Comments
 (0)