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

Unified Diff: pkg/analysis_server/lib/src/services/completion/completion_target.dart

Issue 985183003: fix completion target handling of comments (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/completion_target_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/completion/completion_target.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/completion_target.dart b/pkg/analysis_server/lib/src/services/completion/completion_target.dart
index 47b88638e53acacc874321dda76f6d23a58a3040..7c7badc5759bd32a6437f6cc058a7919cbd2ea26 100644
--- a/pkg/analysis_server/lib/src/services/completion/completion_target.dart
+++ b/pkg/analysis_server/lib/src/services/completion/completion_target.dart
@@ -156,6 +156,18 @@ class CompletionTarget {
// If the node is a candidate target, then we are done.
if (_isCandidateNode(entity, offset)) {
+ // Check to see if the offset is in a preceeding comment
+ Token commentToken = _getContainingCommentToken(entity, offset);
+ if (commentToken != null) {
+ entity = commentToken;
+ // If the preceeding comment is dartdoc token then update
+ // the containing node to be the dartdoc comment
+ Comment docComment =
+ _getContainingDocComment(containingNode, commentToken);
+ if (docComment != null) {
+ containingNode = docComment;
+ }
+ }
return new CompletionTarget._(containingNode, entity);
}
@@ -234,6 +246,46 @@ class CompletionTarget {
}
/**
+ * Determine if the offset is contained in a preceeding comment token
+ * and return that token, otherwise return `null`.
+ */
+ static Token _getContainingCommentToken(AstNode node, int offset) {
+ if (offset >= node.offset) {
+ return null;
+ }
+ Token token = node.beginToken;
+ if (token == null) {
+ return null;
+ }
+ token = token.precedingComments;
+ while (token != null) {
+ if (offset <= token.offset) {
+ return null;
+ }
+ if (offset <= token.end) {
+ if (token.type == TokenType.SINGLE_LINE_COMMENT || offset < token.end) {
+ return token;
+ }
+ }
+ token = token.next;
+ }
+ return null;
+ }
+
+ /**
+ * Determine if the given token is part of the given node's dart doc.
+ */
+ static Comment _getContainingDocComment(AstNode node, Token token) {
+ if (node is AnnotatedNode) {
+ Comment docComment = node.documentationComment;
+ if (docComment != null && docComment.tokens.contains(token)) {
+ return docComment;
+ }
+ }
+ return null;
+ }
+
+ /**
* Determine whether [node] could possibly be the [entity] for a
* [CompletionTarget] associated with the given [offset].
*/
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/completion_target_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698