From 03e415a4e884bb2bd18e366edfbbcbc86f4bf17e Mon Sep 17 00:00:00 2001 From: Jaime Wren Date: Fri, 24 May 2019 21:54:56 +0000 Subject: [PATCH] Update the hover 'containingLibraryName' to not include the 'file:///' prefix. This is a follow up on a comment in the previous change https://dart-review.googlesource.com/c/sdk/+/103481/. Change-Id: I0f377d6c7d68d55464a4e111a6a65715a82e0591 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103546 Reviewed-by: Jaime Wren Reviewed-by: Brian Wilkerson Commit-Queue: Jaime Wren --- pkg/analysis_server/doc/api.html | 5 ++-- .../lib/protocol/protocol_generated.dart | 8 +++---- .../lib/src/computer/computer_hover.dart | 11 ++++++++- .../test/analysis/get_hover_test.dart | 23 ++++++++++--------- pkg/analysis_server/test/lsp/hover_test.dart | 11 +++++++-- .../java/types/HoverInformation.java | 10 ++++---- pkg/analysis_server/tool/spec/spec_input.html | 5 ++-- .../lib/src/protocol/protocol_generated.dart | 8 +++---- 8 files changed, 51 insertions(+), 30 deletions(-) diff --git a/pkg/analysis_server/doc/api.html b/pkg/analysis_server/doc/api.html index c10faf77d57..b39b09053b3 100644 --- a/pkg/analysis_server/doc/api.html +++ b/pkg/analysis_server/doc/api.html @@ -3923,8 +3923,9 @@ a:focus, a:hover {

The URI of the containing library, examples here include - "dart:core", "package:.." and even "file:.." URIs. The data - is omitted if the element is declared inside an HTML file. + "dart:core", "package:.." and file uris represented by the + path on disk, "/..". The data is omitted if the element is + declared inside an HTML file.

containingClassDescription: String (optional)
diff --git a/pkg/analysis_server/lib/protocol/protocol_generated.dart b/pkg/analysis_server/lib/protocol/protocol_generated.dart index bc2c256cf66..8973481746c 100644 --- a/pkg/analysis_server/lib/protocol/protocol_generated.dart +++ b/pkg/analysis_server/lib/protocol/protocol_generated.dart @@ -15941,15 +15941,15 @@ class HoverInformation implements HasToJson { /** * The URI of the containing library, examples here include "dart:core", - * "package:.." and even "file:.." URIs. The data is omitted if the element - * is declared inside an HTML file. + * "package:.." and file uris represented by the path on disk, "/..". The + * data is omitted if the element is declared inside an HTML file. */ String get containingLibraryName => _containingLibraryName; /** * The URI of the containing library, examples here include "dart:core", - * "package:.." and even "file:.." URIs. The data is omitted if the element - * is declared inside an HTML file. + * "package:.." and file uris represented by the path on disk, "/..". The + * data is omitted if the element is declared inside an HTML file. */ void set containingLibraryName(String value) { this._containingLibraryName = value; diff --git a/pkg/analysis_server/lib/src/computer/computer_hover.dart b/pkg/analysis_server/lib/src/computer/computer_hover.dart index b5f3e7ad53a..c3a3fbaf384 100644 --- a/pkg/analysis_server/lib/src/computer/computer_hover.dart +++ b/pkg/analysis_server/lib/src/computer/computer_hover.dart @@ -8,6 +8,7 @@ import 'package:analysis_server/src/computer/computer_overrides.dart'; import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:analyzer/file_system/file_system.dart'; import 'package:analyzer/src/dart/ast/element_locator.dart'; import 'package:analyzer/src/dart/ast/utilities.dart'; import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart'; @@ -72,7 +73,15 @@ class DartUnitHoverComputer { // containing library LibraryElement library = element.library; if (library != null) { - hover.containingLibraryName = library.source.uri.toString(); + Uri uri = library.source.uri; + if (uri.scheme != '' && uri.scheme == 'file') { + // for 'file:' URIs, use the path (contents after 'file:///') + hover.containingLibraryName = _unit + .declaredElement.session.resourceProvider.pathContext + .fromUri(uri); + } else { + hover.containingLibraryName = uri.toString(); + } hover.containingLibraryPath = library.source.fullName; } } diff --git a/pkg/analysis_server/test/analysis/get_hover_test.dart b/pkg/analysis_server/test/analysis/get_hover_test.dart index ae1938fd401..99262919dc5 100644 --- a/pkg/analysis_server/test/analysis/get_hover_test.dart +++ b/pkg/analysis_server/test/analysis/get_hover_test.dart @@ -7,6 +7,7 @@ import 'dart:io'; import 'package:analysis_server/protocol/protocol.dart'; import 'package:analysis_server/protocol/protocol_generated.dart'; +import 'package:path/path.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -21,8 +22,8 @@ main() { @reflectiveTest class AnalysisHoverTest extends AbstractAnalysisTest { - /// If windows, return 'C:/', otherwise return the empty string - String get windowsCColon => Platform.isWindows ? 'C:/' : ''; + /// If windows, return 'C:', otherwise return the empty string + String get windowsCColon => Platform.isWindows ? 'C:' : ''; Future prepareHover(String search) { int offset = findOffset(search); @@ -121,7 +122,7 @@ main() { expect(hover.length, 'A(0)'.length); // element expect(hover.containingLibraryName, - 'file:///${windowsCColon}project/bin/test.dart'); + normalize('$windowsCColon/project/bin/test.dart')); expect(hover.containingLibraryPath, testFile); expect(hover.dartdoc, isNull); expect(hover.elementDescription, '(const) A(int i) → A'); @@ -147,7 +148,7 @@ main() { expect(hover.length, 'A()'.length); // element expect(hover.containingLibraryName, - 'file:///${windowsCColon}project/bin/test.dart'); + normalize('$windowsCColon/project/bin/test.dart')); expect(hover.containingLibraryPath, testFile); expect(hover.dartdoc, isNull); expect(hover.elementDescription, '(new) A() → A'); @@ -174,7 +175,7 @@ main() { expect(hover.length, 'new A()'.length); // element expect(hover.containingLibraryName, - 'file:///${windowsCColon}project/bin/test.dart'); + normalize('$windowsCColon/project/bin/test.dart')); expect(hover.containingLibraryPath, testFile); expect(hover.dartdoc, isNull); expect(hover.elementDescription, 'A() → A'); @@ -200,7 +201,7 @@ main() { expect(hover.length, 'new A()'.length); // element expect(hover.containingLibraryName, - 'file:///${windowsCColon}project/bin/test.dart'); + normalize('$windowsCColon/project/bin/test.dart')); expect(hover.containingLibraryPath, testFile); expect(hover.dartdoc, isNull); expect(hover.elementDescription, 'A() → A'); @@ -339,7 +340,7 @@ List fff(int a, String b) { HoverInformation hover = await prepareHover('fff(int a'); // element expect(hover.containingLibraryName, - 'file:///${windowsCColon}project/bin/test.dart'); + normalize('$windowsCColon/project/bin/test.dart')); expect(hover.containingLibraryPath, testFile); expect(hover.containingClassDescription, isNull); expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); @@ -367,7 +368,7 @@ main(A a) { HoverInformation hover = await prepareHover('fff);'); // element expect(hover.containingLibraryName, - 'file:///${windowsCColon}project/bin/test.dart'); + normalize('$windowsCColon/project/bin/test.dart')); expect(hover.containingLibraryPath, testFile); expect(hover.containingClassDescription, 'A'); expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); @@ -506,7 +507,7 @@ class A { HoverInformation hover = await prepareHover('mmm(int a'); // element expect(hover.containingLibraryName, - 'file:///${windowsCColon}project/bin/test.dart'); + normalize('$windowsCColon/project/bin/test.dart')); expect(hover.containingLibraryPath, testFile); expect(hover.containingClassDescription, 'A'); expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); @@ -536,7 +537,7 @@ main(A a) { expect(hover.length, 'mmm'.length); // element expect(hover.containingLibraryName, - 'file:///${windowsCColon}project/bin/test.dart'); + normalize('$windowsCColon/project/bin/test.dart')); expect(hover.containingLibraryPath, testFile); expect(hover.elementDescription, 'mmm(int a, String b) → List'); expect(hover.elementKind, 'method'); @@ -585,7 +586,7 @@ f(Stream s) { expect(hover.length, 'transform'.length); // element expect(hover.containingLibraryName, - 'file:///${windowsCColon}project/bin/test.dart'); + normalize('$windowsCColon/project/bin/test.dart')); expect(hover.containingLibraryPath, testFile); expect(hover.elementDescription, 'Stream.transform(StreamTransformer streamTransformer) → Stream'); diff --git a/pkg/analysis_server/test/lsp/hover_test.dart b/pkg/analysis_server/test/lsp/hover_test.dart index 46e1a70a97c..7f06e690001 100644 --- a/pkg/analysis_server/test/lsp/hover_test.dart +++ b/pkg/analysis_server/test/lsp/hover_test.dart @@ -6,6 +6,7 @@ import 'dart:io'; import 'package:analysis_server/lsp_protocol/protocol_generated.dart'; import 'package:analysis_server/src/lsp/constants.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -68,11 +69,14 @@ class HoverTest extends AbstractLspAnalysisServerTest { String [[a^bc]]; '''; + final containingLibraryName = + path.normalize("$windowsCColon/project/lib/main.dart"); + final expectedHoverContent = ''' ```dart String abc ``` -*file:///${windowsCColon}project/lib/main.dart* +*$containingLibraryName* --- This is a string. @@ -168,11 +172,14 @@ print(); String [[a^bc]]; '''; + final containingLibraryName = + path.normalize("$windowsCColon/project/lib/main.dart"); + final expectedHoverContent = ''' ```dart String abc ``` -*file:///${windowsCColon}project/lib/main.dart* +*$containingLibraryName* ''' .trim(); diff --git a/pkg/analysis_server/tool/spec/generated/java/types/HoverInformation.java b/pkg/analysis_server/tool/spec/generated/java/types/HoverInformation.java index 36b21ae79f3..88e6f0b6aa5 100644 --- a/pkg/analysis_server/tool/spec/generated/java/types/HoverInformation.java +++ b/pkg/analysis_server/tool/spec/generated/java/types/HoverInformation.java @@ -55,8 +55,9 @@ public class HoverInformation { private final String containingLibraryPath; /** - * The URI of the containing library, examples here include "dart:core", "package:.." and even - * "file:.." URIs. The data is omitted if the element is declared inside an HTML file. + * The URI of the containing library, examples here include "dart:core", "package:.." and file uris + * represented by the path on disk, "/..". The data is omitted if the element is declared inside an + * HTML file. */ private final String containingLibraryName; @@ -185,8 +186,9 @@ public class HoverInformation { } /** - * The URI of the containing library, examples here include "dart:core", "package:.." and even - * "file:.." URIs. The data is omitted if the element is declared inside an HTML file. + * The URI of the containing library, examples here include "dart:core", "package:.." and file uris + * represented by the path on disk, "/..". The data is omitted if the element is declared inside an + * HTML file. */ public String getContainingLibraryName() { return containingLibraryName; diff --git a/pkg/analysis_server/tool/spec/spec_input.html b/pkg/analysis_server/tool/spec/spec_input.html index 2edfc64e8a6..237ae9b50f7 100644 --- a/pkg/analysis_server/tool/spec/spec_input.html +++ b/pkg/analysis_server/tool/spec/spec_input.html @@ -4325,8 +4325,9 @@ String

The URI of the containing library, examples here include - "dart:core", "package:.." and even "file:.." URIs. The data - is omitted if the element is declared inside an HTML file. + "dart:core", "package:.." and file uris represented by the + path on disk, "/..". The data is omitted if the element is + declared inside an HTML file.

diff --git a/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart b/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart index ec76e663608..bed4e0bf799 100644 --- a/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart +++ b/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart @@ -15941,15 +15941,15 @@ class HoverInformation implements HasToJson { /** * The URI of the containing library, examples here include "dart:core", - * "package:.." and even "file:.." URIs. The data is omitted if the element - * is declared inside an HTML file. + * "package:.." and file uris represented by the path on disk, "/..". The + * data is omitted if the element is declared inside an HTML file. */ String get containingLibraryName => _containingLibraryName; /** * The URI of the containing library, examples here include "dart:core", - * "package:.." and even "file:.." URIs. The data is omitted if the element - * is declared inside an HTML file. + * "package:.." and file uris represented by the path on disk, "/..". The + * data is omitted if the element is declared inside an HTML file. */ void set containingLibraryName(String value) { this._containingLibraryName = value;