-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of server support for training data
Change-Id: I4943b8c30575e78c1028d9d0be174f535db99303 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97841 Reviewed-by: Ari Aye <ariaye@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
- Loading branch information
1 parent
fbc70da
commit 3a37316
Showing
8 changed files
with
202 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
pkg/analysis_server/lib/src/services/completion/token_details/token_detail_builder.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analysis_server/protocol/protocol_generated.dart'; | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:analyzer/dart/ast/syntactic_entity.dart'; | ||
import 'package:analyzer/dart/ast/token.dart'; | ||
|
||
/// An object used to build the details for each token in the code being | ||
/// analyzed. | ||
class TokenDetailBuilder { | ||
/// The list of details that were built. | ||
List<TokenDetails> details = []; | ||
|
||
/// Initialize a newly created builder. | ||
TokenDetailBuilder(); | ||
|
||
/// Visit a [node] in the AST structure to build details for all of the tokens | ||
/// contained by that node. | ||
void visitNode(AstNode node) { | ||
for (SyntacticEntity entity in node.childEntities) { | ||
if (entity is Token) { | ||
_createDetails(entity, null); | ||
} else if (entity is SimpleIdentifier) { | ||
List<String> kinds = []; | ||
if (entity.inDeclarationContext()) { | ||
kinds.add('declaration'); | ||
} else { | ||
kinds.add('identifier'); | ||
} | ||
_createDetails(entity.token, kinds); | ||
} else if (entity is AstNode) { | ||
visitNode(entity); | ||
} | ||
} | ||
} | ||
|
||
/// Create the details for a single [token], using the given list of [kinds]. | ||
void _createDetails(Token token, List<String> kinds) { | ||
details.add(new TokenDetails(token.lexeme, token.type.name, | ||
validElementKinds: kinds)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.