Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 03e415a

Browse files
jwrencommit-bot@chromium.org
authored andcommitted
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 <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Jaime Wren <[email protected]>
1 parent 4979a51 commit 03e415a

File tree

8 files changed

+51
-30
lines changed

8 files changed

+51
-30
lines changed

pkg/analysis_server/doc/api.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,8 +3923,9 @@ <h2 class="domain"><a name="types">Types</a></h2>
39233923

39243924
<p>
39253925
The URI of the containing library, examples here include
3926-
"dart:core", "package:.." and even "file:.." URIs. The data
3927-
is omitted if the element is declared inside an HTML file.
3926+
"dart:core", "package:.." and file uris represented by the
3927+
path on disk, "/..". The data is omitted if the element is
3928+
declared inside an HTML file.
39283929
</p>
39293930
</dd><dt class="field"><b>containingClassDescription: String<span style="color:#999999"> (optional)</span></b></dt><dd>
39303931

pkg/analysis_server/lib/protocol/protocol_generated.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15941,15 +15941,15 @@ class HoverInformation implements HasToJson {
1594115941

1594215942
/**
1594315943
* The URI of the containing library, examples here include "dart:core",
15944-
* "package:.." and even "file:.." URIs. The data is omitted if the element
15945-
* is declared inside an HTML file.
15944+
* "package:.." and file uris represented by the path on disk, "/..". The
15945+
* data is omitted if the element is declared inside an HTML file.
1594615946
*/
1594715947
String get containingLibraryName => _containingLibraryName;
1594815948

1594915949
/**
1595015950
* The URI of the containing library, examples here include "dart:core",
15951-
* "package:.." and even "file:.." URIs. The data is omitted if the element
15952-
* is declared inside an HTML file.
15951+
* "package:.." and file uris represented by the path on disk, "/..". The
15952+
* data is omitted if the element is declared inside an HTML file.
1595315953
*/
1595415954
void set containingLibraryName(String value) {
1595515955
this._containingLibraryName = value;

pkg/analysis_server/lib/src/computer/computer_hover.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:analysis_server/src/computer/computer_overrides.dart';
88
import 'package:analyzer/dart/ast/ast.dart';
99
import 'package:analyzer/dart/element/element.dart';
1010
import 'package:analyzer/dart/element/type.dart';
11+
import 'package:analyzer/file_system/file_system.dart';
1112
import 'package:analyzer/src/dart/ast/element_locator.dart';
1213
import 'package:analyzer/src/dart/ast/utilities.dart';
1314
import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart';
@@ -72,7 +73,15 @@ class DartUnitHoverComputer {
7273
// containing library
7374
LibraryElement library = element.library;
7475
if (library != null) {
75-
hover.containingLibraryName = library.source.uri.toString();
76+
Uri uri = library.source.uri;
77+
if (uri.scheme != '' && uri.scheme == 'file') {
78+
// for 'file:' URIs, use the path (contents after 'file:///')
79+
hover.containingLibraryName = _unit
80+
.declaredElement.session.resourceProvider.pathContext
81+
.fromUri(uri);
82+
} else {
83+
hover.containingLibraryName = uri.toString();
84+
}
7685
hover.containingLibraryPath = library.source.fullName;
7786
}
7887
}

pkg/analysis_server/test/analysis/get_hover_test.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:io';
77

88
import 'package:analysis_server/protocol/protocol.dart';
99
import 'package:analysis_server/protocol/protocol_generated.dart';
10+
import 'package:path/path.dart';
1011
import 'package:test/test.dart';
1112
import 'package:test_reflective_loader/test_reflective_loader.dart';
1213

@@ -21,8 +22,8 @@ main() {
2122

2223
@reflectiveTest
2324
class AnalysisHoverTest extends AbstractAnalysisTest {
24-
/// If windows, return 'C:/', otherwise return the empty string
25-
String get windowsCColon => Platform.isWindows ? 'C:/' : '';
25+
/// If windows, return 'C:', otherwise return the empty string
26+
String get windowsCColon => Platform.isWindows ? 'C:' : '';
2627

2728
Future<HoverInformation> prepareHover(String search) {
2829
int offset = findOffset(search);
@@ -121,7 +122,7 @@ main() {
121122
expect(hover.length, 'A(0)'.length);
122123
// element
123124
expect(hover.containingLibraryName,
124-
'file:///${windowsCColon}project/bin/test.dart');
125+
normalize('$windowsCColon/project/bin/test.dart'));
125126
expect(hover.containingLibraryPath, testFile);
126127
expect(hover.dartdoc, isNull);
127128
expect(hover.elementDescription, '(const) A(int i) → A');
@@ -147,7 +148,7 @@ main() {
147148
expect(hover.length, 'A()'.length);
148149
// element
149150
expect(hover.containingLibraryName,
150-
'file:///${windowsCColon}project/bin/test.dart');
151+
normalize('$windowsCColon/project/bin/test.dart'));
151152
expect(hover.containingLibraryPath, testFile);
152153
expect(hover.dartdoc, isNull);
153154
expect(hover.elementDescription, '(new) A() → A');
@@ -174,7 +175,7 @@ main() {
174175
expect(hover.length, 'new A()'.length);
175176
// element
176177
expect(hover.containingLibraryName,
177-
'file:///${windowsCColon}project/bin/test.dart');
178+
normalize('$windowsCColon/project/bin/test.dart'));
178179
expect(hover.containingLibraryPath, testFile);
179180
expect(hover.dartdoc, isNull);
180181
expect(hover.elementDescription, 'A() → A');
@@ -200,7 +201,7 @@ main() {
200201
expect(hover.length, 'new A<String>()'.length);
201202
// element
202203
expect(hover.containingLibraryName,
203-
'file:///${windowsCColon}project/bin/test.dart');
204+
normalize('$windowsCColon/project/bin/test.dart'));
204205
expect(hover.containingLibraryPath, testFile);
205206
expect(hover.dartdoc, isNull);
206207
expect(hover.elementDescription, 'A() → A<String>');
@@ -339,7 +340,7 @@ List<String> fff(int a, String b) {
339340
HoverInformation hover = await prepareHover('fff(int a');
340341
// element
341342
expect(hover.containingLibraryName,
342-
'file:///${windowsCColon}project/bin/test.dart');
343+
normalize('$windowsCColon/project/bin/test.dart'));
343344
expect(hover.containingLibraryPath, testFile);
344345
expect(hover.containingClassDescription, isNull);
345346
expect(hover.dartdoc, '''doc aaa\ndoc bbb''');
@@ -367,7 +368,7 @@ main(A a) {
367368
HoverInformation hover = await prepareHover('fff);');
368369
// element
369370
expect(hover.containingLibraryName,
370-
'file:///${windowsCColon}project/bin/test.dart');
371+
normalize('$windowsCColon/project/bin/test.dart'));
371372
expect(hover.containingLibraryPath, testFile);
372373
expect(hover.containingClassDescription, 'A');
373374
expect(hover.dartdoc, '''doc aaa\ndoc bbb''');
@@ -506,7 +507,7 @@ class A {
506507
HoverInformation hover = await prepareHover('mmm(int a');
507508
// element
508509
expect(hover.containingLibraryName,
509-
'file:///${windowsCColon}project/bin/test.dart');
510+
normalize('$windowsCColon/project/bin/test.dart'));
510511
expect(hover.containingLibraryPath, testFile);
511512
expect(hover.containingClassDescription, 'A');
512513
expect(hover.dartdoc, '''doc aaa\ndoc bbb''');
@@ -536,7 +537,7 @@ main(A a) {
536537
expect(hover.length, 'mmm'.length);
537538
// element
538539
expect(hover.containingLibraryName,
539-
'file:///${windowsCColon}project/bin/test.dart');
540+
normalize('$windowsCColon/project/bin/test.dart'));
540541
expect(hover.containingLibraryPath, testFile);
541542
expect(hover.elementDescription, 'mmm(int a, String b) → List<String>');
542543
expect(hover.elementKind, 'method');
@@ -585,7 +586,7 @@ f(Stream<int> s) {
585586
expect(hover.length, 'transform'.length);
586587
// element
587588
expect(hover.containingLibraryName,
588-
'file:///${windowsCColon}project/bin/test.dart');
589+
normalize('$windowsCColon/project/bin/test.dart'));
589590
expect(hover.containingLibraryPath, testFile);
590591
expect(hover.elementDescription,
591592
'Stream.transform<S>(StreamTransformer<int, S> streamTransformer) → Stream<S>');

pkg/analysis_server/test/lsp/hover_test.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:io';
66

77
import 'package:analysis_server/lsp_protocol/protocol_generated.dart';
88
import 'package:analysis_server/src/lsp/constants.dart';
9+
import 'package:path/path.dart' as path;
910
import 'package:test/test.dart';
1011
import 'package:test_reflective_loader/test_reflective_loader.dart';
1112

@@ -68,11 +69,14 @@ class HoverTest extends AbstractLspAnalysisServerTest {
6869
String [[a^bc]];
6970
''';
7071

72+
final containingLibraryName =
73+
path.normalize("$windowsCColon/project/lib/main.dart");
74+
7175
final expectedHoverContent = '''
7276
```dart
7377
String abc
7478
```
75-
*file:///${windowsCColon}project/lib/main.dart*
79+
*$containingLibraryName*
7680
7781
---
7882
This is a string.
@@ -168,11 +172,14 @@ print();
168172
String [[a^bc]];
169173
''';
170174

175+
final containingLibraryName =
176+
path.normalize("$windowsCColon/project/lib/main.dart");
177+
171178
final expectedHoverContent = '''
172179
```dart
173180
String abc
174181
```
175-
*file:///${windowsCColon}project/lib/main.dart*
182+
*$containingLibraryName*
176183
'''
177184
.trim();
178185

pkg/analysis_server/tool/spec/generated/java/types/HoverInformation.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ public class HoverInformation {
5555
private final String containingLibraryPath;
5656

5757
/**
58-
* The URI of the containing library, examples here include "dart:core", "package:.." and even
59-
* "file:.." URIs. The data is omitted if the element is declared inside an HTML file.
58+
* The URI of the containing library, examples here include "dart:core", "package:.." and file uris
59+
* represented by the path on disk, "/..". The data is omitted if the element is declared inside an
60+
* HTML file.
6061
*/
6162
private final String containingLibraryName;
6263

@@ -185,8 +186,9 @@ public String getContainingClassDescription() {
185186
}
186187

187188
/**
188-
* The URI of the containing library, examples here include "dart:core", "package:.." and even
189-
* "file:.." URIs. The data is omitted if the element is declared inside an HTML file.
189+
* The URI of the containing library, examples here include "dart:core", "package:.." and file uris
190+
* represented by the path on disk, "/..". The data is omitted if the element is declared inside an
191+
* HTML file.
190192
*/
191193
public String getContainingLibraryName() {
192194
return containingLibraryName;

pkg/analysis_server/tool/spec/spec_input.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,8 +4325,9 @@ <h2 class="domain"><a name="types">Types</a></h2>
43254325
<ref>String</ref>
43264326
<p>
43274327
The URI of the containing library, examples here include
4328-
"dart:core", "package:.." and even "file:.." URIs. The data
4329-
is omitted if the element is declared inside an HTML file.
4328+
"dart:core", "package:.." and file uris represented by the
4329+
path on disk, "/..". The data is omitted if the element is
4330+
declared inside an HTML file.
43304331
</p>
43314332
</field>
43324333
<field name="containingClassDescription" optional="true">

pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15941,15 +15941,15 @@ class HoverInformation implements HasToJson {
1594115941

1594215942
/**
1594315943
* The URI of the containing library, examples here include "dart:core",
15944-
* "package:.." and even "file:.." URIs. The data is omitted if the element
15945-
* is declared inside an HTML file.
15944+
* "package:.." and file uris represented by the path on disk, "/..". The
15945+
* data is omitted if the element is declared inside an HTML file.
1594615946
*/
1594715947
String get containingLibraryName => _containingLibraryName;
1594815948

1594915949
/**
1595015950
* The URI of the containing library, examples here include "dart:core",
15951-
* "package:.." and even "file:.." URIs. The data is omitted if the element
15952-
* is declared inside an HTML file.
15951+
* "package:.." and file uris represented by the path on disk, "/..". The
15952+
* data is omitted if the element is declared inside an HTML file.
1595315953
*/
1595415954
void set containingLibraryName(String value) {
1595515955
this._containingLibraryName = value;

0 commit comments

Comments
 (0)