Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6135aed

Browse files
author
Dart CI
committed
Version 2.12.0-44.0.dev
Merge commit '94fa3c89c7caa7a9a6f476e151e2eea15f12bbb5' into 'dev'
2 parents 6a805f4 + 94fa3c8 commit 6135aed

66 files changed

Lines changed: 969 additions & 578 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pkg/_fe_analyzer_shared/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: _fe_analyzer_shared
2-
version: 12.0.0
2+
version: 13.0.0
33
description: Logic that is shared between the front_end and analyzer packages.
44
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/_fe_analyzer_shared
55

pkg/analysis_server/lib/src/analysis_server.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ class AnalysisServerOptions {
632632

633633
/// Return `true` if the new relevance computations should be used when
634634
/// computing code completion suggestions.
635+
// TODO: This flag is no longer used.
635636
bool useNewRelevance = true;
636637

637638
/// The set of enabled features.

pkg/analysis_server/lib/src/server/driver.dart

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@ class Driver implements ServerStarter {
275275
/// A directory to analyze in order to train an analysis server snapshot.
276276
static const String TRAIN_USING = 'train-using';
277277

278-
/// A flag indicating that the new code completion relevance computation
279-
/// should be used to compute relevance scores.
280-
static const String USE_NEW_RELEVANCE = 'use-new-relevance';
281-
282278
/// The builder for attachments that should be included into crash reports.
283279
CrashReportingAttachmentsBuilder crashReportingAttachmentsBuilder =
284280
CrashReportingAttachmentsBuilder.empty;
@@ -317,7 +313,6 @@ class Driver implements ServerStarter {
317313

318314
analysisServerOptions.clientVersion = results[CLIENT_VERSION];
319315
analysisServerOptions.cacheFolder = results[CACHE_FOLDER];
320-
analysisServerOptions.useNewRelevance = results[USE_NEW_RELEVANCE];
321316

322317
// Read in any per-SDK overrides specified in <sdk>/config/settings.json.
323318
var sdkConfig = SdkConfiguration.readFromSdk();
@@ -719,14 +714,34 @@ class Driver implements ServerStarter {
719714
CommandLineParser _createArgParser() {
720715
var parser = CommandLineParser();
721716
parser.addFlag(HELP_OPTION,
722-
help: 'print this help message without starting a server',
723-
abbr: 'h',
724-
defaultsTo: false,
725-
negatable: false);
717+
abbr: 'h', negatable: false, help: 'Print this usage information.');
726718
parser.addOption(CLIENT_ID,
727-
valueHelp: 'name', help: 'an identifier used to identify the client');
719+
valueHelp: 'name', help: 'An identifier used to identify the client.');
728720
parser.addOption(CLIENT_VERSION,
729-
valueHelp: 'version', help: 'the version of the client');
721+
valueHelp: 'version', help: 'The version of the client.');
722+
723+
parser.addFlag(USE_LSP,
724+
defaultsTo: false,
725+
negatable: false,
726+
help: 'Whether to use the Language Server Protocol (LSP).');
727+
728+
parser.addOption(SDK_OPTION,
729+
valueHelp: 'path', help: 'The path to the Dart SDK.');
730+
parser.addOption(CACHE_FOLDER,
731+
valueHelp: 'path',
732+
help: 'The path to the location to write cache data.');
733+
734+
parser.addOption(INSTRUMENTATION_LOG_FILE,
735+
valueHelp: 'file path',
736+
help: 'Write instrumentation data to the given file.');
737+
parser.addOption(NEW_ANALYSIS_DRIVER_LOG,
738+
valueHelp: 'path',
739+
help: "Set a destination for the new analysis driver's log.");
740+
parser.addOption(PORT_OPTION,
741+
valueHelp: 'port',
742+
help: 'The http diagnostic port to serve status and performance '
743+
'information.');
744+
730745
parser.addFlag(DISABLE_SERVER_EXCEPTION_HANDLING,
731746
// TODO(jcollins-g): Pipeline option through and apply to all
732747
// exception-nullifying runZoned() calls.
@@ -738,51 +753,30 @@ class Driver implements ServerStarter {
738753
help: 'disable all completion features', defaultsTo: false, hide: true);
739754
parser.addFlag(DISABLE_SERVER_FEATURE_SEARCH,
740755
help: 'disable all search features', defaultsTo: false, hide: true);
741-
parser.addOption(INSTRUMENTATION_LOG_FILE,
742-
valueHelp: 'file path',
743-
help: 'write instrumentation data to the given file');
744756
parser.addFlag(INTERNAL_PRINT_TO_CONSOLE,
745757
help: 'enable sending `print` output to the console',
746758
defaultsTo: false,
747-
negatable: false);
748-
parser.addOption(NEW_ANALYSIS_DRIVER_LOG,
749-
valueHelp: 'path',
750-
help: "set a destination for the new analysis driver's log");
759+
negatable: false,
760+
hide: true);
761+
751762
parser.addFlag(ANALYTICS_FLAG,
752763
help: 'enable or disable sending analytics information to Google',
753764
hide: !telemetry.SHOW_ANALYTICS_UI);
754765
parser.addFlag(SUPPRESS_ANALYTICS_FLAG,
755766
negatable: false,
756767
help: 'suppress analytics for this session',
757768
hide: !telemetry.SHOW_ANALYTICS_UI);
758-
parser.addOption(PORT_OPTION,
759-
valueHelp: 'port',
760-
help: 'the http diagnostic port on which the server provides'
761-
' status and performance information');
762-
parser.addOption(SDK_OPTION,
763-
valueHelp: 'path', help: 'Path to the Dart sdk');
764-
parser.addOption(CACHE_FOLDER,
765-
valueHelp: 'path', help: 'Path to the location to write cache data');
766-
parser.addFlag(USE_LSP,
767-
defaultsTo: false,
768-
negatable: false,
769-
help: 'Whether to use the Language Server Protocol');
770-
parser.addFlag(ENABLE_COMPLETION_MODEL,
771-
help: 'Whether or not to turn on ML ranking for code completion');
772-
parser.addOption(COMPLETION_MODEL_FOLDER,
773-
valueHelp: 'path',
774-
help: 'Path to the location of a code completion model');
769+
775770
parser.addOption(TRAIN_USING,
776771
valueHelp: 'path',
777772
help: 'Pass in a directory to analyze for purposes of training an '
778773
'analysis server snapshot.');
779774

780-
//
781-
// Temporary flags.
782-
//
783-
parser.addFlag(USE_NEW_RELEVANCE,
784-
defaultsTo: true,
785-
help: 'Use the new relevance computation for code completion.');
775+
parser.addFlag(ENABLE_COMPLETION_MODEL,
776+
help: 'Whether or not to turn on ML ranking for code completion.');
777+
parser.addOption(COMPLETION_MODEL_FOLDER,
778+
valueHelp: 'path',
779+
help: 'Path to the location of a code completion model.');
786780

787781
//
788782
// Deprecated options - no longer read from.
@@ -800,6 +794,8 @@ class Driver implements ServerStarter {
800794
parser.addFlag('preview-dart-2', hide: true);
801795
// Removed 11/12/2020.
802796
parser.addFlag('useAnalysisHighlight2', hide: true);
797+
// Removed 11/13/2020.
798+
parser.addFlag('use-new-relevance', hide: true);
803799
// Removed 9/23/2020.
804800
parser.addFlag('use-fasta-parser', hide: true);
805801

pkg/analysis_server/lib/src/services/correction/dart/data_driven.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
66
import 'package:analysis_server/src/services/correction/fix.dart';
7+
import 'package:analysis_server/src/services/correction/fix/data_driven/code_template.dart';
78
import 'package:analysis_server/src/services/correction/fix/data_driven/element_descriptor.dart';
89
import 'package:analysis_server/src/services/correction/fix/data_driven/element_kind.dart';
910
import 'package:analysis_server/src/services/correction/fix/data_driven/element_matcher.dart';
@@ -178,7 +179,11 @@ class DataDrivenFix extends CorrectionProducer {
178179

179180
@override
180181
Future<void> compute(ChangeBuilder builder) async {
181-
var changes = _transform.changes;
182+
var changes = _transform.changesSelector
183+
.getChanges(TemplateContext.forInvocation(node, utils));
184+
if (changes == null) {
185+
return;
186+
}
182187
var data = <Object>[];
183188
for (var change in changes) {
184189
var result = change.validate(this);

pkg/analysis_server/lib/src/services/correction/fix/data_driven/add_type_parameter.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class AddTypeParameter extends Change<_Data> {
5050
@override
5151
_Data validate(DataDrivenFix fix) {
5252
var node = fix.node;
53-
var context = TemplateContext(getInvocation(node), fix.utils);
53+
var context = TemplateContext.forInvocation(node, fix.utils);
5454
if (node is NamedType) {
5555
// wrong_number_of_type_arguments
5656
// wrong_number_of_type_arguments_constructor
@@ -101,7 +101,7 @@ class AddTypeParameter extends Change<_Data> {
101101

102102
void _applyToTypeArguments(
103103
DartFileEditBuilder builder, DataDrivenFix fix, _TypeArgumentData data) {
104-
var context = TemplateContext(getInvocation(fix.node), fix.utils);
104+
var context = TemplateContext.forInvocation(fix.node, fix.utils);
105105
var typeArguments = data.typeArguments;
106106
if (typeArguments == null) {
107107
// Adding the first type argument.
@@ -130,7 +130,7 @@ class AddTypeParameter extends Change<_Data> {
130130

131131
void _applyToTypeParameters(
132132
DartFileEditBuilder builder, DataDrivenFix fix, _TypeParameterData data) {
133-
var context = TemplateContext(getInvocation(fix.node), fix.utils);
133+
var context = TemplateContext.forInvocation(fix.node, fix.utils);
134134

135135
void writeParameter(DartEditBuilder builder) {
136136
builder.write(name);

pkg/analysis_server/lib/src/services/correction/fix/data_driven/change.dart

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analysis_server/src/services/correction/dart/data_driven.dart';
6-
import 'package:analyzer/dart/ast/ast.dart';
76
import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dart';
87

98
/// The behavior common to all of the changes used to construct a transform.
@@ -13,36 +12,6 @@ abstract class Change<D> {
1312
/// [validate] method.
1413
void apply(DartFileEditBuilder builder, DataDrivenFix fix, D data);
1514

16-
/// Return the invocation containing the given [node]. The invocation will be
17-
/// either an instance creation expression, function invocation, method
18-
/// invocation, or an extension override.
19-
AstNode getInvocation(AstNode node) {
20-
if (node is ArgumentList) {
21-
return node.parent;
22-
} else if (node is InstanceCreationExpression ||
23-
node is InvocationExpression) {
24-
return node;
25-
} else if (node is SimpleIdentifier) {
26-
var parent = node.parent;
27-
if (parent is ConstructorName) {
28-
var grandparent = parent.parent;
29-
if (grandparent is InstanceCreationExpression) {
30-
return grandparent;
31-
}
32-
} else if (parent is MethodInvocation && parent.methodName == node) {
33-
return parent;
34-
}
35-
} else if (node is TypeArgumentList) {
36-
var parent = node.parent;
37-
if (parent is InvocationExpression) {
38-
return parent;
39-
} else if (parent is ExtensionOverride) {
40-
return parent;
41-
}
42-
}
43-
return null;
44-
}
45-
4615
/// Validate that this change can be applied. Return the data to be passed to
4716
/// [apply] if the change can be applied, or `null` if it can't be applied.
4817
D validate(DataDrivenFix fix);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'package:analysis_server/src/services/correction/fix/data_driven/change.dart';
6+
import 'package:analysis_server/src/services/correction/fix/data_driven/code_template.dart';
7+
import 'package:analysis_server/src/services/correction/fix/data_driven/expression.dart';
8+
9+
/// An object that can select a single list of changes from among one or more
10+
/// possible lists.
11+
abstract class ChangesSelector {
12+
/// Return the list of changes that should be applied based on the [context].
13+
List<Change> getChanges(TemplateContext context);
14+
}
15+
16+
/// A changes selector that uses boolean-valued conditions to select the list.
17+
class ConditionalChangesSelector implements ChangesSelector {
18+
/// A table mapping the expressions to be evaluated to the changes that those
19+
/// conditions select.
20+
final Map<Expression, List<Change>> changeMap;
21+
22+
/// Initialize a newly created conditional changes selector with the changes
23+
/// in the [changeMap].
24+
ConditionalChangesSelector(this.changeMap);
25+
26+
@override
27+
List<Change> getChanges(TemplateContext context) {
28+
for (var entry in changeMap.entries) {
29+
if (entry.key.evaluateIn(context)) {
30+
return entry.value;
31+
}
32+
}
33+
return null;
34+
}
35+
}
36+
37+
/// A changes selector that has a single, unconditional list of changes.
38+
class UnconditionalChangesSelector implements ChangesSelector {
39+
/// The list of changes to be returned.
40+
final List<Change> changes;
41+
42+
/// Initialize a newly created changes selector to return the given list of
43+
/// [changes].
44+
UnconditionalChangesSelector(this.changes);
45+
46+
@override
47+
List<Change> getChanges(TemplateContext context) {
48+
return changes;
49+
}
50+
}

pkg/analysis_server/lib/src/services/correction/fix/data_driven/code_fragment_parser.dart

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class CodeFragmentParser {
275275
/// <identifier> | <string>
276276
Expression _parsePrimaryExpression() {
277277
var token = currentToken;
278-
var kind = token.kind;
278+
var kind = token?.kind;
279279
if (kind == _TokenKind.identifier) {
280280
advance();
281281
var variableName = token.lexeme;
@@ -295,8 +295,23 @@ class CodeFragmentParser {
295295
var value = lexeme.substring(1, lexeme.length - 1);
296296
return LiteralString(value);
297297
}
298-
errorReporter.reportErrorForOffset(TransformSetErrorCode.expectedPrimary,
299-
token.offset + delta, token.length);
298+
int offset;
299+
int length;
300+
if (token == null) {
301+
if (tokens.isNotEmpty) {
302+
token = tokens[tokens.length - 1];
303+
offset = token.offset + delta;
304+
length = token.length;
305+
} else {
306+
offset = delta;
307+
length = 0;
308+
}
309+
} else {
310+
offset = token.offset + delta;
311+
length = token.length;
312+
}
313+
errorReporter.reportErrorForOffset(
314+
TransformSetErrorCode.expectedPrimary, offset, length);
300315
return null;
301316
}
302317
}

pkg/analysis_server/lib/src/services/correction/fix/data_driven/code_template.dart

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,45 @@ class TemplateContext {
6565
/// The utilities used to help extract the code associated with various nodes.
6666
final CorrectionUtils utils;
6767

68-
/// Initialize a newly created variable support.
68+
/// Initialize a newly created template context with the [node] and [utils].
6969
TemplateContext(this.node, this.utils);
70+
71+
/// Initialize a newly created template context that uses the invocation
72+
/// containing the [node] and the [utils].
73+
factory TemplateContext.forInvocation(AstNode node, CorrectionUtils utils) =>
74+
TemplateContext(_getInvocation(node), utils);
75+
76+
/// Return the invocation containing the given [node]. The invocation will be
77+
/// either an instance creation expression, function invocation, method
78+
/// invocation, or an extension override.
79+
static AstNode _getInvocation(AstNode node) {
80+
if (node is ArgumentList) {
81+
return node.parent;
82+
} else if (node is InstanceCreationExpression ||
83+
node is InvocationExpression) {
84+
return node;
85+
} else if (node is SimpleIdentifier) {
86+
var parent = node.parent;
87+
if (parent is ConstructorName) {
88+
var grandparent = parent.parent;
89+
if (grandparent is InstanceCreationExpression) {
90+
return grandparent;
91+
}
92+
} else if (parent is Label && parent.parent is NamedExpression) {
93+
return parent.parent.parent.parent;
94+
} else if (parent is MethodInvocation && parent.methodName == node) {
95+
return parent;
96+
}
97+
} else if (node is TypeArgumentList) {
98+
var parent = node.parent;
99+
if (parent is InvocationExpression) {
100+
return parent;
101+
} else if (parent is ExtensionOverride) {
102+
return parent;
103+
}
104+
}
105+
return null;
106+
}
70107
}
71108

72109
/// Literal text within a template.

0 commit comments

Comments
 (0)