mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
show all available import completion suggestions - fixes #23955
R=brianwilkerson@google.com Review URL: https://codereview.chromium.org//1317023002 .
This commit is contained in:
parent
bd95b13b90
commit
c0fe214c47
2 changed files with 44 additions and 55 deletions
|
@ -5,7 +5,6 @@
|
|||
library services.completion.contributor.dart.importuri;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:core' hide Resource;
|
||||
|
||||
import 'package:analysis_server/src/services/completion/dart_completion_manager.dart';
|
||||
|
@ -39,7 +38,6 @@ class ImportUriContributor extends DartCompletionContributor {
|
|||
|
||||
class _ImportUriSuggestionBuilder extends SimpleAstVisitor {
|
||||
final DartCompletionRequest request;
|
||||
HashSet<String> _importedUris;
|
||||
|
||||
_ImportUriSuggestionBuilder(this.request);
|
||||
|
||||
|
@ -68,7 +66,6 @@ class _ImportUriSuggestionBuilder extends SimpleAstVisitor {
|
|||
if (parent is ImportDirective && parent.uri == node) {
|
||||
String partial = node.literal.lexeme.substring(
|
||||
node.contentsOffset - node.offset, request.offset - node.offset);
|
||||
_computeImportedUris();
|
||||
request.replacementOffset = node.contentsOffset;
|
||||
request.replacementLength = node.contentsEnd - node.contentsOffset;
|
||||
_addDartSuggestions();
|
||||
|
@ -77,7 +74,6 @@ class _ImportUriSuggestionBuilder extends SimpleAstVisitor {
|
|||
} else if (parent is PartDirective && parent.uri == node) {
|
||||
String partial = node.literal.lexeme.substring(
|
||||
node.contentsOffset - node.offset, request.offset - node.offset);
|
||||
_computeImportedUris();
|
||||
request.replacementOffset = node.contentsOffset;
|
||||
request.replacementLength = node.contentsEnd - node.contentsOffset;
|
||||
_addFileSuggestions(partial);
|
||||
|
@ -90,7 +86,10 @@ class _ImportUriSuggestionBuilder extends SimpleAstVisitor {
|
|||
for (SdkLibrary lib in factory.dartSdk.sdkLibraries) {
|
||||
if (!lib.isInternal && !lib.isImplementation) {
|
||||
if (!lib.shortName.startsWith('dart:_')) {
|
||||
_addSuggestion(lib.shortName);
|
||||
_addSuggestion(lib.shortName,
|
||||
relevance: lib.shortName == 'dart:core'
|
||||
? DART_RELEVANCE_LOW
|
||||
: DART_RELEVANCE_DEFAULT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,24 +159,15 @@ class _ImportUriSuggestionBuilder extends SimpleAstVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
void _addSuggestion(String completion) {
|
||||
if (!_importedUris.contains(completion)) {
|
||||
request.addSuggestion(new CompletionSuggestion(
|
||||
CompletionSuggestionKind.IMPORT, DART_RELEVANCE_DEFAULT, completion,
|
||||
completion.length, 0, false, false));
|
||||
}
|
||||
}
|
||||
|
||||
void _computeImportedUris() {
|
||||
_importedUris = new HashSet<String>();
|
||||
_importedUris.add('dart:core');
|
||||
for (Directive directive in request.unit.directives) {
|
||||
if (directive is ImportDirective) {
|
||||
String uri = directive.uriContent;
|
||||
if (uri != null && uri.length > 0) {
|
||||
_importedUris.add(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
void _addSuggestion(String completion,
|
||||
{int relevance: DART_RELEVANCE_DEFAULT}) {
|
||||
request.addSuggestion(new CompletionSuggestion(
|
||||
CompletionSuggestionKind.IMPORT,
|
||||
relevance,
|
||||
completion,
|
||||
completion.length,
|
||||
0,
|
||||
false,
|
||||
false));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import 'package:unittest/unittest.dart';
|
|||
|
||||
import '../../utils.dart';
|
||||
import 'completion_test_util.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart_completion_manager.dart';
|
||||
|
||||
main() {
|
||||
initializeTestEnvironment();
|
||||
|
@ -51,7 +52,8 @@ class ImportUriContributorTest extends AbstractCompletionTest {
|
|||
expect(request.replacementOffset, completionOffset - 1);
|
||||
expect(request.replacementLength, 1);
|
||||
assertSuggest('dart:', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('dart:core');
|
||||
assertSuggest('dart:core',
|
||||
csKind: CompletionSuggestionKind.IMPORT, relevance: DART_RELEVANCE_LOW);
|
||||
assertNotSuggested('dart:_internal');
|
||||
assertSuggest('dart:async', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertSuggest('dart:math', csKind: CompletionSuggestionKind.IMPORT);
|
||||
|
@ -63,9 +65,10 @@ class ImportUriContributorTest extends AbstractCompletionTest {
|
|||
expect(request.replacementOffset, completionOffset - 1);
|
||||
expect(request.replacementLength, 1);
|
||||
assertSuggest('dart:', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('dart:core');
|
||||
assertSuggest('dart:core',
|
||||
csKind: CompletionSuggestionKind.IMPORT, relevance: DART_RELEVANCE_LOW);
|
||||
assertNotSuggested('dart:_internal');
|
||||
assertNotSuggested('dart:async');
|
||||
assertSuggest('dart:async', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertSuggest('dart:math', csKind: CompletionSuggestionKind.IMPORT);
|
||||
}
|
||||
|
||||
|
@ -83,9 +86,9 @@ class ImportUriContributorTest extends AbstractCompletionTest {
|
|||
assertNotSuggested('completion.dart');
|
||||
assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo');
|
||||
assertSuggest('foo${separator}', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo${separator}bar.dart');
|
||||
assertNotSuggested('..${separator}blat.dart');
|
||||
assertSuggest('foo/', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo/bar.dart');
|
||||
assertNotSuggested('../blat.dart');
|
||||
}
|
||||
|
||||
test_import_file2() {
|
||||
|
@ -102,9 +105,9 @@ class ImportUriContributorTest extends AbstractCompletionTest {
|
|||
assertNotSuggested('completion.dart');
|
||||
assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo');
|
||||
assertSuggest('foo${separator}', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo${separator}bar.dart');
|
||||
assertNotSuggested('..${separator}blat.dart');
|
||||
assertSuggest('foo/', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo/bar.dart');
|
||||
assertNotSuggested('../blat.dart');
|
||||
}
|
||||
|
||||
test_import_file_child() {
|
||||
|
@ -121,10 +124,9 @@ class ImportUriContributorTest extends AbstractCompletionTest {
|
|||
assertNotSuggested('completion.dart');
|
||||
assertNotSuggested('other.dart');
|
||||
assertNotSuggested('foo');
|
||||
assertNotSuggested('foo${separator}');
|
||||
assertSuggest('foo${separator}bar.dart',
|
||||
csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('..${separator}blat.dart');
|
||||
assertNotSuggested('foo/');
|
||||
assertSuggest('foo/bar.dart', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('../blat.dart');
|
||||
}
|
||||
|
||||
test_import_file_parent() {
|
||||
|
@ -141,10 +143,9 @@ class ImportUriContributorTest extends AbstractCompletionTest {
|
|||
assertNotSuggested('completion.dart');
|
||||
assertNotSuggested('other.dart');
|
||||
assertNotSuggested('foo');
|
||||
assertNotSuggested('foo${separator}');
|
||||
assertNotSuggested('foo${separator}bar.dart');
|
||||
assertSuggest('..${separator}blat.dart',
|
||||
csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo/');
|
||||
assertNotSuggested('foo/bar.dart');
|
||||
assertSuggest('../blat.dart', csKind: CompletionSuggestionKind.IMPORT);
|
||||
}
|
||||
|
||||
test_import_package() {
|
||||
|
@ -218,9 +219,9 @@ class ImportUriContributorTest extends AbstractCompletionTest {
|
|||
assertNotSuggested('completion.dart');
|
||||
assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo');
|
||||
assertSuggest('foo${separator}', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo${separator}bar.dart');
|
||||
assertNotSuggested('..${separator}blat.dart');
|
||||
assertSuggest('foo/', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo/bar.dart');
|
||||
assertNotSuggested('../blat.dart');
|
||||
}
|
||||
|
||||
test_part_file2() {
|
||||
|
@ -237,9 +238,9 @@ class ImportUriContributorTest extends AbstractCompletionTest {
|
|||
assertNotSuggested('completion.dart');
|
||||
assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo');
|
||||
assertSuggest('foo${separator}', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo${separator}bar.dart');
|
||||
assertNotSuggested('..${separator}blat.dart');
|
||||
assertSuggest('foo/', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo/bar.dart');
|
||||
assertNotSuggested('../blat.dart');
|
||||
}
|
||||
|
||||
test_part_file_child() {
|
||||
|
@ -256,10 +257,9 @@ class ImportUriContributorTest extends AbstractCompletionTest {
|
|||
assertNotSuggested('completion.dart');
|
||||
assertNotSuggested('other.dart');
|
||||
assertNotSuggested('foo');
|
||||
assertNotSuggested('foo${separator}');
|
||||
assertSuggest('foo${separator}bar.dart',
|
||||
csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('..${separator}blat.dart');
|
||||
assertNotSuggested('foo/');
|
||||
assertSuggest('foo/bar.dart', csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('../blat.dart');
|
||||
}
|
||||
|
||||
test_part_file_parent() {
|
||||
|
@ -276,9 +276,8 @@ class ImportUriContributorTest extends AbstractCompletionTest {
|
|||
assertNotSuggested('completion.dart');
|
||||
assertNotSuggested('other.dart');
|
||||
assertNotSuggested('foo');
|
||||
assertNotSuggested('foo${separator}');
|
||||
assertNotSuggested('foo${separator}bar.dart');
|
||||
assertSuggest('..${separator}blat.dart',
|
||||
csKind: CompletionSuggestionKind.IMPORT);
|
||||
assertNotSuggested('foo/');
|
||||
assertNotSuggested('foo/bar.dart');
|
||||
assertSuggest('../blat.dart', csKind: CompletionSuggestionKind.IMPORT);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue