mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 12:57:42 +00:00
[analysis_server] Restore use of pathContext.fromUri() for parsing file URIs in the LSP server
This revertsbe4189f047
plus adds an additional test to verify pkg:path to behaviour (to catch future regressions or if pkg:path has to be reverted, this will need reverting too). This relies on the fix made at https://github.com/dart-lang/path/issues/148 which rolled into the SDK inf1de897762
. Change-Id: I1dea45e2017f7505bc4aca97f6c07c1a6e445a5e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319523 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
49ec5d5e7a
commit
aee6d0af18
|
@ -396,7 +396,7 @@ mixin _CallHierarchyUtils on HandlerHelperMixin<AnalysisServer> {
|
|||
displayName: item.name,
|
||||
containerName: item.detail,
|
||||
kind: fromSymbolKind(item.kind),
|
||||
file: item.uri.toFilePath(),
|
||||
file: pathContext.fromUri(item.uri),
|
||||
nameRange: nameRange.result,
|
||||
codeRange: codeRange.result,
|
||||
);
|
||||
|
|
|
@ -43,6 +43,6 @@ class WorkspaceFoldersHandler
|
|||
/// Return the result of converting the list of workspace [folders] to file
|
||||
/// paths.
|
||||
List<String> _convertWorkspaceFolders(List<WorkspaceFolder> folders) {
|
||||
return folders.map((wf) => wf.uri.toFilePath()).toList();
|
||||
return folders.map((wf) => pathContext.fromUri(wf.uri)).toList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ class CompletionResolveHandler
|
|||
// Compute the relative path and then put into a URI so the display
|
||||
// always uses forward slashes (as a URI) regardless of platform.
|
||||
? pathContext.toUri(pathContext.relative(
|
||||
libraryUri.toFilePath(),
|
||||
pathContext.fromUri(libraryUri),
|
||||
from: pathContext.dirname(file),
|
||||
))
|
||||
: libraryUri;
|
||||
|
|
|
@ -44,13 +44,13 @@ class InitializeMessageHandler
|
|||
// Only file URIs are supported, but there's no way to signal this to
|
||||
// the LSP client (and certainly not before initialization).
|
||||
if (uri.isScheme('file')) {
|
||||
workspacePaths.add(uri.toFilePath());
|
||||
workspacePaths.add(pathContext.fromUri(uri));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rootUri != null) {
|
||||
if (rootUri.isScheme('file')) {
|
||||
workspacePaths.add(rootUri.toFilePath());
|
||||
workspacePaths.add(pathContext.fromUri(rootUri));
|
||||
}
|
||||
} else if (rootPath != null) {
|
||||
workspacePaths.add(rootPath);
|
||||
|
|
|
@ -68,11 +68,12 @@ class MoveTopLevelToFile extends RefactoringProducer {
|
|||
return;
|
||||
}
|
||||
_initializeFromMembers(members);
|
||||
var pathContext = refactoringContext.server.resourceProvider.pathContext;
|
||||
var sourcePath = members.containingFile;
|
||||
// TODO(dantup): Add refactor-specific validation for incoming arguments.
|
||||
// Argument is a String URI.
|
||||
var destinationUri = Uri.parse(commandArguments[0] as String);
|
||||
var destinationFilePath = destinationUri.toFilePath();
|
||||
var destinationFilePath = pathContext.fromUri(destinationUri);
|
||||
|
||||
var destinationImportUri =
|
||||
unitResult.session.uriConverter.pathToUri(destinationFilePath);
|
||||
|
|
|
@ -183,7 +183,7 @@ abstract class AbstractLspAnalysisServerTest
|
|||
String? getCurrentFileContent(Uri uri) {
|
||||
try {
|
||||
return server.resourceProvider
|
||||
.getFile(uri.toFilePath())
|
||||
.getFile(pathContext.fromUri(uri))
|
||||
.readAsStringSync();
|
||||
} catch (_) {
|
||||
return null;
|
||||
|
@ -1367,7 +1367,8 @@ mixin LspAnalysisServerTestMixin on LspRequestHelpersMixin
|
|||
return configurationParams.items.map(
|
||||
(requestedConfig) {
|
||||
final uri = requestedConfig.scopeUri;
|
||||
final path = uri != null ? Uri.parse(uri).toFilePath() : null;
|
||||
final path =
|
||||
uri != null ? pathContext.fromUri(Uri.parse(uri)) : null;
|
||||
// Use the config the test provided for this path, or fall back to
|
||||
// global.
|
||||
return (folders != null ? folders[path] : null) ?? global;
|
||||
|
@ -1472,7 +1473,7 @@ mixin LspAnalysisServerTestMixin on LspRequestHelpersMixin
|
|||
/// Formats a path relative to the project root always using forward slashes.
|
||||
///
|
||||
/// This is used in the text format for comparing edits.
|
||||
String relativeUri(Uri uri) => relativePath(uri.toFilePath());
|
||||
String relativeUri(Uri uri) => relativePath(pathContext.fromUri(uri));
|
||||
|
||||
Future<WorkspaceEdit?> rename(
|
||||
Uri uri,
|
||||
|
@ -1574,7 +1575,8 @@ mixin LspAnalysisServerTestMixin on LspRequestHelpersMixin
|
|||
.map((notification) => PublishDiagnosticsParams.fromJson(
|
||||
notification.params as Map<String, Object?>))
|
||||
.listen((diagnostics) {
|
||||
latestDiagnostics[diagnostics.uri.toFilePath()] = diagnostics.diagnostics;
|
||||
latestDiagnostics[pathContext.fromUri(diagnostics.uri)] =
|
||||
diagnostics.diagnostics;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -236,6 +236,14 @@ class ServerTest extends AbstractLspAnalysisServerTest {
|
|||
);
|
||||
}
|
||||
|
||||
/// The LSP server relies on pathContext.fromUri() handling encoded colons
|
||||
/// in paths, so verify that works as expected.
|
||||
Future<void> test_pathContext_fromUri_windows() async {
|
||||
expect(path.windows.fromUri('file:///C:/foo'), r'C:\foo');
|
||||
expect(path.windows.fromUri('file:///C%3a/foo'), r'C:\foo');
|
||||
expect(path.windows.fromUri('file:///C%3A/foo'), r'C:\foo');
|
||||
}
|
||||
|
||||
Future<void> test_shutdown_initialized() async {
|
||||
await initialize();
|
||||
final response = await sendShutdown();
|
||||
|
|
Loading…
Reference in a new issue