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 <jwren@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jaime Wren <jwren@google.com>
This commit is contained in:
Jaime Wren
2019-05-24 21:54:56 +00:00
committed by commit-bot@chromium.org
parent 4979a51a9c
commit 03e415a4e8
8 changed files with 51 additions and 30 deletions
+3 -2
View File
@@ -3923,8 +3923,9 @@ a:focus, a:hover {
<p>
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.
</p>
</dd><dt class="field"><b>containingClassDescription: String<span style="color:#999999"> (optional)</span></b></dt><dd>
@@ -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;
@@ -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;
}
}
@@ -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<HoverInformation> 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<String>()'.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<String>');
@@ -339,7 +340,7 @@ List<String> 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<String>');
expect(hover.elementKind, 'method');
@@ -585,7 +586,7 @@ f(Stream<int> 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<S>(StreamTransformer<int, S> streamTransformer) → Stream<S>');
+9 -2
View File
@@ -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();
@@ -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;
@@ -4325,8 +4325,9 @@
<ref>String</ref>
<p>
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.
</p>
</field>
<field name="containingClassDescription" optional="true">
@@ -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;