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

Unified Diff: pkg/analysis_server/lib/src/services/correction/assist_internal.dart

Issue 1737563002: Make add/remove type Quick Assists less obtrusive. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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/correction/assist_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/correction/assist_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
index be95ec110e997d1078a2285df34f7db6c05f51b3..a35eeb82b9880b9a8524f12a2cf6ff0a4a30a65c 100644
--- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
@@ -287,10 +287,6 @@ class AssistProcessor {
void _addProposal_addTypeAnnotation_VariableDeclaration() {
AstNode node = this.node;
- // check if "var v = 42;^"
- if (node is VariableDeclarationStatement) {
- node = (node as VariableDeclarationStatement).variables;
- }
// prepare VariableDeclarationList
VariableDeclarationList declarationList =
node.getAncestor((node) => node is VariableDeclarationList);
@@ -310,6 +306,11 @@ class AssistProcessor {
return;
}
VariableDeclaration variable = variables[0];
+ // must be not after the name of the variable
+ if (selectionOffset > variable.name.end) {
+ _coverageMarker();
+ return;
+ }
// we need an initializer to get the type from
Expression initializer = variable.initializer;
if (initializer == null) {
@@ -1431,44 +1432,26 @@ class AssistProcessor {
}
void _addProposal_removeTypeAnnotation() {
- VariableDeclarationList variableList;
- // try top-level variable
- {
- TopLevelVariableDeclaration declaration =
- node.getAncestor((node) => node is TopLevelVariableDeclaration);
- if (declaration != null) {
- variableList = declaration.variables;
- }
- }
- // try class field
- if (variableList == null) {
- FieldDeclaration fieldDeclaration =
- node.getAncestor((node) => node is FieldDeclaration);
- if (fieldDeclaration != null) {
- variableList = fieldDeclaration.fields;
- }
- }
- // try local variable
- if (variableList == null) {
- VariableDeclarationStatement statement =
- node.getAncestor((node) => node is VariableDeclarationStatement);
- if (statement != null) {
- variableList = statement.variables;
- }
- }
- if (variableList == null) {
+ VariableDeclarationList declarationList =
+ node.getAncestor((n) => n is VariableDeclarationList);
+ if (declarationList == null) {
_coverageMarker();
return;
}
// we need a type
- TypeName typeNode = variableList.type;
+ TypeName typeNode = declarationList.type;
if (typeNode == null) {
_coverageMarker();
return;
}
+ // must be not after the name of the variable
+ VariableDeclaration firstVariable = declarationList.variables[0];
+ if (selectionOffset > firstVariable.name.end) {
+ _coverageMarker();
+ return;
+ }
// add edit
- Token keyword = variableList.keyword;
- VariableDeclaration firstVariable = variableList.variables[0];
+ Token keyword = declarationList.keyword;
SourceRange typeRange = rangeStartStart(typeNode, firstVariable);
if (keyword != null && keyword.lexeme != 'var') {
_addReplaceEdit(typeRange, '');
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/correction/assist_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698