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 <jwren@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/doc/api.html b/pkg/analysis_server/doc/api.html
index 918ff0b..e82eb2b 100644
--- a/pkg/analysis_server/doc/api.html
+++ b/pkg/analysis_server/doc/api.html
@@ -3851,10 +3851,9 @@
</dd><dt class="field"><b>containingLibraryName: String<span style="color:#999999"> (optional)</span></b></dt><dd>
<p>
- The name of the library in which the referenced element is
- declared. This data is omitted if there is no referenced
- element, or if the element is declared inside an HTML
- file.
+ 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.
</p>
</dd><dt class="field"><b>containingClassDescription: String<span style="color:#999999"> (optional)</span></b></dt><dd>
diff --git a/pkg/analysis_server/lib/protocol/protocol_generated.dart b/pkg/analysis_server/lib/protocol/protocol_generated.dart
index 6e7da59..287fcd5 100644
--- a/pkg/analysis_server/lib/protocol/protocol_generated.dart
+++ b/pkg/analysis_server/lib/protocol/protocol_generated.dart
@@ -15586,16 +15586,16 @@
}
/**
- * The name of the library in which the referenced element is declared. This
- * data is omitted if there is no referenced element, or if the element is
- * declared inside an HTML file.
+ * 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.
*/
String get containingLibraryName => _containingLibraryName;
/**
- * The name of the library in which the referenced element is declared. This
- * data is omitted if there is no referenced element, or if the element is
- * declared inside an HTML file.
+ * 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.
*/
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 1dd0b83..b5f3e7a 100644
--- a/pkg/analysis_server/lib/src/computer/computer_hover.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_hover.dart
@@ -72,7 +72,7 @@
// containing library
LibraryElement library = element.library;
if (library != null) {
- hover.containingLibraryName = library.name;
+ hover.containingLibraryName = library.source.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 7dc1119..ae1938f 100644
--- a/pkg/analysis_server/test/analysis/get_hover_test.dart
+++ b/pkg/analysis_server/test/analysis/get_hover_test.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
+import 'dart:io';
import 'package:analysis_server/protocol/protocol.dart';
import 'package:analysis_server/protocol/protocol_generated.dart';
@@ -20,6 +21,9 @@
@reflectiveTest
class AnalysisHoverTest extends AbstractAnalysisTest {
+ /// If windows, return 'C:/', otherwise return the empty string
+ String get windowsCColon => Platform.isWindows ? 'C:/' : '';
+
Future<HoverInformation> prepareHover(String search) {
int offset = findOffset(search);
return prepareHoverAt(offset);
@@ -116,7 +120,8 @@
expect(hover.offset, findOffset('A(0)'));
expect(hover.length, 'A(0)'.length);
// element
- expect(hover.containingLibraryName, 'my.library');
+ expect(hover.containingLibraryName,
+ 'file:///${windowsCColon}project/bin/test.dart');
expect(hover.containingLibraryPath, testFile);
expect(hover.dartdoc, isNull);
expect(hover.elementDescription, '(const) A(int i) → A');
@@ -141,7 +146,8 @@
expect(hover.offset, findOffset('A()'));
expect(hover.length, 'A()'.length);
// element
- expect(hover.containingLibraryName, 'my.library');
+ expect(hover.containingLibraryName,
+ 'file:///${windowsCColon}project/bin/test.dart');
expect(hover.containingLibraryPath, testFile);
expect(hover.dartdoc, isNull);
expect(hover.elementDescription, '(new) A() → A');
@@ -167,7 +173,8 @@
expect(hover.offset, findOffset('new A'));
expect(hover.length, 'new A()'.length);
// element
- expect(hover.containingLibraryName, 'my.library');
+ expect(hover.containingLibraryName,
+ 'file:///${windowsCColon}project/bin/test.dart');
expect(hover.containingLibraryPath, testFile);
expect(hover.dartdoc, isNull);
expect(hover.elementDescription, 'A() → A');
@@ -192,7 +199,8 @@
expect(hover.offset, findOffset('new A<String>'));
expect(hover.length, 'new A<String>()'.length);
// element
- expect(hover.containingLibraryName, 'my.library');
+ expect(hover.containingLibraryName,
+ 'file:///${windowsCColon}project/bin/test.dart');
expect(hover.containingLibraryPath, testFile);
expect(hover.dartdoc, isNull);
expect(hover.elementDescription, 'A() → A<String>');
@@ -214,6 +222,7 @@
}
{
HoverInformation hover = await prepareHover('String>');
+ expect(hover.containingLibraryName, 'dart:core');
expect(hover.offset, findOffset('String>'));
expect(hover.length, 'String'.length);
expect(hover.elementKind, 'class');
@@ -329,7 +338,8 @@
''');
HoverInformation hover = await prepareHover('fff(int a');
// element
- expect(hover.containingLibraryName, 'my.library');
+ expect(hover.containingLibraryName,
+ 'file:///${windowsCColon}project/bin/test.dart');
expect(hover.containingLibraryPath, testFile);
expect(hover.containingClassDescription, isNull);
expect(hover.dartdoc, '''doc aaa\ndoc bbb''');
@@ -356,7 +366,8 @@
''');
HoverInformation hover = await prepareHover('fff);');
// element
- expect(hover.containingLibraryName, 'my.library');
+ expect(hover.containingLibraryName,
+ 'file:///${windowsCColon}project/bin/test.dart');
expect(hover.containingLibraryPath, testFile);
expect(hover.containingClassDescription, 'A');
expect(hover.dartdoc, '''doc aaa\ndoc bbb''');
@@ -494,7 +505,8 @@
''');
HoverInformation hover = await prepareHover('mmm(int a');
// element
- expect(hover.containingLibraryName, 'my.library');
+ expect(hover.containingLibraryName,
+ 'file:///${windowsCColon}project/bin/test.dart');
expect(hover.containingLibraryPath, testFile);
expect(hover.containingClassDescription, 'A');
expect(hover.dartdoc, '''doc aaa\ndoc bbb''');
@@ -523,7 +535,8 @@
expect(hover.offset, findOffset('mmm(42, '));
expect(hover.length, 'mmm'.length);
// element
- expect(hover.containingLibraryName, 'my.library');
+ expect(hover.containingLibraryName,
+ 'file:///${windowsCColon}project/bin/test.dart');
expect(hover.containingLibraryPath, testFile);
expect(hover.elementDescription, 'mmm(int a, String b) → List<String>');
expect(hover.elementKind, 'method');
@@ -571,7 +584,8 @@
expect(hover.offset, findOffset('transform(n'));
expect(hover.length, 'transform'.length);
// element
- expect(hover.containingLibraryName, 'my.library');
+ expect(hover.containingLibraryName,
+ 'file:///${windowsCColon}project/bin/test.dart');
expect(hover.containingLibraryPath, testFile);
expect(hover.elementDescription,
'Stream.transform<S>(StreamTransformer<int, S> streamTransformer) → Stream<S>');
diff --git a/pkg/analysis_server/test/integration/analysis/get_hover_test.dart b/pkg/analysis_server/test/integration/analysis/get_hover_test.dart
index e2f25af..49f0dc4 100644
--- a/pkg/analysis_server/test/integration/analysis/get_hover_test.dart
+++ b/pkg/analysis_server/test/integration/analysis/get_hover_test.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
+import 'dart:io';
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:path/path.dart' as path;
@@ -81,13 +82,13 @@
expect(info.length, equals(length));
if (isCore) {
expect(path.basename(info.containingLibraryPath), equals('core.dart'));
- expect(info.containingLibraryName, equals('dart.core'));
+ expect(info.containingLibraryName, equals('dart:core'));
} else if (isLocal || isLiteral) {
expect(info.containingLibraryPath, isNull);
expect(info.containingLibraryName, isNull);
} else {
expect(info.containingLibraryPath, equals(pathname));
- expect(info.containingLibraryName, equals('lib.test'));
+ expect(info.containingLibraryName, isNotNull);
}
if (docRegexp == null) {
expect(info.dartdoc, isNull);
diff --git a/pkg/analysis_server/test/lsp/hover_test.dart b/pkg/analysis_server/test/lsp/hover_test.dart
index 6b9be51..46e1a70 100644
--- a/pkg/analysis_server/test/lsp/hover_test.dart
+++ b/pkg/analysis_server/test/lsp/hover_test.dart
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'dart:io';
+
import 'package:analysis_server/lsp_protocol/protocol_generated.dart';
import 'package:analysis_server/src/lsp/constants.dart';
import 'package:test/test.dart';
@@ -18,6 +20,9 @@
@reflectiveTest
class HoverTest extends AbstractLspAnalysisServerTest {
+ /// If windows, return 'C:/', otherwise return the empty string
+ String get windowsCColon => Platform.isWindows ? 'C:/' : '';
+
test_dartDoc_macros() async {
final content = '''
/// {@template template_name}
@@ -67,6 +72,8 @@
```dart
String abc
```
+*file:///${windowsCColon}project/lib/main.dart*
+
---
This is a string.
@@ -165,6 +172,7 @@
```dart
String abc
```
+*file:///${windowsCColon}project/lib/main.dart*
'''
.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 463b420..36b21ae 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,8 @@
private final String containingLibraryPath;
/**
- * The name of the library in which the referenced element is declared. This data is omitted if
- * there is no referenced element, or if the element is declared inside an HTML file.
+ * 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.
*/
private final String containingLibraryName;
@@ -185,8 +185,8 @@
}
/**
- * The name of the library in which the referenced element is declared. This data is omitted if
- * there is no referenced element, or if the element is declared inside an HTML file.
+ * 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.
*/
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 362a389..f091a4a 100644
--- a/pkg/analysis_server/tool/spec/spec_input.html
+++ b/pkg/analysis_server/tool/spec/spec_input.html
@@ -4212,10 +4212,9 @@
<field name="containingLibraryName" optional="true">
<ref>String</ref>
<p>
- The name of the library in which the referenced element is
- declared. This data is omitted if there is no referenced
- element, or if the element is declared inside an HTML
- file.
+ 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.
</p>
</field>
<field name="containingClassDescription" optional="true">
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 5d1b076..fc05957 100644
--- a/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart
+++ b/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart
@@ -15586,16 +15586,16 @@
}
/**
- * The name of the library in which the referenced element is declared. This
- * data is omitted if there is no referenced element, or if the element is
- * declared inside an HTML file.
+ * 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.
*/
String get containingLibraryName => _containingLibraryName;
/**
- * The name of the library in which the referenced element is declared. This
- * data is omitted if there is no referenced element, or if the element is
- * declared inside an HTML file.
+ * 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.
*/
void set containingLibraryName(String value) {
this._containingLibraryName = value;