mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +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,
|
displayName: item.name,
|
||||||
containerName: item.detail,
|
containerName: item.detail,
|
||||||
kind: fromSymbolKind(item.kind),
|
kind: fromSymbolKind(item.kind),
|
||||||
file: item.uri.toFilePath(),
|
file: pathContext.fromUri(item.uri),
|
||||||
nameRange: nameRange.result,
|
nameRange: nameRange.result,
|
||||||
codeRange: codeRange.result,
|
codeRange: codeRange.result,
|
||||||
);
|
);
|
||||||
|
|
|
@ -43,6 +43,6 @@ class WorkspaceFoldersHandler
|
||||||
/// Return the result of converting the list of workspace [folders] to file
|
/// Return the result of converting the list of workspace [folders] to file
|
||||||
/// paths.
|
/// paths.
|
||||||
List<String> _convertWorkspaceFolders(List<WorkspaceFolder> folders) {
|
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
|
// Compute the relative path and then put into a URI so the display
|
||||||
// always uses forward slashes (as a URI) regardless of platform.
|
// always uses forward slashes (as a URI) regardless of platform.
|
||||||
? pathContext.toUri(pathContext.relative(
|
? pathContext.toUri(pathContext.relative(
|
||||||
libraryUri.toFilePath(),
|
pathContext.fromUri(libraryUri),
|
||||||
from: pathContext.dirname(file),
|
from: pathContext.dirname(file),
|
||||||
))
|
))
|
||||||
: libraryUri;
|
: libraryUri;
|
||||||
|
|
|
@ -44,13 +44,13 @@ class InitializeMessageHandler
|
||||||
// Only file URIs are supported, but there's no way to signal this to
|
// Only file URIs are supported, but there's no way to signal this to
|
||||||
// the LSP client (and certainly not before initialization).
|
// the LSP client (and certainly not before initialization).
|
||||||
if (uri.isScheme('file')) {
|
if (uri.isScheme('file')) {
|
||||||
workspacePaths.add(uri.toFilePath());
|
workspacePaths.add(pathContext.fromUri(uri));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rootUri != null) {
|
if (rootUri != null) {
|
||||||
if (rootUri.isScheme('file')) {
|
if (rootUri.isScheme('file')) {
|
||||||
workspacePaths.add(rootUri.toFilePath());
|
workspacePaths.add(pathContext.fromUri(rootUri));
|
||||||
}
|
}
|
||||||
} else if (rootPath != null) {
|
} else if (rootPath != null) {
|
||||||
workspacePaths.add(rootPath);
|
workspacePaths.add(rootPath);
|
||||||
|
|
|
@ -68,11 +68,12 @@ class MoveTopLevelToFile extends RefactoringProducer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_initializeFromMembers(members);
|
_initializeFromMembers(members);
|
||||||
|
var pathContext = refactoringContext.server.resourceProvider.pathContext;
|
||||||
var sourcePath = members.containingFile;
|
var sourcePath = members.containingFile;
|
||||||
// TODO(dantup): Add refactor-specific validation for incoming arguments.
|
// TODO(dantup): Add refactor-specific validation for incoming arguments.
|
||||||
// Argument is a String URI.
|
// Argument is a String URI.
|
||||||
var destinationUri = Uri.parse(commandArguments[0] as String);
|
var destinationUri = Uri.parse(commandArguments[0] as String);
|
||||||
var destinationFilePath = destinationUri.toFilePath();
|
var destinationFilePath = pathContext.fromUri(destinationUri);
|
||||||
|
|
||||||
var destinationImportUri =
|
var destinationImportUri =
|
||||||
unitResult.session.uriConverter.pathToUri(destinationFilePath);
|
unitResult.session.uriConverter.pathToUri(destinationFilePath);
|
||||||
|
|
|
@ -183,7 +183,7 @@ abstract class AbstractLspAnalysisServerTest
|
||||||
String? getCurrentFileContent(Uri uri) {
|
String? getCurrentFileContent(Uri uri) {
|
||||||
try {
|
try {
|
||||||
return server.resourceProvider
|
return server.resourceProvider
|
||||||
.getFile(uri.toFilePath())
|
.getFile(pathContext.fromUri(uri))
|
||||||
.readAsStringSync();
|
.readAsStringSync();
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -1367,7 +1367,8 @@ mixin LspAnalysisServerTestMixin on LspRequestHelpersMixin
|
||||||
return configurationParams.items.map(
|
return configurationParams.items.map(
|
||||||
(requestedConfig) {
|
(requestedConfig) {
|
||||||
final uri = requestedConfig.scopeUri;
|
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
|
// Use the config the test provided for this path, or fall back to
|
||||||
// global.
|
// global.
|
||||||
return (folders != null ? folders[path] : null) ?? 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.
|
/// Formats a path relative to the project root always using forward slashes.
|
||||||
///
|
///
|
||||||
/// This is used in the text format for comparing edits.
|
/// 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(
|
Future<WorkspaceEdit?> rename(
|
||||||
Uri uri,
|
Uri uri,
|
||||||
|
@ -1574,7 +1575,8 @@ mixin LspAnalysisServerTestMixin on LspRequestHelpersMixin
|
||||||
.map((notification) => PublishDiagnosticsParams.fromJson(
|
.map((notification) => PublishDiagnosticsParams.fromJson(
|
||||||
notification.params as Map<String, Object?>))
|
notification.params as Map<String, Object?>))
|
||||||
.listen((diagnostics) {
|
.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 {
|
Future<void> test_shutdown_initialized() async {
|
||||||
await initialize();
|
await initialize();
|
||||||
final response = await sendShutdown();
|
final response = await sendShutdown();
|
||||||
|
|
Loading…
Reference in a new issue