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

Commit cd2188f

Browse files
committed
DAS change in hover behavior- the containingLibraryName now returns the URI of the containing library instead of the (possibly non-existent) library name
Change-Id: Ief2a7615b92ca635c696d48f907677bae538577b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103481 Reviewed-by: Jaime Wren <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 4fc86d7 commit cd2188f

File tree

9 files changed

+57
-36
lines changed

9 files changed

+57
-36
lines changed

pkg/analysis_server/doc/api.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3851,10 +3851,9 @@ <h2 class="domain"><a name="types">Types</a></h2>
38513851
</dd><dt class="field"><b>containingLibraryName: String<span style="color:#999999"> (optional)</span></b></dt><dd>
38523852

38533853
<p>
3854-
The name of the library in which the referenced element is
3855-
declared. This data is omitted if there is no referenced
3856-
element, or if the element is declared inside an HTML
3857-
file.
3854+
The URI of the containing library, examples here include
3855+
"dart:core", "package:.." and even "file:.." URIs. The data
3856+
is omitted if the element is declared inside an HTML file.
38583857
</p>
38593858
</dd><dt class="field"><b>containingClassDescription: String<span style="color:#999999"> (optional)</span></b></dt><dd>
38603859

pkg/analysis_server/lib/protocol/protocol_generated.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15586,16 +15586,16 @@ class HoverInformation implements HasToJson {
1558615586
}
1558715587

1558815588
/**
15589-
* The name of the library in which the referenced element is declared. This
15590-
* data is omitted if there is no referenced element, or if the element is
15591-
* declared inside an HTML file.
15589+
* The URI of the containing library, examples here include "dart:core",
15590+
* "package:.." and even "file:.." URIs. The data is omitted if the element
15591+
* is declared inside an HTML file.
1559215592
*/
1559315593
String get containingLibraryName => _containingLibraryName;
1559415594

1559515595
/**
15596-
* The name of the library in which the referenced element is declared. This
15597-
* data is omitted if there is no referenced element, or if the element is
15598-
* declared inside an HTML file.
15596+
* The URI of the containing library, examples here include "dart:core",
15597+
* "package:.." and even "file:.." URIs. The data is omitted if the element
15598+
* is declared inside an HTML file.
1559915599
*/
1560015600
void set containingLibraryName(String value) {
1560115601
this._containingLibraryName = value;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class DartUnitHoverComputer {
7272
// containing library
7373
LibraryElement library = element.library;
7474
if (library != null) {
75-
hover.containingLibraryName = library.name;
75+
hover.containingLibraryName = library.source.uri.toString();
7676
hover.containingLibraryPath = library.source.fullName;
7777
}
7878
}

pkg/analysis_server/test/analysis/get_hover_test.dart

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:io';
67

78
import 'package:analysis_server/protocol/protocol.dart';
89
import 'package:analysis_server/protocol/protocol_generated.dart';
@@ -20,6 +21,9 @@ main() {
2021

2122
@reflectiveTest
2223
class AnalysisHoverTest extends AbstractAnalysisTest {
24+
/// If windows, return 'C:/', otherwise return the empty string
25+
String get windowsCColon => Platform.isWindows ? 'C:/' : '';
26+
2327
Future<HoverInformation> prepareHover(String search) {
2428
int offset = findOffset(search);
2529
return prepareHoverAt(offset);
@@ -116,7 +120,8 @@ main() {
116120
expect(hover.offset, findOffset('A(0)'));
117121
expect(hover.length, 'A(0)'.length);
118122
// element
119-
expect(hover.containingLibraryName, 'my.library');
123+
expect(hover.containingLibraryName,
124+
'file:///${windowsCColon}project/bin/test.dart');
120125
expect(hover.containingLibraryPath, testFile);
121126
expect(hover.dartdoc, isNull);
122127
expect(hover.elementDescription, '(const) A(int i) → A');
@@ -141,7 +146,8 @@ main() {
141146
expect(hover.offset, findOffset('A()'));
142147
expect(hover.length, 'A()'.length);
143148
// element
144-
expect(hover.containingLibraryName, 'my.library');
149+
expect(hover.containingLibraryName,
150+
'file:///${windowsCColon}project/bin/test.dart');
145151
expect(hover.containingLibraryPath, testFile);
146152
expect(hover.dartdoc, isNull);
147153
expect(hover.elementDescription, '(new) A() → A');
@@ -167,7 +173,8 @@ main() {
167173
expect(hover.offset, findOffset('new A'));
168174
expect(hover.length, 'new A()'.length);
169175
// element
170-
expect(hover.containingLibraryName, 'my.library');
176+
expect(hover.containingLibraryName,
177+
'file:///${windowsCColon}project/bin/test.dart');
171178
expect(hover.containingLibraryPath, testFile);
172179
expect(hover.dartdoc, isNull);
173180
expect(hover.elementDescription, 'A() → A');
@@ -192,7 +199,8 @@ main() {
192199
expect(hover.offset, findOffset('new A<String>'));
193200
expect(hover.length, 'new A<String>()'.length);
194201
// element
195-
expect(hover.containingLibraryName, 'my.library');
202+
expect(hover.containingLibraryName,
203+
'file:///${windowsCColon}project/bin/test.dart');
196204
expect(hover.containingLibraryPath, testFile);
197205
expect(hover.dartdoc, isNull);
198206
expect(hover.elementDescription, 'A() → A<String>');
@@ -214,6 +222,7 @@ main() {
214222
}
215223
{
216224
HoverInformation hover = await prepareHover('String>');
225+
expect(hover.containingLibraryName, 'dart:core');
217226
expect(hover.offset, findOffset('String>'));
218227
expect(hover.length, 'String'.length);
219228
expect(hover.elementKind, 'class');
@@ -329,7 +338,8 @@ List<String> fff(int a, String b) {
329338
''');
330339
HoverInformation hover = await prepareHover('fff(int a');
331340
// element
332-
expect(hover.containingLibraryName, 'my.library');
341+
expect(hover.containingLibraryName,
342+
'file:///${windowsCColon}project/bin/test.dart');
333343
expect(hover.containingLibraryPath, testFile);
334344
expect(hover.containingClassDescription, isNull);
335345
expect(hover.dartdoc, '''doc aaa\ndoc bbb''');
@@ -356,7 +366,8 @@ main(A a) {
356366
''');
357367
HoverInformation hover = await prepareHover('fff);');
358368
// element
359-
expect(hover.containingLibraryName, 'my.library');
369+
expect(hover.containingLibraryName,
370+
'file:///${windowsCColon}project/bin/test.dart');
360371
expect(hover.containingLibraryPath, testFile);
361372
expect(hover.containingClassDescription, 'A');
362373
expect(hover.dartdoc, '''doc aaa\ndoc bbb''');
@@ -494,7 +505,8 @@ class A {
494505
''');
495506
HoverInformation hover = await prepareHover('mmm(int a');
496507
// element
497-
expect(hover.containingLibraryName, 'my.library');
508+
expect(hover.containingLibraryName,
509+
'file:///${windowsCColon}project/bin/test.dart');
498510
expect(hover.containingLibraryPath, testFile);
499511
expect(hover.containingClassDescription, 'A');
500512
expect(hover.dartdoc, '''doc aaa\ndoc bbb''');
@@ -523,7 +535,8 @@ main(A a) {
523535
expect(hover.offset, findOffset('mmm(42, '));
524536
expect(hover.length, 'mmm'.length);
525537
// element
526-
expect(hover.containingLibraryName, 'my.library');
538+
expect(hover.containingLibraryName,
539+
'file:///${windowsCColon}project/bin/test.dart');
527540
expect(hover.containingLibraryPath, testFile);
528541
expect(hover.elementDescription, 'mmm(int a, String b) → List<String>');
529542
expect(hover.elementKind, 'method');
@@ -571,7 +584,8 @@ f(Stream<int> s) {
571584
expect(hover.offset, findOffset('transform(n'));
572585
expect(hover.length, 'transform'.length);
573586
// element
574-
expect(hover.containingLibraryName, 'my.library');
587+
expect(hover.containingLibraryName,
588+
'file:///${windowsCColon}project/bin/test.dart');
575589
expect(hover.containingLibraryPath, testFile);
576590
expect(hover.elementDescription,
577591
'Stream.transform<S>(StreamTransformer<int, S> streamTransformer) → Stream<S>');

pkg/analysis_server/test/integration/analysis/get_hover_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:io';
67

78
import 'package:analysis_server/protocol/protocol_generated.dart';
89
import 'package:path/path.dart' as path;
@@ -81,13 +82,13 @@ main() {
8182
expect(info.length, equals(length));
8283
if (isCore) {
8384
expect(path.basename(info.containingLibraryPath), equals('core.dart'));
84-
expect(info.containingLibraryName, equals('dart.core'));
85+
expect(info.containingLibraryName, equals('dart:core'));
8586
} else if (isLocal || isLiteral) {
8687
expect(info.containingLibraryPath, isNull);
8788
expect(info.containingLibraryName, isNull);
8889
} else {
8990
expect(info.containingLibraryPath, equals(pathname));
90-
expect(info.containingLibraryName, equals('lib.test'));
91+
expect(info.containingLibraryName, isNotNull);
9192
}
9293
if (docRegexp == null) {
9394
expect(info.dartdoc, isNull);

pkg/analysis_server/test/lsp/hover_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:io';
6+
57
import 'package:analysis_server/lsp_protocol/protocol_generated.dart';
68
import 'package:analysis_server/src/lsp/constants.dart';
79
import 'package:test/test.dart';
@@ -18,6 +20,9 @@ main() {
1820

1921
@reflectiveTest
2022
class HoverTest extends AbstractLspAnalysisServerTest {
23+
/// If windows, return 'C:/', otherwise return the empty string
24+
String get windowsCColon => Platform.isWindows ? 'C:/' : '';
25+
2126
test_dartDoc_macros() async {
2227
final content = '''
2328
/// {@template template_name}
@@ -67,6 +72,8 @@ class HoverTest extends AbstractLspAnalysisServerTest {
6772
```dart
6873
String abc
6974
```
75+
*file:///${windowsCColon}project/lib/main.dart*
76+
7077
---
7178
This is a string.
7279
@@ -165,6 +172,7 @@ print();
165172
```dart
166173
String abc
167174
```
175+
*file:///${windowsCColon}project/lib/main.dart*
168176
'''
169177
.trim();
170178

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

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

5757
/**
58-
* The name of the library in which the referenced element is declared. This data is omitted if
59-
* there is no referenced element, or if the element is declared inside an HTML file.
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.
6060
*/
6161
private final String containingLibraryName;
6262

@@ -185,8 +185,8 @@ public String getContainingClassDescription() {
185185
}
186186

187187
/**
188-
* The name of the library in which the referenced element is declared. This data is omitted if
189-
* there is no referenced element, or if the element is declared inside an HTML file.
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.
190190
*/
191191
public String getContainingLibraryName() {
192192
return containingLibraryName;

pkg/analysis_server/tool/spec/spec_input.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,10 +4212,9 @@ <h2 class="domain"><a name="types">Types</a></h2>
42124212
<field name="containingLibraryName" optional="true">
42134213
<ref>String</ref>
42144214
<p>
4215-
The name of the library in which the referenced element is
4216-
declared. This data is omitted if there is no referenced
4217-
element, or if the element is declared inside an HTML
4218-
file.
4215+
The URI of the containing library, examples here include
4216+
"dart:core", "package:.." and even "file:.." URIs. The data
4217+
is omitted if the element is declared inside an HTML file.
42194218
</p>
42204219
</field>
42214220
<field name="containingClassDescription" optional="true">

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15586,16 +15586,16 @@ class HoverInformation implements HasToJson {
1558615586
}
1558715587

1558815588
/**
15589-
* The name of the library in which the referenced element is declared. This
15590-
* data is omitted if there is no referenced element, or if the element is
15591-
* declared inside an HTML file.
15589+
* The URI of the containing library, examples here include "dart:core",
15590+
* "package:.." and even "file:.." URIs. The data is omitted if the element
15591+
* is declared inside an HTML file.
1559215592
*/
1559315593
String get containingLibraryName => _containingLibraryName;
1559415594

1559515595
/**
15596-
* The name of the library in which the referenced element is declared. This
15597-
* data is omitted if there is no referenced element, or if the element is
15598-
* declared inside an HTML file.
15596+
* The URI of the containing library, examples here include "dart:core",
15597+
* "package:.." and even "file:.." URIs. The data is omitted if the element
15598+
* is declared inside an HTML file.
1559915599
*/
1560015600
void set containingLibraryName(String value) {
1560115601
this._containingLibraryName = value;

0 commit comments

Comments
 (0)