Add CompletionSuggestion.libraryUri, keep isNotImported.

Change-Id: I1bce246c2d8eaa968a47ae6ba82114592b991a47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231040
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2022-02-04 22:49:10 +00:00 committed by Commit Bot
parent 4eaacc3df9
commit 52290eba28
16 changed files with 254 additions and 225 deletions

View file

@ -36,7 +36,6 @@ Element convertElement(engine.Element element,
aliasedType: aliasedType,
parameters: elementParameters,
returnType: elementReturnType,
libraryUri: element.library?.source.uri.toString(),
);
}

View file

@ -206,7 +206,7 @@ class CiderCompletionComputer {
List<CompletionSuggestionBuilder> _librarySuggestions(
LibraryElement element) {
var suggestionBuilder = SuggestionBuilder(_dartCompletionRequest);
suggestionBuilder.libraryUri = element.source.uri;
suggestionBuilder.libraryUriStr = element.source.uri.toString();
var visitor = LibraryElementSuggestionBuilder(
_dartCompletionRequest, suggestionBuilder);
var exportMap = element.exportNamespace.definedNames;

View file

@ -7,6 +7,7 @@ import 'package:analysis_server/src/services/completion/dart/completion_manager.
import 'package:analysis_server/src/services/completion/dart/local_library_contributor.dart';
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart'
show SuggestionBuilder;
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/dart/resolver/scope.dart';
/// A contributor for calculating suggestions for imported top level members.
@ -27,8 +28,11 @@ class ImportedReferenceContributor extends DartCompletionContributor {
for (var importElement in imports) {
var libraryElement = importElement.importedLibrary;
if (libraryElement != null) {
_buildSuggestions(importElement.namespace,
prefix: importElement.prefix?.name);
_buildSuggestions(
libraryElement: libraryElement,
namespace: importElement.namespace,
prefix: importElement.prefix?.name,
);
if (libraryElement.isDartCore &&
request.opType.includeTypeNameSuggestions) {
builder.suggestName('Never');
@ -37,10 +41,16 @@ class ImportedReferenceContributor extends DartCompletionContributor {
}
}
void _buildSuggestions(Namespace namespace, {String? prefix}) {
void _buildSuggestions({
required LibraryElement libraryElement,
required Namespace namespace,
String? prefix,
}) {
builder.libraryUriStr = libraryElement.source.uri.toString();
var visitor = LibraryElementSuggestionBuilder(request, builder, prefix);
for (var elem in namespace.definedNames.values) {
elem.accept(visitor);
}
builder.libraryUriStr = null;
}
}

View file

@ -41,6 +41,7 @@ class LibraryMemberContributor extends DartCompletionContributor {
if (importElem.prefix?.name == elem.name) {
var library = importElem.importedLibrary;
if (library != null) {
builder.libraryUriStr = library.source.uri.toString();
for (var element in importElem.namespace.definedNames.values) {
if (typesOnly && isConstructor) {
// Suggest constructors from the imported libraries.
@ -72,6 +73,7 @@ class LibraryMemberContributor extends DartCompletionContributor {
if (!typesOnly && importElem.isDeferred) {
builder.suggestLoadLibraryFunction(library.loadLibraryFunction);
}
builder.libraryUriStr = null;
}
}
}

View file

@ -81,6 +81,7 @@ class NotImportedContributor extends DartCompletionContributor {
var exportNamespace = element.exportNamespace;
var exportElements = exportNamespace.definedNames.values.toList();
builder.libraryUriStr = file.uriStr;
builder.isNotImportedLibrary = true;
builder.laterReplacesEarlier = false;
@ -92,6 +93,7 @@ class NotImportedContributor extends DartCompletionContributor {
_extensions(exportElements),
);
builder.libraryUriStr = null;
builder.isNotImportedLibrary = false;
builder.laterReplacesEarlier = true;
}

View file

@ -56,7 +56,7 @@ class CompletionSuggestionBuilderImpl implements CompletionSuggestionBuilder {
final int relevance;
final String? completionOverride;
final Uri? libraryUri;
final String? libraryUriStr;
final bool isNotImported;
CompletionSuggestionBuilderImpl({
@ -64,7 +64,7 @@ class CompletionSuggestionBuilderImpl implements CompletionSuggestionBuilder {
required this.kind,
required this.completionOverride,
required this.relevance,
required this.libraryUri,
required this.libraryUriStr,
required this.isNotImported,
});
@ -102,21 +102,12 @@ class CompletionSuggestionBuilderImpl implements CompletionSuggestionBuilder {
parameterTypes: element.parameterTypes,
defaultArgumentListString: element.defaultArgumentList?.text,
defaultArgumentListTextRanges: element.defaultArgumentList?.ranges,
isNotImported: isNotImported,
libraryUri: libraryUriStr,
isNotImported: isNotImported ? true : null,
);
}
}
/// Wrapper around a potentially nullable value.
///
/// When the wrapper instance is provided for a property, the property
/// value is replaced, even if the value to set is `null` itself.
class CopyWithValue<T> {
final T value;
CopyWithValue(this.value);
}
/// Information about an [Element] that does not depend on the location where
/// this element is suggested. For some often used elements, such as classes,
/// it might be cached, so created only once.
@ -277,7 +268,7 @@ class SuggestionBuilder {
/// The URI of the library from which suggestions are being added.
/// This URI is not necessary the same as the URI that declares an element,
/// because of exports.
Uri? libraryUri;
String? libraryUriStr;
/// This flag is set to `true` while adding suggestions for top-level
/// elements from not-yet-imported libraries.
@ -1319,7 +1310,7 @@ class SuggestionBuilder {
kind: kind,
completionOverride: completion,
relevance: relevance,
libraryUri: libraryUri,
libraryUriStr: libraryUriStr,
isNotImported: isNotImported,
);
}
@ -1596,44 +1587,3 @@ extension on Object? {
return self is T ? self : null;
}
}
extension CompletionSuggestionExtension on CompletionSuggestion {
CompletionSuggestion copyWith({
CopyWithValue<bool?>? isNotImported,
CopyWithValue<int>? relevance,
}) {
return protocol.CompletionSuggestion(
kind,
relevance.orElse(this.relevance),
completion,
selectionOffset,
selectionLength,
isDeprecated,
isPotential,
displayText: displayText,
replacementOffset: replacementOffset,
replacementLength: replacementLength,
docSummary: docSummary,
docComplete: docComplete,
declaringType: declaringType,
defaultArgumentListString: defaultArgumentListString,
defaultArgumentListTextRanges: defaultArgumentListTextRanges,
element: element,
returnType: returnType,
parameterNames: parameterNames,
parameterTypes: parameterTypes,
requiredParameterCount: requiredParameterCount,
hasNamedParameters: hasNamedParameters,
parameterName: parameterName,
parameterType: parameterType,
isNotImported: isNotImported.orElse(this.isNotImported),
);
}
}
extension _CopyWithValueExtension<T> on CopyWithValue<T>? {
T orElse(T defaultValue) {
final self = this;
return self != null ? self.value : defaultValue;
}
}

View file

@ -1162,10 +1162,14 @@ void f(A a) {
check(response).suggestions.matches([
(suggestion) => suggestion
..completion.isEqualTo('foo01')
..isGetter,
..isGetter
..libraryUri.isNull
..isNotImported.isNull,
(suggestion) => suggestion
..completion.isEqualTo('foo02')
..isGetter,
..isGetter
..libraryUri.isNull
..isNotImported.isNull,
]);
}
@ -1609,6 +1613,29 @@ void f() {
]);
}
Future<void> test_prefixed_importPrefix_class() async {
await _configureWithWorkspaceRoot();
var response = await _getTestCodeSuggestions('''
import 'dart:math' as math;
void f() {
math.Rand^
}
''');
check(response)
..assertComplete()
..hasReplacement(left: 4);
check(response).suggestions.withElementClass.matches([
(suggestion) => suggestion
..completion.isEqualTo('Random')
..libraryUri.isEqualTo('dart:math')
..isNotImported.isNull,
]);
}
Future<void> test_unprefixed_filters() async {
await _configureWithWorkspaceRoot();
@ -1664,10 +1691,14 @@ void f() {
check(response).suggestions.withElementClass.matches([
(suggestion) => suggestion
..completion.isEqualTo('A01')
..isClass,
..isClass
..libraryUri.isEqualTo('package:test/a.dart')
..isNotImported.isNull,
(suggestion) => suggestion
..completion.isEqualTo('A02')
..isClass,
..isClass
..libraryUri.isEqualTo('package:test/b.dart')
..isNotImported.isNull,
]);
}
@ -1698,10 +1729,14 @@ void f() {
check(response).suggestions.matches([
(suggestion) => suggestion
..completion.isEqualTo('foo01')
..isTopLevelVariable,
..isTopLevelVariable
..libraryUri.isEqualTo('package:test/a.dart')
..isNotImported.isNull,
(suggestion) => suggestion
..completion.isEqualTo('foo02')
..isTopLevelVariable,
..isTopLevelVariable
..libraryUri.isEqualTo('package:test/b.dart')
..isNotImported.isNull,
]);
}
@ -1724,7 +1759,8 @@ void f() {
check(response).suggestions.withElementClass.matches([
(suggestion) => suggestion
..completion.isEqualTo('math.Random')
..libraryUriToImport.isNull,
..libraryUri.isEqualTo('dart:math')
..isNotImported.isNull,
]);
}

View file

@ -305,6 +305,7 @@ final Matcher isCompletionSuggestion =
'hasNamedParameters': isBool,
'parameterName': isString,
'parameterType': isString,
'libraryUri': isString,
'isNotImported': isBool
}));
@ -384,8 +385,7 @@ final Matcher isElement = LazyMatcher(() => MatchesJsonObject('Element', {
'parameters': isString,
'returnType': isString,
'typeParameters': isString,
'aliasedType': isString,
'libraryUri': isString
'aliasedType': isString
}));
/// ElementDeclaration

View file

@ -64,8 +64,7 @@ class B extends A {
'kind': 'CLASS',
'name': 'B',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -77,8 +76,7 @@ class B extends A {
'kind': 'CLASS',
'name': 'A',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 0,
'interfaces': [],
@ -118,8 +116,7 @@ class CCC extends BBB implements AAA {}
'kind': 'CLASS',
'name': 'AAA',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -131,8 +128,7 @@ class CCC extends BBB implements AAA {}
'kind': 'CLASS',
'name': 'Object',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'interfaces': [],
'mixins': [],
@ -143,8 +139,7 @@ class CCC extends BBB implements AAA {}
'kind': 'CLASS',
'name': 'BBB',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 0,
'interfaces': [],
@ -156,8 +151,7 @@ class CCC extends BBB implements AAA {}
'kind': 'CLASS',
'name': 'CCC',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 0,
'interfaces': [],
@ -210,8 +204,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'A',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -223,8 +216,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'Object',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'interfaces': [],
'mixins': [],
@ -235,8 +227,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'B',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 0,
'interfaces': [],
@ -248,8 +239,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'C',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 2,
'interfaces': [],
@ -275,8 +265,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'B',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -288,8 +277,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'A',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 2,
'interfaces': [],
@ -301,8 +289,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'Object',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'interfaces': [],
'mixins': [],
@ -313,8 +300,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'C',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 0,
'interfaces': [],
@ -340,8 +326,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'C',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -353,8 +338,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'B',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 2,
'interfaces': [],
@ -366,8 +350,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'A',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 3,
'interfaces': [],
@ -379,8 +362,7 @@ class C extends B {
'kind': 'CLASS',
'name': 'Object',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'interfaces': [],
'mixins': [],
@ -405,8 +387,7 @@ class T implements MA, MB {
'kind': 'CLASS',
'name': 'T',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [2, 3],
@ -418,8 +399,7 @@ class T implements MA, MB {
'kind': 'CLASS',
'name': 'Object',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'interfaces': [],
'mixins': [],
@ -430,8 +410,7 @@ class T implements MA, MB {
'kind': 'CLASS',
'name': 'MA',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -443,8 +422,7 @@ class T implements MA, MB {
'kind': 'CLASS',
'name': 'MB',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -471,8 +449,7 @@ class E extends A {}
'kind': 'CLASS',
'name': 'A',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -484,8 +461,7 @@ class E extends A {}
'kind': 'CLASS',
'name': 'Object',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'interfaces': [],
'mixins': [],
@ -496,8 +472,7 @@ class E extends A {}
'kind': 'CLASS',
'name': 'B',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 0,
'interfaces': [],
@ -509,8 +484,7 @@ class E extends A {}
'kind': 'CLASS',
'name': 'C',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 0,
'interfaces': [],
@ -522,8 +496,7 @@ class E extends A {}
'kind': 'CLASS',
'name': 'D',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 0,
'interfaces': [],
@ -535,8 +508,7 @@ class E extends A {}
'kind': 'CLASS',
'name': 'E',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 0,
'interfaces': [],
@ -548,8 +520,7 @@ class E extends A {}
'kind': 'CLASS',
'name': 'F',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 4,
'interfaces': [],
@ -561,8 +532,7 @@ class E extends A {}
'kind': 'CLASS',
'name': 'G',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 4,
'interfaces': [],
@ -588,8 +558,7 @@ class T extends Object with MA, MB {
'kind': 'CLASS',
'name': 'T',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -601,8 +570,7 @@ class T extends Object with MA, MB {
'kind': 'CLASS',
'name': 'Object',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'interfaces': [],
'mixins': [],
@ -613,8 +581,7 @@ class T extends Object with MA, MB {
'kind': 'CLASS',
'name': 'MA',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -626,8 +593,7 @@ class T extends Object with MA, MB {
'kind': 'CLASS',
'name': 'MB',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [],
@ -1167,8 +1133,7 @@ class D extends C {}
'kind': 'CLASS',
'name': 'C',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 1,
'interfaces': [3],
@ -1180,8 +1145,7 @@ class D extends C {}
'kind': 'CLASS',
'name': 'A',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 2,
'interfaces': [],
@ -1193,8 +1157,7 @@ class D extends C {}
'kind': 'CLASS',
'name': 'Object',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'interfaces': [],
'mixins': [],
@ -1205,8 +1168,7 @@ class D extends C {}
'kind': 'CLASS',
'name': 'B',
'location': anything,
'flags': 0,
'libraryUri': anything
'flags': 0
},
'superclass': 2,
'interfaces': [],

View file

@ -250,11 +250,19 @@ extension CompletionSuggestionExtension
);
}
@useResult
CheckTarget<String?> get libraryUri {
return nest(
value.suggestion.libraryUri,
(selected) => 'has libraryUri ${valueStr(selected)}',
);
}
@useResult
CheckTarget<String?> get libraryUriToImport {
return nest(
value.suggestion.isNotImported == true
? value.suggestion.element?.libraryUri
? value.suggestion.libraryUri
: null,
(selected) => 'has libraryUriToImport ${valueStr(selected)}',
);

View file

@ -175,6 +175,21 @@ public class CompletionSuggestion {
*/
private final String parameterType;
/**
* This field is omitted if getSuggestions was used rather than getSuggestions2.
*
* This field is omitted if this suggestion corresponds to a locally declared element.
*
* If this suggestion corresponds to an already imported element, then this field is the URI of a
* library that provides this element, not the URI of the library where the element is declared.
*
* If this suggestion corresponds to an element from a not yet imported library, this field is the
* URI of a library that could be imported to make this suggestion accessible in the file where
* completion was requested, such as package:foo/bar.dart or
* file:///home/me/workspace/foo/test/bar_test.dart.
*/
private final String libraryUri;
/**
* True if the suggestion is for an element from a not yet imported library. This field is omitted
* if the element is declared locally, or is from library is already imported, so that the
@ -185,7 +200,7 @@ public class CompletionSuggestion {
/**
* Constructor for {@link CompletionSuggestion}.
*/
public CompletionSuggestion(String kind, int relevance, String completion, String displayText, Integer replacementOffset, Integer replacementLength, int selectionOffset, int selectionLength, boolean isDeprecated, boolean isPotential, String docSummary, String docComplete, String declaringType, String defaultArgumentListString, int[] defaultArgumentListTextRanges, Element element, String returnType, List<String> parameterNames, List<String> parameterTypes, Integer requiredParameterCount, Boolean hasNamedParameters, String parameterName, String parameterType, Boolean isNotImported) {
public CompletionSuggestion(String kind, int relevance, String completion, String displayText, Integer replacementOffset, Integer replacementLength, int selectionOffset, int selectionLength, boolean isDeprecated, boolean isPotential, String docSummary, String docComplete, String declaringType, String defaultArgumentListString, int[] defaultArgumentListTextRanges, Element element, String returnType, List<String> parameterNames, List<String> parameterTypes, Integer requiredParameterCount, Boolean hasNamedParameters, String parameterName, String parameterType, String libraryUri, Boolean isNotImported) {
this.kind = kind;
this.relevance = relevance;
this.completion = completion;
@ -209,6 +224,7 @@ public class CompletionSuggestion {
this.hasNamedParameters = hasNamedParameters;
this.parameterName = parameterName;
this.parameterType = parameterType;
this.libraryUri = libraryUri;
this.isNotImported = isNotImported;
}
@ -240,6 +256,7 @@ public class CompletionSuggestion {
ObjectUtilities.equals(other.hasNamedParameters, hasNamedParameters) &&
ObjectUtilities.equals(other.parameterName, parameterName) &&
ObjectUtilities.equals(other.parameterType, parameterType) &&
ObjectUtilities.equals(other.libraryUri, libraryUri) &&
ObjectUtilities.equals(other.isNotImported, isNotImported);
}
return false;
@ -269,8 +286,9 @@ public class CompletionSuggestion {
Boolean hasNamedParameters = jsonObject.get("hasNamedParameters") == null ? null : jsonObject.get("hasNamedParameters").getAsBoolean();
String parameterName = jsonObject.get("parameterName") == null ? null : jsonObject.get("parameterName").getAsString();
String parameterType = jsonObject.get("parameterType") == null ? null : jsonObject.get("parameterType").getAsString();
String libraryUri = jsonObject.get("libraryUri") == null ? null : jsonObject.get("libraryUri").getAsString();
Boolean isNotImported = jsonObject.get("isNotImported") == null ? null : jsonObject.get("isNotImported").getAsBoolean();
return new CompletionSuggestion(kind, relevance, completion, displayText, replacementOffset, replacementLength, selectionOffset, selectionLength, isDeprecated, isPotential, docSummary, docComplete, declaringType, defaultArgumentListString, defaultArgumentListTextRanges, element, returnType, parameterNames, parameterTypes, requiredParameterCount, hasNamedParameters, parameterName, parameterType, isNotImported);
return new CompletionSuggestion(kind, relevance, completion, displayText, replacementOffset, replacementLength, selectionOffset, selectionLength, isDeprecated, isPotential, docSummary, docComplete, declaringType, defaultArgumentListString, defaultArgumentListTextRanges, element, returnType, parameterNames, parameterTypes, requiredParameterCount, hasNamedParameters, parameterName, parameterType, libraryUri, isNotImported);
}
public static List<CompletionSuggestion> fromJsonArray(JsonArray jsonArray) {
@ -390,6 +408,23 @@ public class CompletionSuggestion {
return kind;
}
/**
* This field is omitted if getSuggestions was used rather than getSuggestions2.
*
* This field is omitted if this suggestion corresponds to a locally declared element.
*
* If this suggestion corresponds to an already imported element, then this field is the URI of a
* library that provides this element, not the URI of the library where the element is declared.
*
* If this suggestion corresponds to an element from a not yet imported library, this field is the
* URI of a library that could be imported to make this suggestion accessible in the file where
* completion was requested, such as package:foo/bar.dart or
* file:///home/me/workspace/foo/test/bar_test.dart.
*/
public String getLibraryUri() {
return libraryUri;
}
/**
* The name of the optional parameter being suggested. This field is omitted if the suggestion is
* not the addition of an optional argument within an argument list.
@ -505,6 +540,7 @@ public class CompletionSuggestion {
builder.append(hasNamedParameters);
builder.append(parameterName);
builder.append(parameterType);
builder.append(libraryUri);
builder.append(isNotImported);
return builder.toHashCode();
}
@ -578,6 +614,9 @@ public class CompletionSuggestion {
if (parameterType != null) {
jsonObject.addProperty("parameterType", parameterType);
}
if (libraryUri != null) {
jsonObject.addProperty("libraryUri", libraryUri);
}
if (isNotImported != null) {
jsonObject.addProperty("isNotImported", isNotImported);
}
@ -634,6 +673,8 @@ public class CompletionSuggestion {
builder.append(parameterName + ", ");
builder.append("parameterType=");
builder.append(parameterType + ", ");
builder.append("libraryUri=");
builder.append(libraryUri + ", ");
builder.append("isNotImported=");
builder.append(isNotImported);
builder.append("]");

View file

@ -100,16 +100,10 @@ public class Element {
*/
private final String aliasedType;
/**
* If the element belongs to a library, the URI of the library. Otherwise, this field will not be
* defined.
*/
private final String libraryUri;
/**
* Constructor for {@link Element}.
*/
public Element(String kind, String name, Location location, int flags, String parameters, String returnType, String typeParameters, String aliasedType, String libraryUri) {
public Element(String kind, String name, Location location, int flags, String parameters, String returnType, String typeParameters, String aliasedType) {
this.kind = kind;
this.name = name;
this.location = location;
@ -118,7 +112,6 @@ public class Element {
this.returnType = returnType;
this.typeParameters = typeParameters;
this.aliasedType = aliasedType;
this.libraryUri = libraryUri;
}
@Override
@ -133,8 +126,7 @@ public class Element {
ObjectUtilities.equals(other.parameters, parameters) &&
ObjectUtilities.equals(other.returnType, returnType) &&
ObjectUtilities.equals(other.typeParameters, typeParameters) &&
ObjectUtilities.equals(other.aliasedType, aliasedType) &&
ObjectUtilities.equals(other.libraryUri, libraryUri);
ObjectUtilities.equals(other.aliasedType, aliasedType);
}
return false;
}
@ -148,8 +140,7 @@ public class Element {
String returnType = jsonObject.get("returnType") == null ? null : jsonObject.get("returnType").getAsString();
String typeParameters = jsonObject.get("typeParameters") == null ? null : jsonObject.get("typeParameters").getAsString();
String aliasedType = jsonObject.get("aliasedType") == null ? null : jsonObject.get("aliasedType").getAsString();
String libraryUri = jsonObject.get("libraryUri") == null ? null : jsonObject.get("libraryUri").getAsString();
return new Element(kind, name, location, flags, parameters, returnType, typeParameters, aliasedType, libraryUri);
return new Element(kind, name, location, flags, parameters, returnType, typeParameters, aliasedType);
}
public static List<Element> fromJsonArray(JsonArray jsonArray) {
@ -193,14 +184,6 @@ public class Element {
return kind;
}
/**
* If the element belongs to a library, the URI of the library. Otherwise, this field will not be
* defined.
*/
public String getLibraryUri() {
return libraryUri;
}
/**
* The location of the name in the declaration of the element.
*/
@ -252,7 +235,6 @@ public class Element {
builder.append(returnType);
builder.append(typeParameters);
builder.append(aliasedType);
builder.append(libraryUri);
return builder.toHashCode();
}
@ -300,9 +282,6 @@ public class Element {
if (aliasedType != null) {
jsonObject.addProperty("aliasedType", aliasedType);
}
if (libraryUri != null) {
jsonObject.addProperty("libraryUri", libraryUri);
}
return jsonObject;
}
@ -325,9 +304,7 @@ public class Element {
builder.append("typeParameters=");
builder.append(typeParameters + ", ");
builder.append("aliasedType=");
builder.append(aliasedType + ", ");
builder.append("libraryUri=");
builder.append(libraryUri);
builder.append(aliasedType);
builder.append("]");
return builder.toString();
}

View file

@ -612,6 +612,23 @@ class CompletionSuggestion implements HasToJson {
/// if the parameterName field is omitted.
String? parameterType;
/// This field is omitted if getSuggestions was used rather than
/// getSuggestions2.
///
/// This field is omitted if this suggestion corresponds to a locally
/// declared element.
///
/// If this suggestion corresponds to an already imported element, then this
/// field is the URI of a library that provides this element, not the URI of
/// the library where the element is declared.
///
/// If this suggestion corresponds to an element from a not yet imported
/// library, this field is the URI of a library that could be imported to
/// make this suggestion accessible in the file where completion was
/// requested, such as package:foo/bar.dart or
/// file:///home/me/workspace/foo/test/bar_test.dart.
String? libraryUri;
/// True if the suggestion is for an element from a not yet imported library.
/// This field is omitted if the element is declared locally, or is from
/// library is already imported, so that the suggestion can be inserted as
@ -642,6 +659,7 @@ class CompletionSuggestion implements HasToJson {
this.hasNamedParameters,
this.parameterName,
this.parameterType,
this.libraryUri,
this.isNotImported});
factory CompletionSuggestion.fromJson(
@ -781,6 +799,11 @@ class CompletionSuggestion implements HasToJson {
parameterType = jsonDecoder.decodeString(
jsonPath + '.parameterType', json['parameterType']);
}
String? libraryUri;
if (json.containsKey('libraryUri')) {
libraryUri = jsonDecoder.decodeString(
jsonPath + '.libraryUri', json['libraryUri']);
}
bool? isNotImported;
if (json.containsKey('isNotImported')) {
isNotImported = jsonDecoder.decodeBool(
@ -804,6 +827,7 @@ class CompletionSuggestion implements HasToJson {
hasNamedParameters: hasNamedParameters,
parameterName: parameterName,
parameterType: parameterType,
libraryUri: libraryUri,
isNotImported: isNotImported);
} else {
throw jsonDecoder.mismatch(jsonPath, 'CompletionSuggestion', json);
@ -884,6 +908,10 @@ class CompletionSuggestion implements HasToJson {
if (parameterType != null) {
result['parameterType'] = parameterType;
}
var libraryUri = this.libraryUri;
if (libraryUri != null) {
result['libraryUri'] = libraryUri;
}
var isNotImported = this.isNotImported;
if (isNotImported != null) {
result['isNotImported'] = isNotImported;
@ -923,6 +951,7 @@ class CompletionSuggestion implements HasToJson {
hasNamedParameters == other.hasNamedParameters &&
parameterName == other.parameterName &&
parameterType == other.parameterType &&
libraryUri == other.libraryUri &&
isNotImported == other.isNotImported;
}
return false;
@ -953,6 +982,7 @@ class CompletionSuggestion implements HasToJson {
hasNamedParameters,
parameterName,
parameterType,
libraryUri,
isNotImported,
]);
}
@ -1234,17 +1264,12 @@ class Element implements HasToJson {
/// this field will not be defined.
String? aliasedType;
/// If the element belongs to a library, the URI of the library. Otherwise,
/// this field will not be defined.
String? libraryUri;
Element(this.kind, this.name, this.flags,
{this.location,
this.parameters,
this.returnType,
this.typeParameters,
this.aliasedType,
this.libraryUri});
this.aliasedType});
factory Element.fromJson(
JsonDecoder jsonDecoder, String jsonPath, Object? json) {
@ -1294,18 +1319,12 @@ class Element implements HasToJson {
aliasedType = jsonDecoder.decodeString(
jsonPath + '.aliasedType', json['aliasedType']);
}
String? libraryUri;
if (json.containsKey('libraryUri')) {
libraryUri = jsonDecoder.decodeString(
jsonPath + '.libraryUri', json['libraryUri']);
}
return Element(kind, name, flags,
location: location,
parameters: parameters,
returnType: returnType,
typeParameters: typeParameters,
aliasedType: aliasedType,
libraryUri: libraryUri);
aliasedType: aliasedType);
} else {
throw jsonDecoder.mismatch(jsonPath, 'Element', json);
}
@ -1344,10 +1363,6 @@ class Element implements HasToJson {
if (aliasedType != null) {
result['aliasedType'] = aliasedType;
}
var libraryUri = this.libraryUri;
if (libraryUri != null) {
result['libraryUri'] = libraryUri;
}
return result;
}
@ -1364,8 +1379,7 @@ class Element implements HasToJson {
parameters == other.parameters &&
returnType == other.returnType &&
typeParameters == other.typeParameters &&
aliasedType == other.aliasedType &&
libraryUri == other.libraryUri;
aliasedType == other.aliasedType;
}
return false;
}
@ -1380,7 +1394,6 @@ class Element implements HasToJson {
returnType,
typeParameters,
aliasedType,
libraryUri,
);
}

View file

@ -612,6 +612,23 @@ class CompletionSuggestion implements HasToJson {
/// if the parameterName field is omitted.
String? parameterType;
/// This field is omitted if getSuggestions was used rather than
/// getSuggestions2.
///
/// This field is omitted if this suggestion corresponds to a locally
/// declared element.
///
/// If this suggestion corresponds to an already imported element, then this
/// field is the URI of a library that provides this element, not the URI of
/// the library where the element is declared.
///
/// If this suggestion corresponds to an element from a not yet imported
/// library, this field is the URI of a library that could be imported to
/// make this suggestion accessible in the file where completion was
/// requested, such as package:foo/bar.dart or
/// file:///home/me/workspace/foo/test/bar_test.dart.
String? libraryUri;
/// True if the suggestion is for an element from a not yet imported library.
/// This field is omitted if the element is declared locally, or is from
/// library is already imported, so that the suggestion can be inserted as
@ -642,6 +659,7 @@ class CompletionSuggestion implements HasToJson {
this.hasNamedParameters,
this.parameterName,
this.parameterType,
this.libraryUri,
this.isNotImported});
factory CompletionSuggestion.fromJson(
@ -781,6 +799,11 @@ class CompletionSuggestion implements HasToJson {
parameterType = jsonDecoder.decodeString(
jsonPath + '.parameterType', json['parameterType']);
}
String? libraryUri;
if (json.containsKey('libraryUri')) {
libraryUri = jsonDecoder.decodeString(
jsonPath + '.libraryUri', json['libraryUri']);
}
bool? isNotImported;
if (json.containsKey('isNotImported')) {
isNotImported = jsonDecoder.decodeBool(
@ -804,6 +827,7 @@ class CompletionSuggestion implements HasToJson {
hasNamedParameters: hasNamedParameters,
parameterName: parameterName,
parameterType: parameterType,
libraryUri: libraryUri,
isNotImported: isNotImported);
} else {
throw jsonDecoder.mismatch(jsonPath, 'CompletionSuggestion', json);
@ -884,6 +908,10 @@ class CompletionSuggestion implements HasToJson {
if (parameterType != null) {
result['parameterType'] = parameterType;
}
var libraryUri = this.libraryUri;
if (libraryUri != null) {
result['libraryUri'] = libraryUri;
}
var isNotImported = this.isNotImported;
if (isNotImported != null) {
result['isNotImported'] = isNotImported;
@ -923,6 +951,7 @@ class CompletionSuggestion implements HasToJson {
hasNamedParameters == other.hasNamedParameters &&
parameterName == other.parameterName &&
parameterType == other.parameterType &&
libraryUri == other.libraryUri &&
isNotImported == other.isNotImported;
}
return false;
@ -953,6 +982,7 @@ class CompletionSuggestion implements HasToJson {
hasNamedParameters,
parameterName,
parameterType,
libraryUri,
isNotImported,
]);
}
@ -1234,17 +1264,12 @@ class Element implements HasToJson {
/// this field will not be defined.
String? aliasedType;
/// If the element belongs to a library, the URI of the library. Otherwise,
/// this field will not be defined.
String? libraryUri;
Element(this.kind, this.name, this.flags,
{this.location,
this.parameters,
this.returnType,
this.typeParameters,
this.aliasedType,
this.libraryUri});
this.aliasedType});
factory Element.fromJson(
JsonDecoder jsonDecoder, String jsonPath, Object? json) {
@ -1294,18 +1319,12 @@ class Element implements HasToJson {
aliasedType = jsonDecoder.decodeString(
jsonPath + '.aliasedType', json['aliasedType']);
}
String? libraryUri;
if (json.containsKey('libraryUri')) {
libraryUri = jsonDecoder.decodeString(
jsonPath + '.libraryUri', json['libraryUri']);
}
return Element(kind, name, flags,
location: location,
parameters: parameters,
returnType: returnType,
typeParameters: typeParameters,
aliasedType: aliasedType,
libraryUri: libraryUri);
aliasedType: aliasedType);
} else {
throw jsonDecoder.mismatch(jsonPath, 'Element', json);
}
@ -1344,10 +1363,6 @@ class Element implements HasToJson {
if (aliasedType != null) {
result['aliasedType'] = aliasedType;
}
var libraryUri = this.libraryUri;
if (libraryUri != null) {
result['libraryUri'] = libraryUri;
}
return result;
}
@ -1364,8 +1379,7 @@ class Element implements HasToJson {
parameters == other.parameters &&
returnType == other.returnType &&
typeParameters == other.typeParameters &&
aliasedType == other.aliasedType &&
libraryUri == other.libraryUri;
aliasedType == other.aliasedType;
}
return false;
}
@ -1380,7 +1394,6 @@ class Element implements HasToJson {
returnType,
typeParameters,
aliasedType,
libraryUri,
);
}

View file

@ -165,6 +165,7 @@ final Matcher isCompletionSuggestion =
'hasNamedParameters': isBool,
'parameterName': isString,
'parameterType': isString,
'libraryUri': isString,
'isNotImported': isBool
}));
@ -237,8 +238,7 @@ final Matcher isElement = LazyMatcher(() => MatchesJsonObject('Element', {
'parameters': isString,
'returnType': isString,
'typeParameters': isString,
'aliasedType': isString,
'libraryUri': isString
'aliasedType': isString
}));
/// ElementKind

View file

@ -380,6 +380,29 @@
omitted if the parameterName field is omitted.
</p>
</field>
<field name="libraryUri" experimental="true" optional="true">
<ref>String</ref>
<p>
This field is omitted if <tt>getSuggestions</tt> was used rather
than <tt>getSuggestions2</tt>.
</p>
<p>
This field is omitted if this suggestion corresponds to a locally
declared element.
</p>
<p>
If this suggestion corresponds to an already imported element,
then this field is the URI of a library that provides this element,
not the URI of the library where the element is declared.
</p>
<p>
If this suggestion corresponds to an element from a not yet
imported library, this field is the URI of a library that could be
imported to make this suggestion accessible in the file where
completion was requested, such as <tt>package:foo/bar.dart</tt> or
<tt>file:///home/me/workspace/foo/test/bar_test.dart</tt>.
</p>
</field>
<field name="isNotImported" optional="true" experimental="true">
<ref>bool</ref>
<p>
@ -563,13 +586,6 @@
Otherwise this field will not be defined.
</p>
</field>
<field name="libraryUri" optional="true" experimental="true">
<ref>String</ref>
<p>
If the element belongs to a library, the URI of the library.
Otherwise, this field will not be defined.
</p>
</field>
</object>
</type>
<type name="ElementKind">