Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/dart/uri_contributor.dart

Issue 2342473002: improve import URI completions at EOF (Closed)
Patch Set: update tests Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/completion_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library services.completion.contributor.dart.importuri; 5 library services.completion.contributor.dart.importuri;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:core'; 8 import 'dart:core';
9 9
10 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart'; 10 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart';
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 @override 49 @override
50 visitImportDirective(ImportDirective node) { 50 visitImportDirective(ImportDirective node) {
51 visitNamespaceDirective(node); 51 visitNamespaceDirective(node);
52 } 52 }
53 53
54 visitNamespaceDirective(NamespaceDirective node) { 54 visitNamespaceDirective(NamespaceDirective node) {
55 StringLiteral uri = node.uri; 55 StringLiteral uri = node.uri;
56 if (uri is SimpleStringLiteral) { 56 if (uri is SimpleStringLiteral) {
57 int offset = request.offset; 57 int offset = request.offset;
58 if (uri.offset < offset && 58 int start = uri.offset;
59 (offset < uri.end || offset == uri.offset + 1)) { 59 int end = uri.end;
60 // Handle degenerate case where import or export is only line in file 60 if (offset > start) {
61 // and there is no semicolon 61 if (offset < end) {
62 visitSimpleStringLiteral(uri); 62 // Quoted non-empty string
63 visitSimpleStringLiteral(uri);
64 } else if (offset == end) {
65 if (end == start + 1) {
66 // Quoted empty string
67 visitSimpleStringLiteral(uri);
68 } else {
69 String data = request.source.contents.data;
70 if (end == data.length) {
71 String ch = data[end - 1];
72 if (ch != '"' && ch != "'") {
73 // Insertion point at end of file
74 // and missing closing quote on non-empty string
75 visitSimpleStringLiteral(uri);
76 }
77 }
78 }
79 }
80 }
81 else if (offset == start && offset == end) {
82 String data = request.source.contents.data;
83 if (end == data.length) {
84 String ch = data[end - 1];
85 if (ch == '"' || ch == "'") {
86 // Insertion point at end of file
87 // and missing closing quote on empty string
88 visitSimpleStringLiteral(uri);
89 }
90 }
63 } 91 }
64 } 92 }
65 } 93 }
66 94
67 @override 95 @override
68 visitSimpleStringLiteral(SimpleStringLiteral node) { 96 visitSimpleStringLiteral(SimpleStringLiteral node) {
69 AstNode parent = node.parent; 97 AstNode parent = node.parent;
70 if (parent is NamespaceDirective && parent.uri == node) { 98 if (parent is NamespaceDirective && parent.uri == node) {
71 String partialUri = _extractPartialUri(node); 99 String partialUri = _extractPartialUri(node);
72 if (partialUri != null) { 100 if (partialUri != null) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 215 }
188 216
189 String _extractPartialUri(SimpleStringLiteral node) { 217 String _extractPartialUri(SimpleStringLiteral node) {
190 if (request.offset < node.contentsOffset) { 218 if (request.offset < node.contentsOffset) {
191 return null; 219 return null;
192 } 220 }
193 return node.literal.lexeme.substring( 221 return node.literal.lexeme.substring(
194 node.contentsOffset - node.offset, request.offset - node.offset); 222 node.contentsOffset - node.offset, request.offset - node.offset);
195 } 223 }
196 } 224 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698