Add AvailableSuggestion.declaringLibraryUri

We need this to support existingImports filtering, because filtering
is done on suggestion basis, not on the whole suggestion set basic,
because of re-exports.

R=brianwilkerson@google.com

Change-Id: Id97cb122fa6e3c5c62e367098e1917eba997a76f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/104808
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov 2019-06-05 01:20:51 +00:00 committed by commit-bot@chromium.org
parent 9dcb026b26
commit 37b714401d
10 changed files with 123 additions and 10 deletions

View file

@ -109,7 +109,7 @@ a:focus, a:hover {
<body>
<h1>Analysis Server API Specification</h1>
<h1 style="color:#999999">Version
1.27.0
1.27.1
</h1>
<p>
This document contains a specification of the API provided by the
@ -3077,6 +3077,13 @@ a:focus, a:hover {
<p>
The identifier to present to the user for code completion.
</p>
</dd><dt class="field"><b>declaringLibraryUri: String</b></dt><dd>
<p>
The URI of the library that declares the element being suggested,
not the URI of the library associated with the enclosing
<tt>AvailableSuggestionSet</tt>.
</p>
</dd><dt class="field"><b>element: <a href="#type_Element">Element</a></b></dt><dd>
<p>

View file

@ -6,7 +6,7 @@
// To regenerate the file, use the script
// "pkg/analysis_server/tool/spec/generate_files".
const String PROTOCOL_VERSION = '1.27.0';
const String PROTOCOL_VERSION = '1.27.1';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES = 'analysis.analyzedFiles';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES_DIRECTORIES = 'directories';

View file

@ -5075,6 +5075,7 @@ class AnalyticsSendTimingResult implements ResponseResult {
*
* {
* "label": String
* "declaringLibraryUri": String
* "element": Element
* "defaultArgumentListString": optional String
* "defaultArgumentListTextRanges": optional List<int>
@ -5091,6 +5092,8 @@ class AnalyticsSendTimingResult implements ResponseResult {
class AvailableSuggestion implements HasToJson {
String _label;
String _declaringLibraryUri;
Element _element;
String _defaultArgumentListString;
@ -5122,6 +5125,21 @@ class AvailableSuggestion implements HasToJson {
this._label = value;
}
/**
* The URI of the library that declares the element being suggested, not the
* URI of the library associated with the enclosing AvailableSuggestionSet.
*/
String get declaringLibraryUri => _declaringLibraryUri;
/**
* The URI of the library that declares the element being suggested, not the
* URI of the library associated with the enclosing AvailableSuggestionSet.
*/
void set declaringLibraryUri(String value) {
assert(value != null);
this._declaringLibraryUri = value;
}
/**
* Information about the element reference being suggested.
*/
@ -5255,7 +5273,7 @@ class AvailableSuggestion implements HasToJson {
this._requiredParameterCount = value;
}
AvailableSuggestion(String label, Element element,
AvailableSuggestion(String label, String declaringLibraryUri, Element element,
{String defaultArgumentListString,
List<int> defaultArgumentListTextRanges,
String docComplete,
@ -5265,6 +5283,7 @@ class AvailableSuggestion implements HasToJson {
List<String> relevanceTags,
int requiredParameterCount}) {
this.label = label;
this.declaringLibraryUri = declaringLibraryUri;
this.element = element;
this.defaultArgumentListString = defaultArgumentListString;
this.defaultArgumentListTextRanges = defaultArgumentListTextRanges;
@ -5288,6 +5307,13 @@ class AvailableSuggestion implements HasToJson {
} else {
throw jsonDecoder.mismatch(jsonPath, "label");
}
String declaringLibraryUri;
if (json.containsKey("declaringLibraryUri")) {
declaringLibraryUri = jsonDecoder.decodeString(
jsonPath + ".declaringLibraryUri", json["declaringLibraryUri"]);
} else {
throw jsonDecoder.mismatch(jsonPath, "declaringLibraryUri");
}
Element element;
if (json.containsKey("element")) {
element = new Element.fromJson(
@ -5339,7 +5365,7 @@ class AvailableSuggestion implements HasToJson {
jsonPath + ".requiredParameterCount",
json["requiredParameterCount"]);
}
return new AvailableSuggestion(label, element,
return new AvailableSuggestion(label, declaringLibraryUri, element,
defaultArgumentListString: defaultArgumentListString,
defaultArgumentListTextRanges: defaultArgumentListTextRanges,
docComplete: docComplete,
@ -5357,6 +5383,7 @@ class AvailableSuggestion implements HasToJson {
Map<String, dynamic> toJson() {
Map<String, dynamic> result = {};
result["label"] = label;
result["declaringLibraryUri"] = declaringLibraryUri;
result["element"] = element.toJson();
if (defaultArgumentListString != null) {
result["defaultArgumentListString"] = defaultArgumentListString;
@ -5392,6 +5419,7 @@ class AvailableSuggestion implements HasToJson {
bool operator ==(other) {
if (other is AvailableSuggestion) {
return label == other.label &&
declaringLibraryUri == other.declaringLibraryUri &&
element == other.element &&
defaultArgumentListString == other.defaultArgumentListString &&
listEqual(defaultArgumentListTextRanges,
@ -5413,6 +5441,7 @@ class AvailableSuggestion implements HasToJson {
int get hashCode {
int hash = 0;
hash = JenkinsSmiHash.combine(hash, label.hashCode);
hash = JenkinsSmiHash.combine(hash, declaringLibraryUri.hashCode);
hash = JenkinsSmiHash.combine(hash, element.hashCode);
hash = JenkinsSmiHash.combine(hash, defaultArgumentListString.hashCode);
hash = JenkinsSmiHash.combine(hash, defaultArgumentListTextRanges.hashCode);

View file

@ -184,6 +184,13 @@ protocol.AvailableSuggestion _protocolAvailableSuggestion(
label = '${declaration.parent.name}.${declaration.name}';
}
String declaringLibraryUri;
if (declaration.parent == null) {
declaringLibraryUri = '${declaration.locationLibraryUri}';
} else {
declaringLibraryUri = '${declaration.parent.locationLibraryUri}';
}
List<String> relevanceTags;
if (declaration.relevanceTags == null) {
relevanceTags = null;
@ -194,6 +201,7 @@ protocol.AvailableSuggestion _protocolAvailableSuggestion(
return protocol.AvailableSuggestion(
label,
declaringLibraryUri,
_protocolElement(declaration),
defaultArgumentListString: declaration.defaultArgumentListString,
defaultArgumentListTextRanges: declaration.defaultArgumentListTextRanges,

View file

@ -172,6 +172,7 @@ final Matcher isAnalysisStatus = new LazyMatcher(() => new MatchesJsonObject(
*
* {
* "label": String
* "declaringLibraryUri": String
* "element": Element
* "defaultArgumentListString": optional String
* "defaultArgumentListTextRanges": optional List<int>
@ -186,6 +187,7 @@ final Matcher isAnalysisStatus = new LazyMatcher(() => new MatchesJsonObject(
final Matcher isAvailableSuggestion =
new LazyMatcher(() => new MatchesJsonObject("AvailableSuggestion", {
"label": isString,
"declaringLibraryUri": isString,
"element": isElement
}, optionalFields: {
"defaultArgumentListString": isString,

View file

@ -61,6 +61,7 @@ class A {
assertJsonText(_getSuggestion(set, 'A'), '''
{
"label": "A",
"declaringLibraryUri": "package:test/a.dart",
"element": {
"kind": "CLASS",
"name": "A",
@ -82,6 +83,7 @@ class A {
assertJsonText(_getSuggestion(set, 'A.a'), '''
{
"label": "A.a",
"declaringLibraryUri": "package:test/a.dart",
"element": {
"kind": "CONSTRUCTOR",
"name": "a",
@ -118,6 +120,7 @@ enum MyEnum {
assertJsonText(_getSuggestion(set, 'MyEnum'), '''
{
"label": "MyEnum",
"declaringLibraryUri": "package:test/a.dart",
"element": {
"kind": "ENUM",
"name": "MyEnum",
@ -139,6 +142,7 @@ enum MyEnum {
assertJsonText(_getSuggestion(set, 'MyEnum.aaa'), '''
{
"label": "MyEnum.aaa",
"declaringLibraryUri": "package:test/a.dart",
"element": {
"kind": "ENUM_CONSTANT",
"name": "aaa",
@ -160,6 +164,7 @@ enum MyEnum {
assertJsonText(_getSuggestion(set, 'MyEnum.bbb'), '''
{
"label": "MyEnum.bbb",
"declaringLibraryUri": "package:test/a.dart",
"element": {
"kind": "ENUM_CONSTANT",
"name": "bbb",
@ -195,6 +200,7 @@ var stringV = 'hi';
assertJsonText(_getSuggestion(set, 'boolV'), '''
{
"label": "boolV",
"declaringLibraryUri": "package:test/a.dart",
"element": {
"kind": "TOP_LEVEL_VARIABLE",
"name": "boolV",
@ -217,6 +223,7 @@ var stringV = 'hi';
assertJsonText(_getSuggestion(set, 'intV'), '''
{
"label": "intV",
"declaringLibraryUri": "package:test/a.dart",
"element": {
"kind": "TOP_LEVEL_VARIABLE",
"name": "intV",
@ -239,6 +246,7 @@ var stringV = 'hi';
assertJsonText(_getSuggestion(set, 'doubleV'), '''
{
"label": "doubleV",
"declaringLibraryUri": "package:test/a.dart",
"element": {
"kind": "TOP_LEVEL_VARIABLE",
"name": "doubleV",
@ -261,6 +269,7 @@ var stringV = 'hi';
assertJsonText(_getSuggestion(set, 'stringV'), '''
{
"label": "stringV",
"declaringLibraryUri": "package:test/a.dart",
"element": {
"kind": "TOP_LEVEL_VARIABLE",
"name": "stringV",

View file

@ -41,6 +41,12 @@ public class AvailableSuggestion {
*/
private final String label;
/**
* The URI of the library that declares the element being suggested, not the URI of the library
* associated with the enclosing AvailableSuggestionSet.
*/
private final String declaringLibraryUri;
/**
* Information about the element reference being suggested.
*/
@ -96,8 +102,9 @@ public class AvailableSuggestion {
/**
* Constructor for {@link AvailableSuggestion}.
*/
public AvailableSuggestion(String label, Element element, String defaultArgumentListString, int[] defaultArgumentListTextRanges, String docComplete, String docSummary, List<String> parameterNames, List<String> parameterTypes, List<String> relevanceTags, Integer requiredParameterCount) {
public AvailableSuggestion(String label, String declaringLibraryUri, Element element, String defaultArgumentListString, int[] defaultArgumentListTextRanges, String docComplete, String docSummary, List<String> parameterNames, List<String> parameterTypes, List<String> relevanceTags, Integer requiredParameterCount) {
this.label = label;
this.declaringLibraryUri = declaringLibraryUri;
this.element = element;
this.defaultArgumentListString = defaultArgumentListString;
this.defaultArgumentListTextRanges = defaultArgumentListTextRanges;
@ -115,6 +122,7 @@ public class AvailableSuggestion {
AvailableSuggestion other = (AvailableSuggestion) obj;
return
ObjectUtilities.equals(other.label, label) &&
ObjectUtilities.equals(other.declaringLibraryUri, declaringLibraryUri) &&
ObjectUtilities.equals(other.element, element) &&
ObjectUtilities.equals(other.defaultArgumentListString, defaultArgumentListString) &&
Arrays.equals(other.defaultArgumentListTextRanges, defaultArgumentListTextRanges) &&
@ -130,6 +138,7 @@ public class AvailableSuggestion {
public static AvailableSuggestion fromJson(JsonObject jsonObject) {
String label = jsonObject.get("label").getAsString();
String declaringLibraryUri = jsonObject.get("declaringLibraryUri").getAsString();
Element element = Element.fromJson(jsonObject.get("element").getAsJsonObject());
String defaultArgumentListString = jsonObject.get("defaultArgumentListString") == null ? null : jsonObject.get("defaultArgumentListString").getAsString();
int[] defaultArgumentListTextRanges = jsonObject.get("defaultArgumentListTextRanges") == null ? null : JsonUtilities.decodeIntArray(jsonObject.get("defaultArgumentListTextRanges").getAsJsonArray());
@ -139,7 +148,7 @@ public class AvailableSuggestion {
List<String> parameterTypes = jsonObject.get("parameterTypes") == null ? null : JsonUtilities.decodeStringList(jsonObject.get("parameterTypes").getAsJsonArray());
List<String> relevanceTags = jsonObject.get("relevanceTags") == null ? null : JsonUtilities.decodeStringList(jsonObject.get("relevanceTags").getAsJsonArray());
Integer requiredParameterCount = jsonObject.get("requiredParameterCount") == null ? null : jsonObject.get("requiredParameterCount").getAsInt();
return new AvailableSuggestion(label, element, defaultArgumentListString, defaultArgumentListTextRanges, docComplete, docSummary, parameterNames, parameterTypes, relevanceTags, requiredParameterCount);
return new AvailableSuggestion(label, declaringLibraryUri, element, defaultArgumentListString, defaultArgumentListTextRanges, docComplete, docSummary, parameterNames, parameterTypes, relevanceTags, requiredParameterCount);
}
public static List<AvailableSuggestion> fromJsonArray(JsonArray jsonArray) {
@ -154,6 +163,14 @@ public class AvailableSuggestion {
return list;
}
/**
* The URI of the library that declares the element being suggested, not the URI of the library
* associated with the enclosing AvailableSuggestionSet.
*/
public String getDeclaringLibraryUri() {
return declaringLibraryUri;
}
/**
* A default String for use in generating argument list source contents on the client side.
*/
@ -235,6 +252,7 @@ public class AvailableSuggestion {
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder();
builder.append(label);
builder.append(declaringLibraryUri);
builder.append(element);
builder.append(defaultArgumentListString);
builder.append(defaultArgumentListTextRanges);
@ -250,6 +268,7 @@ public class AvailableSuggestion {
public JsonObject toJson() {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("label", label);
jsonObject.addProperty("declaringLibraryUri", declaringLibraryUri);
jsonObject.add("element", element.toJson());
if (defaultArgumentListString != null) {
jsonObject.addProperty("defaultArgumentListString", defaultArgumentListString);
@ -300,6 +319,8 @@ public class AvailableSuggestion {
builder.append("[");
builder.append("label=");
builder.append(label + ", ");
builder.append("declaringLibraryUri=");
builder.append(declaringLibraryUri + ", ");
builder.append("element=");
builder.append(element + ", ");
builder.append("defaultArgumentListString=");

View file

@ -7,7 +7,7 @@
<body>
<h1>Analysis Server API Specification</h1>
<h1 style="color:#999999">Version
<version>1.27.0</version>
<version>1.27.1</version>
</h1>
<p>
This document contains a specification of the API provided by the
@ -3598,6 +3598,14 @@
The identifier to present to the user for code completion.
</p>
</field>
<field name="declaringLibraryUri">
<ref>String</ref>
<p>
The URI of the library that declares the element being suggested,
not the URI of the library associated with the enclosing
<tt>AvailableSuggestionSet</tt>.
</p>
</field>
<field name="element">
<ref>Element</ref>
<p>

View file

@ -6,7 +6,7 @@
// To regenerate the file, use the script
// "pkg/analysis_server/tool/spec/generate_files".
const String PROTOCOL_VERSION = '1.27.0';
const String PROTOCOL_VERSION = '1.27.1';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES = 'analysis.analyzedFiles';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES_DIRECTORIES = 'directories';

View file

@ -5075,6 +5075,7 @@ class AnalyticsSendTimingResult implements ResponseResult {
*
* {
* "label": String
* "declaringLibraryUri": String
* "element": Element
* "defaultArgumentListString": optional String
* "defaultArgumentListTextRanges": optional List<int>
@ -5091,6 +5092,8 @@ class AnalyticsSendTimingResult implements ResponseResult {
class AvailableSuggestion implements HasToJson {
String _label;
String _declaringLibraryUri;
Element _element;
String _defaultArgumentListString;
@ -5122,6 +5125,21 @@ class AvailableSuggestion implements HasToJson {
this._label = value;
}
/**
* The URI of the library that declares the element being suggested, not the
* URI of the library associated with the enclosing AvailableSuggestionSet.
*/
String get declaringLibraryUri => _declaringLibraryUri;
/**
* The URI of the library that declares the element being suggested, not the
* URI of the library associated with the enclosing AvailableSuggestionSet.
*/
void set declaringLibraryUri(String value) {
assert(value != null);
this._declaringLibraryUri = value;
}
/**
* Information about the element reference being suggested.
*/
@ -5255,7 +5273,7 @@ class AvailableSuggestion implements HasToJson {
this._requiredParameterCount = value;
}
AvailableSuggestion(String label, Element element,
AvailableSuggestion(String label, String declaringLibraryUri, Element element,
{String defaultArgumentListString,
List<int> defaultArgumentListTextRanges,
String docComplete,
@ -5265,6 +5283,7 @@ class AvailableSuggestion implements HasToJson {
List<String> relevanceTags,
int requiredParameterCount}) {
this.label = label;
this.declaringLibraryUri = declaringLibraryUri;
this.element = element;
this.defaultArgumentListString = defaultArgumentListString;
this.defaultArgumentListTextRanges = defaultArgumentListTextRanges;
@ -5288,6 +5307,13 @@ class AvailableSuggestion implements HasToJson {
} else {
throw jsonDecoder.mismatch(jsonPath, "label");
}
String declaringLibraryUri;
if (json.containsKey("declaringLibraryUri")) {
declaringLibraryUri = jsonDecoder.decodeString(
jsonPath + ".declaringLibraryUri", json["declaringLibraryUri"]);
} else {
throw jsonDecoder.mismatch(jsonPath, "declaringLibraryUri");
}
Element element;
if (json.containsKey("element")) {
element = new Element.fromJson(
@ -5339,7 +5365,7 @@ class AvailableSuggestion implements HasToJson {
jsonPath + ".requiredParameterCount",
json["requiredParameterCount"]);
}
return new AvailableSuggestion(label, element,
return new AvailableSuggestion(label, declaringLibraryUri, element,
defaultArgumentListString: defaultArgumentListString,
defaultArgumentListTextRanges: defaultArgumentListTextRanges,
docComplete: docComplete,
@ -5357,6 +5383,7 @@ class AvailableSuggestion implements HasToJson {
Map<String, dynamic> toJson() {
Map<String, dynamic> result = {};
result["label"] = label;
result["declaringLibraryUri"] = declaringLibraryUri;
result["element"] = element.toJson();
if (defaultArgumentListString != null) {
result["defaultArgumentListString"] = defaultArgumentListString;
@ -5392,6 +5419,7 @@ class AvailableSuggestion implements HasToJson {
bool operator ==(other) {
if (other is AvailableSuggestion) {
return label == other.label &&
declaringLibraryUri == other.declaringLibraryUri &&
element == other.element &&
defaultArgumentListString == other.defaultArgumentListString &&
listEqual(defaultArgumentListTextRanges,
@ -5413,6 +5441,7 @@ class AvailableSuggestion implements HasToJson {
int get hashCode {
int hash = 0;
hash = JenkinsSmiHash.combine(hash, label.hashCode);
hash = JenkinsSmiHash.combine(hash, declaringLibraryUri.hashCode);
hash = JenkinsSmiHash.combine(hash, element.hashCode);
hash = JenkinsSmiHash.combine(hash, defaultArgumentListString.hashCode);
hash = JenkinsSmiHash.combine(hash, defaultArgumentListTextRanges.hashCode);