From b767744cfc1e3a24e9ccd27abeb47fa756493bce Mon Sep 17 00:00:00 2001 From: lambdabaa Date: Wed, 9 Jan 2019 00:13:39 +0000 Subject: [PATCH] Add optional elementUri field to CompletionSuggestion types in analysis server protocol This will enable clients such as IntelliJ to display the package which code completions are being offered from in addition to the keyword or identifier that they're already getting from analysis server. R=brianwilkerson@google.com Change-Id: I30311451ad56b4eddbe73da20641ee0d14849293 Reviewed-on: https://dart-review.googlesource.com/c/88744 Reviewed-by: Brian Wilkerson Commit-Queue: Ari Aye --- pkg/analysis_server/doc/api.html | 8 ++++- .../lib/protocol/protocol_constants.dart | 2 +- .../support/protocol_matchers.dart | 2 ++ .../java/types/CompletionSuggestion.java | 27 +++++++++++++++-- pkg/analysis_server/tool/spec/spec_input.html | 2 +- .../lib/src/protocol/protocol_constants.dart | 2 +- pkg/analyzer_plugin/doc/api.html | 6 ++++ .../lib/protocol/protocol_common.dart | 30 +++++++++++++++++++ .../support/protocol_matchers.dart | 2 ++ .../tool/spec/common_types_spec.html | 7 +++++ 10 files changed, 82 insertions(+), 6 deletions(-) diff --git a/pkg/analysis_server/doc/api.html b/pkg/analysis_server/doc/api.html index 713507e0e53..bf31832f509 100644 --- a/pkg/analysis_server/doc/api.html +++ b/pkg/analysis_server/doc/api.html @@ -109,7 +109,7 @@ a:focus, a:hover {

Analysis Server API Specification

Version - 1.21.1 + 1.22.1

This document contains a specification of the API provided by the @@ -2918,6 +2918,12 @@ a:focus, a:hover { is only defined if the displayed text should be different than the completion. Otherwise it is omitted.

+
elementUri: String (optional)
+ +

+ The URI of the element corresponding to this suggestion. It will be + set whenever analysis server is able to compute it. +

selectionOffset: int

diff --git a/pkg/analysis_server/lib/protocol/protocol_constants.dart b/pkg/analysis_server/lib/protocol/protocol_constants.dart index 15c626a0896..fd21adb3efb 100644 --- a/pkg/analysis_server/lib/protocol/protocol_constants.dart +++ b/pkg/analysis_server/lib/protocol/protocol_constants.dart @@ -6,7 +6,7 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". -const String PROTOCOL_VERSION = '1.21.1'; +const String PROTOCOL_VERSION = '1.22.1'; const String ANALYSIS_NOTIFICATION_ANALYZED_FILES = 'analysis.analyzedFiles'; const String ANALYSIS_NOTIFICATION_ANALYZED_FILES_DIRECTORIES = 'directories'; diff --git a/pkg/analysis_server/test/integration/support/protocol_matchers.dart b/pkg/analysis_server/test/integration/support/protocol_matchers.dart index 3e82faf224c..6630dbef0af 100644 --- a/pkg/analysis_server/test/integration/support/protocol_matchers.dart +++ b/pkg/analysis_server/test/integration/support/protocol_matchers.dart @@ -202,6 +202,7 @@ final Matcher isCompletionId = isString; * "relevance": int * "completion": String * "displayText": optional String + * "elementUri": optional String * "selectionOffset": int * "selectionLength": int * "isDeprecated": bool @@ -233,6 +234,7 @@ final Matcher isCompletionSuggestion = "isPotential": isBool }, optionalFields: { "displayText": isString, + "elementUri": isString, "docSummary": isString, "docComplete": isString, "declaringType": isString, diff --git a/pkg/analysis_server/tool/spec/generated/java/types/CompletionSuggestion.java b/pkg/analysis_server/tool/spec/generated/java/types/CompletionSuggestion.java index 073d8029e53..83f2643b027 100644 --- a/pkg/analysis_server/tool/spec/generated/java/types/CompletionSuggestion.java +++ b/pkg/analysis_server/tool/spec/generated/java/types/CompletionSuggestion.java @@ -59,6 +59,12 @@ public class CompletionSuggestion { */ private final String displayText; + /** + * The URI of the element corresponding to this suggestion. It will be set whenever analysis server + * is able to compute it. + */ + private final String elementUri; + /** * The offset, relative to the beginning of the completion, of where the selection should be placed * after insertion. @@ -169,11 +175,12 @@ public class CompletionSuggestion { /** * Constructor for {@link CompletionSuggestion}. */ - public CompletionSuggestion(String kind, int relevance, String completion, String displayText, int selectionOffset, int selectionLength, boolean isDeprecated, boolean isPotential, String docSummary, String docComplete, String declaringType, String defaultArgumentListString, int[] defaultArgumentListTextRanges, Element element, String returnType, List parameterNames, List parameterTypes, Integer requiredParameterCount, Boolean hasNamedParameters, String parameterName, String parameterType, String importUri) { + public CompletionSuggestion(String kind, int relevance, String completion, String displayText, String elementUri, int selectionOffset, int selectionLength, boolean isDeprecated, boolean isPotential, String docSummary, String docComplete, String declaringType, String defaultArgumentListString, int[] defaultArgumentListTextRanges, Element element, String returnType, List parameterNames, List parameterTypes, Integer requiredParameterCount, Boolean hasNamedParameters, String parameterName, String parameterType, String importUri) { this.kind = kind; this.relevance = relevance; this.completion = completion; this.displayText = displayText; + this.elementUri = elementUri; this.selectionOffset = selectionOffset; this.selectionLength = selectionLength; this.isDeprecated = isDeprecated; @@ -203,6 +210,7 @@ public class CompletionSuggestion { other.relevance == relevance && ObjectUtilities.equals(other.completion, completion) && ObjectUtilities.equals(other.displayText, displayText) && + ObjectUtilities.equals(other.elementUri, elementUri) && other.selectionOffset == selectionOffset && other.selectionLength == selectionLength && other.isDeprecated == isDeprecated && @@ -230,6 +238,7 @@ public class CompletionSuggestion { int relevance = jsonObject.get("relevance").getAsInt(); String completion = jsonObject.get("completion").getAsString(); String displayText = jsonObject.get("displayText") == null ? null : jsonObject.get("displayText").getAsString(); + String elementUri = jsonObject.get("elementUri") == null ? null : jsonObject.get("elementUri").getAsString(); int selectionOffset = jsonObject.get("selectionOffset").getAsInt(); int selectionLength = jsonObject.get("selectionLength").getAsInt(); boolean isDeprecated = jsonObject.get("isDeprecated").getAsBoolean(); @@ -248,7 +257,7 @@ public class CompletionSuggestion { String parameterName = jsonObject.get("parameterName") == null ? null : jsonObject.get("parameterName").getAsString(); String parameterType = jsonObject.get("parameterType") == null ? null : jsonObject.get("parameterType").getAsString(); String importUri = jsonObject.get("importUri") == null ? null : jsonObject.get("importUri").getAsString(); - return new CompletionSuggestion(kind, relevance, completion, displayText, selectionOffset, selectionLength, isDeprecated, isPotential, docSummary, docComplete, declaringType, defaultArgumentListString, defaultArgumentListTextRanges, element, returnType, parameterNames, parameterTypes, requiredParameterCount, hasNamedParameters, parameterName, parameterType, importUri); + return new CompletionSuggestion(kind, relevance, completion, displayText, elementUri, selectionOffset, selectionLength, isDeprecated, isPotential, docSummary, docComplete, declaringType, defaultArgumentListString, defaultArgumentListTextRanges, element, returnType, parameterNames, parameterTypes, requiredParameterCount, hasNamedParameters, parameterName, parameterType, importUri); } public static List fromJsonArray(JsonArray jsonArray) { @@ -329,6 +338,14 @@ public class CompletionSuggestion { return element; } + /** + * The URI of the element corresponding to this suggestion. It will be set whenever analysis server + * is able to compute it. + */ + public String getElementUri() { + return elementUri; + } + /** * True if the function or method being suggested has at least one named parameter. This field is * omitted if the parameterNames field is omitted. @@ -444,6 +461,7 @@ public class CompletionSuggestion { builder.append(relevance); builder.append(completion); builder.append(displayText); + builder.append(elementUri); builder.append(selectionOffset); builder.append(selectionLength); builder.append(isDeprecated); @@ -473,6 +491,9 @@ public class CompletionSuggestion { if (displayText != null) { jsonObject.addProperty("displayText", displayText); } + if (elementUri != null) { + jsonObject.addProperty("elementUri", elementUri); + } jsonObject.addProperty("selectionOffset", selectionOffset); jsonObject.addProperty("selectionLength", selectionLength); jsonObject.addProperty("isDeprecated", isDeprecated); @@ -546,6 +567,8 @@ public class CompletionSuggestion { builder.append(completion + ", "); builder.append("displayText="); builder.append(displayText + ", "); + builder.append("elementUri="); + builder.append(elementUri + ", "); builder.append("selectionOffset="); builder.append(selectionOffset + ", "); builder.append("selectionLength="); diff --git a/pkg/analysis_server/tool/spec/spec_input.html b/pkg/analysis_server/tool/spec/spec_input.html index 0266e7c669c..24189915a5b 100644 --- a/pkg/analysis_server/tool/spec/spec_input.html +++ b/pkg/analysis_server/tool/spec/spec_input.html @@ -7,7 +7,7 @@

Analysis Server API Specification

Version - 1.21.1 + 1.22.1

This document contains a specification of the API provided by the diff --git a/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart b/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart index 15c626a0896..fd21adb3efb 100644 --- a/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart +++ b/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart @@ -6,7 +6,7 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/spec/generate_files". -const String PROTOCOL_VERSION = '1.21.1'; +const String PROTOCOL_VERSION = '1.22.1'; const String ANALYSIS_NOTIFICATION_ANALYZED_FILES = 'analysis.analyzedFiles'; const String ANALYSIS_NOTIFICATION_ANALYZED_FILES_DIRECTORIES = 'directories'; diff --git a/pkg/analyzer_plugin/doc/api.html b/pkg/analyzer_plugin/doc/api.html index 6ab809cf669..0d84b988255 100644 --- a/pkg/analyzer_plugin/doc/api.html +++ b/pkg/analyzer_plugin/doc/api.html @@ -1004,6 +1004,12 @@ a:focus, a:hover { is only defined if the displayed text should be different than the completion. Otherwise it is omitted.

+
elementUri: String (optional)
+ +

+ The URI of the element corresponding to this suggestion. It will be + set whenever analysis server is able to compute it. +

selectionOffset: int

diff --git a/pkg/analyzer_plugin/lib/protocol/protocol_common.dart b/pkg/analyzer_plugin/lib/protocol/protocol_common.dart index 596aa9e9cdd..b7718d79686 100644 --- a/pkg/analyzer_plugin/lib/protocol/protocol_common.dart +++ b/pkg/analyzer_plugin/lib/protocol/protocol_common.dart @@ -598,6 +598,7 @@ class ChangeContentOverlay implements HasToJson { * "relevance": int * "completion": String * "displayText": optional String + * "elementUri": optional String * "selectionOffset": int * "selectionLength": int * "isDeprecated": bool @@ -629,6 +630,8 @@ class CompletionSuggestion implements HasToJson { String _displayText; + String _elementUri; + int _selectionOffset; int _selectionLength; @@ -728,6 +731,20 @@ class CompletionSuggestion implements HasToJson { this._displayText = value; } + /** + * The URI of the element corresponding to this suggestion. It will be set + * whenever analysis server is able to compute it. + */ + String get elementUri => _elementUri; + + /** + * The URI of the element corresponding to this suggestion. It will be set + * whenever analysis server is able to compute it. + */ + void set elementUri(String value) { + this._elementUri = value; + } + /** * The offset, relative to the beginning of the completion, of where the * selection should be placed after insertion. @@ -1003,6 +1020,7 @@ class CompletionSuggestion implements HasToJson { bool isDeprecated, bool isPotential, {String displayText, + String elementUri, String docSummary, String docComplete, String declaringType, @@ -1021,6 +1039,7 @@ class CompletionSuggestion implements HasToJson { this.relevance = relevance; this.completion = completion; this.displayText = displayText; + this.elementUri = elementUri; this.selectionOffset = selectionOffset; this.selectionLength = selectionLength; this.isDeprecated = isDeprecated; @@ -1073,6 +1092,11 @@ class CompletionSuggestion implements HasToJson { displayText = jsonDecoder.decodeString( jsonPath + ".displayText", json["displayText"]); } + String elementUri; + if (json.containsKey("elementUri")) { + elementUri = jsonDecoder.decodeString( + jsonPath + ".elementUri", json["elementUri"]); + } int selectionOffset; if (json.containsKey("selectionOffset")) { selectionOffset = jsonDecoder.decodeInt( @@ -1178,6 +1202,7 @@ class CompletionSuggestion implements HasToJson { return new CompletionSuggestion(kind, relevance, completion, selectionOffset, selectionLength, isDeprecated, isPotential, displayText: displayText, + elementUri: elementUri, docSummary: docSummary, docComplete: docComplete, declaringType: declaringType, @@ -1206,6 +1231,9 @@ class CompletionSuggestion implements HasToJson { if (displayText != null) { result["displayText"] = displayText; } + if (elementUri != null) { + result["elementUri"] = elementUri; + } result["selectionOffset"] = selectionOffset; result["selectionLength"] = selectionLength; result["isDeprecated"] = isDeprecated; @@ -1265,6 +1293,7 @@ class CompletionSuggestion implements HasToJson { relevance == other.relevance && completion == other.completion && displayText == other.displayText && + elementUri == other.elementUri && selectionOffset == other.selectionOffset && selectionLength == other.selectionLength && isDeprecated == other.isDeprecated && @@ -1297,6 +1326,7 @@ class CompletionSuggestion implements HasToJson { hash = JenkinsSmiHash.combine(hash, relevance.hashCode); hash = JenkinsSmiHash.combine(hash, completion.hashCode); hash = JenkinsSmiHash.combine(hash, displayText.hashCode); + hash = JenkinsSmiHash.combine(hash, elementUri.hashCode); hash = JenkinsSmiHash.combine(hash, selectionOffset.hashCode); hash = JenkinsSmiHash.combine(hash, selectionLength.hashCode); hash = JenkinsSmiHash.combine(hash, isDeprecated.hashCode); diff --git a/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart b/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart index 820f31e0377..d95c14d4e45 100644 --- a/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart +++ b/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart @@ -134,6 +134,7 @@ final Matcher isChangeContentOverlay = new LazyMatcher(() => * "relevance": int * "completion": String * "displayText": optional String + * "elementUri": optional String * "selectionOffset": int * "selectionLength": int * "isDeprecated": bool @@ -165,6 +166,7 @@ final Matcher isCompletionSuggestion = "isPotential": isBool }, optionalFields: { "displayText": isString, + "elementUri": isString, "docSummary": isString, "docComplete": isString, "declaringType": isString, diff --git a/pkg/analyzer_plugin/tool/spec/common_types_spec.html b/pkg/analyzer_plugin/tool/spec/common_types_spec.html index ed8daca55a3..d12b351dd53 100644 --- a/pkg/analyzer_plugin/tool/spec/common_types_spec.html +++ b/pkg/analyzer_plugin/tool/spec/common_types_spec.html @@ -206,6 +206,13 @@ completion. Otherwise it is omitted.

+ + String +

+ The URI of the element corresponding to this suggestion. It will be + set whenever analysis server is able to compute it. +

+
int