Skip to content

Commit cbfc078

Browse files
srawlinsCommit Queue
authored andcommitted
DAS plugins: Bump language version to 3.9
Change-Id: I880e53634c570cc25f4ff22dd01397b088b9bd07 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447441 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 1465c10 commit cbfc078

23 files changed

+580
-353
lines changed

pkg/analysis_server_plugin/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.2.3-dev
22

33
- Require version `8.2.0` of the `analyzer` package.
4+
- Require Dart SDK `^3.9.0`.
45
- Add support for automatic re-analysis of files changed on-disk (as opposed to
56
file contents changed in the IDE, which is already supported).
67

pkg/analysis_server_plugin/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ linter:
3030
- unnecessary_library_directive
3131
- unnecessary_parenthesis
3232
- unreachable_from_main
33+
- use_null_aware_elements
3334

pkg/analysis_server_plugin/lib/edit/correction_utils.dart

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ final class CorrectionUtils {
3131
String? _endOfLine;
3232

3333
CorrectionUtils(ParsedUnitResult result)
34-
: _unit = result.unit,
35-
_buffer = result.content;
34+
: _unit = result.unit,
35+
_buffer = result.content;
3636

3737
/// The EOL sequence to use for this [CompilationUnit].
3838
String get endOfLine {
@@ -131,8 +131,10 @@ final class CorrectionUtils {
131131

132132
/// Returns a [SourceRange] that covers [sourceRange] and extends (if
133133
/// possible) to cover whole lines.
134-
SourceRange getLinesRange(SourceRange sourceRange,
135-
{bool skipLeadingEmptyLines = false}) {
134+
SourceRange getLinesRange(
135+
SourceRange sourceRange, {
136+
bool skipLeadingEmptyLines = false,
137+
}) {
136138
// Calculate the start:
137139
var startOffset = sourceRange.offset;
138140
var startLineOffset = getLineContentStart(startOffset);
@@ -143,8 +145,9 @@ final class CorrectionUtils {
143145
var endOffset = sourceRange.end;
144146
var afterEndLineOffset = endOffset;
145147
var lineInfo = _unit.lineInfo;
146-
var lineStart = lineInfo
147-
.getOffsetOfLine(lineInfo.getLocation(startLineOffset).lineNumber - 1);
148+
var lineStart = lineInfo.getOffsetOfLine(
149+
lineInfo.getLocation(startLineOffset).lineNumber - 1,
150+
);
148151
if (lineStart == startLineOffset) {
149152
// Only consume line endings after the end of the range if there is
150153
// nothing else on the line containing the beginning of the range.
@@ -184,10 +187,7 @@ final class CorrectionUtils {
184187

185188
/// Returns the text of the given [AstNode] in the unit, including preceding
186189
/// comments.
187-
String getNodeText(
188-
AstNode node, {
189-
bool withLeadingComments = false,
190-
}) {
190+
String getNodeText(AstNode node, {bool withLeadingComments = false}) {
191191
var firstToken = withLeadingComments
192192
? node.beginToken.precedingComments ?? node.beginToken
193193
: node.beginToken;
@@ -252,8 +252,13 @@ final class CorrectionUtils {
252252
/// Usually [includeLeading] and [ensureTrailingNewline] are set together,
253253
/// when indenting a set of statements to go inside a block (as opposed to
254254
/// just wrapping a nested expression that might span multiple lines).
255-
String replaceSourceIndent(String source, String oldIndent, String newIndent,
256-
{bool includeLeading = false, bool ensureTrailingNewline = false}) {
255+
String replaceSourceIndent(
256+
String source,
257+
String oldIndent,
258+
String newIndent, {
259+
bool includeLeading = false,
260+
bool ensureTrailingNewline = false,
261+
}) {
257262
// Prepare token ranges.
258263
var lineRanges = <SourceRange>[];
259264
{
@@ -323,12 +328,20 @@ final class CorrectionUtils {
323328
/// when indenting a set of statements to go inside a block (as opposed to
324329
/// just wrapping a nested expression that might span multiple lines).
325330
String replaceSourceRangeIndent(
326-
SourceRange range, String oldIndent, String newIndent,
327-
{bool includeLeading = false, bool ensureTrailingNewline = false}) {
331+
SourceRange range,
332+
String oldIndent,
333+
String newIndent, {
334+
bool includeLeading = false,
335+
bool ensureTrailingNewline = false,
336+
}) {
328337
var oldSource = getRangeText(range);
329-
return replaceSourceIndent(oldSource, oldIndent, newIndent,
330-
includeLeading: includeLeading,
331-
ensureTrailingNewline: ensureTrailingNewline);
338+
return replaceSourceIndent(
339+
oldSource,
340+
oldIndent,
341+
newIndent,
342+
includeLeading: includeLeading,
343+
ensureTrailingNewline: ensureTrailingNewline,
344+
);
332345
}
333346

334347
/// Returns the [_InvertedCondition] for the given logical expression.
@@ -367,13 +380,21 @@ final class CorrectionUtils {
367380
ls = _invertCondition0(le);
368381
rs = _invertCondition0(re);
369382
return _InvertedCondition._binary(
370-
TokenType.BAR_BAR.precedence, ls, ' || ', rs);
383+
TokenType.BAR_BAR.precedence,
384+
ls,
385+
' || ',
386+
rs,
387+
);
371388
}
372389
if (operator == TokenType.BAR_BAR) {
373390
ls = _invertCondition0(le);
374391
rs = _invertCondition0(re);
375392
return _InvertedCondition._binary(
376-
TokenType.AMPERSAND_AMPERSAND.precedence, ls, ' && ', rs);
393+
TokenType.AMPERSAND_AMPERSAND.precedence,
394+
ls,
395+
' && ',
396+
rs,
397+
);
377398
}
378399
} else if (expression is IsExpression) {
379400
var expressionSource = getNodeText(expression.expression);
@@ -432,14 +453,15 @@ class TokenUtils {
432453
static List<Token> getTokens(String s, FeatureSet featureSet) {
433454
try {
434455
var tokens = <Token>[];
435-
var scanner = Scanner(
436-
_SourceMock(),
437-
CharSequenceReader(s),
438-
DiagnosticListener.nullListener,
439-
)..configureFeatures(
440-
featureSetForOverriding: featureSet,
441-
featureSet: featureSet,
442-
);
456+
var scanner =
457+
Scanner(
458+
_SourceMock(),
459+
CharSequenceReader(s),
460+
DiagnosticListener.nullListener,
461+
)..configureFeatures(
462+
featureSetForOverriding: featureSet,
463+
featureSet: featureSet,
464+
);
443465
var token = scanner.tokenize();
444466
while (!token.isEof) {
445467
tokens.add(token);
@@ -460,25 +482,37 @@ class _InvertedCondition {
460482

461483
_InvertedCondition(this._precedence, this._source);
462484

463-
static _InvertedCondition _binary(int precedence, _InvertedCondition left,
464-
String operation, _InvertedCondition right) {
465-
var src = _parenthesizeIfRequired(left, precedence) +
485+
static _InvertedCondition _binary(
486+
int precedence,
487+
_InvertedCondition left,
488+
String operation,
489+
_InvertedCondition right,
490+
) {
491+
var src =
492+
_parenthesizeIfRequired(left, precedence) +
466493
operation +
467494
_parenthesizeIfRequired(right, precedence);
468495
return _InvertedCondition(precedence, src);
469496
}
470497

471498
static _InvertedCondition _binary2(
472-
_InvertedCondition left, String operation, _InvertedCondition right) {
499+
_InvertedCondition left,
500+
String operation,
501+
_InvertedCondition right,
502+
) {
473503
// TODO(scheglov): consider merging with "_binary()" after testing
474504
return _InvertedCondition(
475-
1 << 20, '${left._source}$operation${right._source}');
505+
1 << 20,
506+
'${left._source}$operation${right._source}',
507+
);
476508
}
477509

478510
/// Adds enclosing parenthesis if the precedence of the [_InvertedCondition]
479511
/// if less than the precedence of the expression we are going it to use in.
480512
static String _parenthesizeIfRequired(
481-
_InvertedCondition expr, int newOperatorPrecedence) {
513+
_InvertedCondition expr,
514+
int newOperatorPrecedence,
515+
) {
482516
if (expr._precedence < newOperatorPrecedence) {
483517
return '(${expr._source})';
484518
}

pkg/analysis_server_plugin/lib/edit/dart/correction_producer.dart

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ sealed class CorrectionProducer<T extends ParsedUnitResult>
168168
}
169169
var diagnosticOffset = diagnostic.problemMessage.offset;
170170
var diagnosticLength = diagnostic.problemMessage.length;
171-
return _coveringNode =
172-
unit.nodeCovering(offset: diagnosticOffset, length: diagnosticLength);
171+
return _coveringNode = unit.nodeCovering(
172+
offset: diagnosticOffset,
173+
length: diagnosticLength,
174+
);
173175
}
174176

175177
/// The length of the source range associated with the diagnostic being
@@ -242,15 +244,15 @@ final class CorrectionProducerContext {
242244
required Token token,
243245
required int selectionOffset,
244246
required int selectionLength,
245-
}) : _libraryResult = libraryResult,
246-
_unitResult = unitResult,
247-
_sessionHelper = AnalysisSessionHelper(unitResult.session),
248-
_utils = dartFixContext?.correctionUtils ?? CorrectionUtils(unitResult),
249-
_applyingBulkFixes = applyingBulkFixes,
250-
_diagnostic = diagnostic,
251-
_token = token,
252-
_selectionOffset = selectionOffset,
253-
_selectionLength = selectionLength;
247+
}) : _libraryResult = libraryResult,
248+
_unitResult = unitResult,
249+
_sessionHelper = AnalysisSessionHelper(unitResult.session),
250+
_utils = dartFixContext?.correctionUtils ?? CorrectionUtils(unitResult),
251+
_applyingBulkFixes = applyingBulkFixes,
252+
_diagnostic = diagnostic,
253+
_token = token,
254+
_selectionOffset = selectionOffset,
255+
_selectionLength = selectionLength;
254256

255257
String get path => _unitResult.path;
256258

@@ -296,8 +298,10 @@ final class CorrectionProducerContext {
296298
int selectionOffset = -1,
297299
int selectionLength = 0,
298300
}) {
299-
var node = unitResult.unit
300-
.nodeCovering(offset: selectionOffset, length: selectionLength);
301+
var node = unitResult.unit.nodeCovering(
302+
offset: selectionOffset,
303+
length: selectionLength,
304+
);
301305
node ??= unitResult.unit;
302306

303307
var token = _tokenAt(node, selectionOffset) ?? node.beginToken;
@@ -445,7 +449,8 @@ abstract class ResolvedCorrectionProducer
445449
/// Returns the extension declaration for the given [fragment], or `null` if
446450
/// there is no such extension.
447451
Future<ExtensionDeclaration?> getExtensionDeclaration(
448-
ExtensionFragment fragment) async {
452+
ExtensionFragment fragment,
453+
) async {
449454
var result = await sessionHelper.getFragmentDeclaration(fragment);
450455
var node = result?.node;
451456
if (node is ExtensionDeclaration) {
@@ -457,7 +462,8 @@ abstract class ResolvedCorrectionProducer
457462
/// Returns the extension type for the given [fragment], or `null` if there
458463
/// is no such extension type.
459464
Future<ExtensionTypeDeclaration?> getExtensionTypeDeclaration(
460-
ExtensionTypeFragment fragment) async {
465+
ExtensionTypeFragment fragment,
466+
) async {
461467
var result = await sessionHelper.getFragmentDeclaration(fragment);
462468
var node = result?.node;
463469
if (node is ExtensionTypeDeclaration) {
@@ -588,11 +594,10 @@ abstract class ResolvedCorrectionProducer
588594
} else if (assignment.writeType case var expectedType?) {
589595
// `v += myFunction();`.
590596
var method = assignment.element;
591-
if (method
592-
case MethodElement(
593-
:var returnType,
594-
formalParameters: List(length: 1, :var first),
595-
)) {
597+
if (method case MethodElement(
598+
:var returnType,
599+
formalParameters: List(length: 1, :var first),
600+
)) {
596601
if (typeSystem.isAssignableTo(returnType, expectedType)) {
597602
// The return type is assignable to the expected type, then use
598603
// the expected parameter type.
@@ -708,10 +713,13 @@ abstract class ResolvedCorrectionProducer
708713
/// Looks if the [expression] is directly inside a closure and returns the
709714
/// return type of the closure.
710715
DartType? _closureReturnType(Expression expression) {
711-
if (expression.enclosingClosure
712-
case FunctionExpression(:var correspondingParameter, :var staticType)) {
713-
if (correspondingParameter?.type ?? staticType
714-
case FunctionType(:var returnType)) {
716+
if (expression.enclosingClosure case FunctionExpression(
717+
:var correspondingParameter,
718+
:var staticType,
719+
)) {
720+
if (correspondingParameter?.type ?? staticType case FunctionType(
721+
:var returnType,
722+
)) {
715723
return returnType;
716724
}
717725
}
@@ -757,7 +765,7 @@ sealed class _AbstractCorrectionProducer<T extends ParsedUnitResult> {
757765
final CorrectionProducerContext _context;
758766

759767
_AbstractCorrectionProducer({required CorrectionProducerContext context})
760-
: _context = context;
768+
: _context = context;
761769

762770
/// Whether the fixes are being built for the bulk-fix request.
763771
bool get applyingBulkFixes => _context._applyingBulkFixes;
@@ -796,10 +804,11 @@ sealed class _AbstractCorrectionProducer<T extends ParsedUnitResult> {
796804

797805
CorrectionUtils get utils => _context._utils;
798806

799-
CodeStyleOptions getCodeStyleOptions(File file) =>
800-
sessionHelper.session.analysisContext
801-
.getAnalysisOptionsForFile(file)
802-
.codeStyleOptions;
807+
CodeStyleOptions getCodeStyleOptions(File file) => sessionHelper
808+
.session
809+
.analysisContext
810+
.getAnalysisOptionsForFile(file)
811+
.codeStyleOptions;
803812

804813
/// Returns the function body of the most deeply nested method or function
805814
/// that encloses the [node], or `null` if the node is not in a method or

pkg/analysis_server_plugin/lib/edit/fix/dart_fix_context.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DartFixContext implements FixContext {
5050
/// least some getFixes requsts. Caching the response can speed up such
5151
/// requests.
5252
final Map<String, Future<Map<LibraryElement, Element>>>
53-
_cachedTopLevelDeclarations = {};
53+
_cachedTopLevelDeclarations = {};
5454

5555
@override
5656
final Diagnostic diagnostic;
@@ -64,8 +64,8 @@ class DartFixContext implements FixContext {
6464
required Diagnostic error,
6565
this.autoTriggered = false,
6666
CorrectionUtils? correctionUtils,
67-
}) : diagnostic = error,
68-
correctionUtils = correctionUtils ?? CorrectionUtils(unitResult);
67+
}) : diagnostic = error,
68+
correctionUtils = correctionUtils ?? CorrectionUtils(unitResult);
6969

7070
@override
7171
Diagnostic get error => diagnostic;
@@ -95,9 +95,7 @@ class DartFixContext implements FixContext {
9595
await analysisDriver.discoverAvailableFiles();
9696

9797
var fsState = analysisDriver.fsState;
98-
var filter = FileStateFilter(
99-
fsState.getFileForPath(unitResult.path),
100-
);
98+
var filter = FileStateFilter(fsState.getFileForPath(unitResult.path));
10199

102100
for (var file in fsState.knownFiles.toList()) {
103101
if (!filter.shouldInclude(file)) {

pkg/analysis_server_plugin/lib/src/correction/assist_generators.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ class _RegisteredAssistGenerators {
2424
/// A mapping from registered _assist_ producer generators to the [LintCode]s
2525
/// for which they may also act as a _fix_ producer generator.
2626
Map<ProducerGenerator, Set<LintCode>> get lintRuleMap => _lintRuleMap ??= {
27-
for (var generator in producerGenerators)
28-
generator: {
29-
for (var MapEntry(key: lintName, value: generators)
30-
in registeredFixGenerators.lintProducers.entries)
31-
if (generators.contains(generator)) lintName,
32-
},
33-
};
27+
for (var generator in producerGenerators)
28+
generator: {
29+
for (var MapEntry(key: lintName, value: generators)
30+
in registeredFixGenerators.lintProducers.entries)
31+
if (generators.contains(generator)) lintName,
32+
},
33+
};
3434

3535
void registerGenerator(ProducerGenerator generator) {
3636
producerGenerators.add(generator);

0 commit comments

Comments
 (0)