Skip to content

Commit

Permalink
Version 3.4.0-281.0.dev
Browse files Browse the repository at this point in the history
Merge 41612e4 into dev
  • Loading branch information
Dart CI committed Mar 28, 2024
2 parents cc95cb2 + 41612e4 commit 51f6973
Show file tree
Hide file tree
Showing 53 changed files with 380 additions and 175 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ vars = {
"boringssl_rev": "d24a38200fef19150eef00cad35b138936c08767",
"browser-compat-data_tag": "ac8cae697014da1ff7124fba33b0b4245cc6cd1b", # v1.0.22
"cpu_features_rev": "936b9ab5515dead115606559502e3864958f7f6e",
"devtools_rev": "5a2f92117eb2257fa38bbc4f4ccb18bb5dbd6ebe",
"devtools_rev": "9e510709212a714eaf985141629fef04a1180356",
"icu_rev": "81d656878ec611cb0b42d52c82e9dae93920d9ba",
"jinja2_rev": "2222b31554f03e62600cd7e383376a7c187967a1",
"libcxx_rev": "44079a4cc04cdeffb9cfe8067bfb3c276fb2bab0",
Expand Down
3 changes: 2 additions & 1 deletion pkg/_fe_analyzer_shared/lib/src/macros/code_optimizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ class _Listener extends Listener {
});

@override
void beginExtensionDeclaration(Token extensionKeyword, Token? name) {
void beginExtensionDeclaration(
Token? augmentToken, Token extensionKeyword, Token? name) {
if (name != null) {
declaredNames.add(name.lexeme);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ class ForwardingListener implements Listener {
}

@override
void beginExtensionDeclaration(Token extensionKeyword, Token? name) {
listener?.beginExtensionDeclaration(extensionKeyword, name);
void beginExtensionDeclaration(
Token? augmentToken, Token extensionKeyword, Token? name) {
listener?.beginExtensionDeclaration(augmentToken, extensionKeyword, name);
}

@override
Expand Down
3 changes: 2 additions & 1 deletion pkg/_fe_analyzer_shared/lib/src/parser/listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ class Listener implements UnescapeErrorListener {
/// - type variables
///
/// At this point we have parsed the name and type parameter declarations.
void beginExtensionDeclaration(Token extensionKeyword, Token? name) {}
void beginExtensionDeclaration(
Token? augmentToken, Token extensionKeyword, Token? name) {}

/// Handle the end of an extension methods declaration. Substructures:
/// - substructures from [beginExtensionDeclaration]
Expand Down
14 changes: 14 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/parser/modifier_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ class ModifierContext {
return token;
}

/// Parse modifiers for extension declarations.
Token parseExtensionModifiers(Token token, Token keyword) {
token = _parseModifiers(token);
reportTopLevelModifierError(constToken, keyword);
reportTopLevelModifierError(externalToken, keyword);
reportExtraneousModifier(abstractToken);
reportExtraneousModifier(covariantToken);
reportExtraneousModifier(lateToken);
reportExtraneousModifier(requiredToken);
reportExtraneousModifier(staticToken);
reportExtraneousModifier(varToken);
return token;
}

/// Parse modifiers for mixin declarations.
Token parseMixinModifiers(Token token, Token keyword) {
token = _parseModifiers(token);
Expand Down
21 changes: 13 additions & 8 deletions pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,9 @@ class Parser {
Token? endGroup = keyword.next!.endGroup;
if (endGroup != null && optional('on', endGroup.next!)) {
directiveState?.checkDeclaration();
return parseExtension(beginToken, keyword);
ModifierContext context = new ModifierContext(this);
context.parseExtensionModifiers(modifierStart, keyword);
return parseExtension(beginToken, context.augmentToken, keyword);
}
}
directiveState?.checkDeclaration();
Expand Down Expand Up @@ -762,9 +764,10 @@ class Parser {
return parseMixin(
beginToken, context.augmentToken, baseToken, keyword);
} else if (identical(value, 'extension')) {
context.parseTopLevelKeywordModifiers(modifierStart, keyword);
context.parseExtensionModifiers(modifierStart, keyword);
directiveState?.checkDeclaration();
return parseExtension(modifierStart.next!, keyword);
return parseExtension(
modifierStart.next!, context.augmentToken, keyword);
} else if (identical(value, 'part')) {
context.parseTopLevelKeywordModifiers(modifierStart, keyword);
return parsePartOrPartOf(keyword, directiveState);
Expand Down Expand Up @@ -3056,7 +3059,8 @@ class Parser {
}

/// Parses an extension or extension type declaration.
Token parseExtension(Token beginToken, Token extensionKeyword) {
Token parseExtension(
Token beginToken, Token? augmentToken, Token extensionKeyword) {
assert(optional('extension', extensionKeyword));
Token token = extensionKeyword;
listener.beginExtensionDeclarationPrelude(extensionKeyword);
Expand All @@ -3066,7 +3070,8 @@ class Parser {
return parseExtensionTypeDeclaration(
beginToken, token.next!, extensionKeyword, typeKeyword);
} else {
return parseExtensionDeclaration(beginToken, token, extensionKeyword);
return parseExtensionDeclaration(
beginToken, token, augmentToken, extensionKeyword);
}
}

Expand All @@ -3084,8 +3089,8 @@ class Parser {
/// `}'
/// ```
///
Token parseExtensionDeclaration(
Token beginToken, Token token, Token extensionKeyword) {
Token parseExtensionDeclaration(Token beginToken, Token token,
Token? augmentToken, Token extensionKeyword) {
assert(optional('extension', extensionKeyword));
assert(!optional('type', token));
Token? name = token.next!;
Expand All @@ -3100,7 +3105,7 @@ class Parser {
}
token = computeTypeParamOrArg(token, /* inDeclaration = */ true)
.parseVariables(token, this);
listener.beginExtensionDeclaration(extensionKeyword, name);
listener.beginExtensionDeclaration(augmentToken, extensionKeyword, name);
Token onKeyword = token.next!;
if (!optional('on', onKeyword)) {
// Recovery
Expand Down
6 changes: 6 additions & 0 deletions pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,12 @@ class LspAnalysisServer extends AnalysisServer {
// If we skip the work above, we still need to ensure plugins are notified
// of the new overlay (which usually happens in `_afterOverlayChanged`).
_notifyPluginsOverlayChanged(path, plugin.AddContentOverlay(content));

// We also need to ensure notifications like Outline can still sent in
// this case (which are usually triggered by the re-analysis), so force
// sending the resolved unit to the result stream even if we didn't need
// to re-analyze it.
unawaited(getResolvedUnit(path, sendCachedToStream: true));
}
}

Expand Down
34 changes: 34 additions & 0 deletions pkg/analysis_server/test/lsp/outline_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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 'dart:async';

import 'package:analysis_server/lsp_protocol/protocol.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
Expand Down Expand Up @@ -172,4 +174,36 @@ class A {
end: Position(line: 9, character: 17))));
expect(fieldD.children, isNull);
}

/// As an optimization, when a file is opened but does not contain any changes
/// from what was on disk, we skip analysis (in onOverlayCreated).
/// We still need to ensure that notifications like Outline (which are
/// triggered by analysis results and only sent for open files) are sent to
/// the client.
Future<void> test_openedWithoutChanges() async {
var content = r'''
class A {}
''';

// Create the file on disk so that opening the file won't re-trigger
// analysis.
newFile(mainFilePath, content);

// Track when outlines arrive.
Outline? mainOutline;
unawaited(
waitForOutline(mainFileUri).then((outline) => mainOutline = outline),
);

await Future.wait([
initialize(initializationOptions: {'outline': true}),
waitForAnalysisComplete(),
]);
await pumpEventQueue(times: 5000);
expect(mainOutline, isNull); // Shouldn't be sent yet, file is not open.

await openFile(mainFileUri, content);
await pumpEventQueue(times: 5000);
expect(mainOutline, isNotNull); // Should have been sent now.
}
}
12 changes: 11 additions & 1 deletion pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6446,6 +6446,10 @@ final class ExtendsClauseImpl extends AstNodeImpl implements ExtendsClause {
/// 'on' [TypeAnnotation] [ShowClause]? [HideClause]?
/// '{' [ClassMember]* '}'
abstract final class ExtensionDeclaration implements CompilationUnitMember {
/// The 'augment' keyword, or `null` if the keyword was absent.
@experimental
Token? get augmentKeyword;

@override
ExtensionElement? get declaredElement;

Expand Down Expand Up @@ -6486,6 +6490,9 @@ abstract final class ExtensionDeclaration implements CompilationUnitMember {
/// 'on' [TypeAnnotation] '{' [ClassMember]* '}'
final class ExtensionDeclarationImpl extends CompilationUnitMemberImpl
implements ExtensionDeclaration {
@override
final Token? augmentKeyword;

@override
final Token extensionKeyword;

Expand Down Expand Up @@ -6520,6 +6527,7 @@ final class ExtensionDeclarationImpl extends CompilationUnitMemberImpl
ExtensionDeclarationImpl({
required super.comment,
required super.metadata,
required this.augmentKeyword,
required this.extensionKeyword,
required this.typeKeyword,
required this.name,
Expand Down Expand Up @@ -6547,7 +6555,8 @@ final class ExtensionDeclarationImpl extends CompilationUnitMemberImpl
}

@override
Token get firstTokenAfterCommentAndMetadata => extensionKeyword;
Token get firstTokenAfterCommentAndMetadata =>
augmentKeyword ?? extensionKeyword;

@override
NodeListImpl<ClassMemberImpl> get members => _members;
Expand All @@ -6561,6 +6570,7 @@ final class ExtensionDeclarationImpl extends CompilationUnitMemberImpl

@override
ChildEntities get _childEntities => ChildEntities()
..addToken('augmentKeyword', augmentKeyword)
..addToken('extensionKeyword', extensionKeyword)
..addToken('name', name)
..addNode('typeParameters', typeParameters)
Expand Down
7 changes: 6 additions & 1 deletion pkg/analyzer/lib/src/fasta/ast_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ class AstBuilder extends StackListener {
void beginEnum(Token enumKeyword) {}

@override
void beginExtensionDeclaration(Token extensionKeyword, Token? nameToken) {
void beginExtensionDeclaration(
Token? augmentKeyword, Token extensionKeyword, Token? nameToken) {
assert(optional('extension', extensionKeyword));
assert(_classLikeBuilder == null);
debugEvent("ExtensionHeader");
Expand All @@ -321,6 +322,7 @@ class AstBuilder extends StackListener {
_classLikeBuilder = _ExtensionDeclarationBuilder(
comment: comment,
metadata: metadata,
augmentKeyword: augmentKeyword,
extensionKeyword: extensionKeyword,
name: nameToken,
typeParameters: typeParameters,
Expand Down Expand Up @@ -6086,6 +6088,7 @@ class _EnumDeclarationBuilder extends _ClassLikeDeclarationBuilder {
}

class _ExtensionDeclarationBuilder extends _ClassLikeDeclarationBuilder {
final Token? augmentKeyword;
final Token extensionKeyword;
final Token? name;

Expand All @@ -6095,6 +6098,7 @@ class _ExtensionDeclarationBuilder extends _ClassLikeDeclarationBuilder {
required super.typeParameters,
required super.leftBracket,
required super.rightBracket,
required this.augmentKeyword,
required this.extensionKeyword,
required this.name,
});
Expand All @@ -6107,6 +6111,7 @@ class _ExtensionDeclarationBuilder extends _ClassLikeDeclarationBuilder {
return ExtensionDeclarationImpl(
comment: comment,
metadata: metadata,
augmentKeyword: augmentKeyword,
extensionKeyword: extensionKeyword,
typeKeyword: typeKeyword,
name: name,
Expand Down
5 changes: 3 additions & 2 deletions pkg/analyzer/test/generated/parser_fasta_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ class ForwardingTestListener extends ForwardingListener {
}

@override
void beginExtensionDeclaration(Token extensionKeyword, Token? name) {
super.beginExtensionDeclaration(extensionKeyword, name);
void beginExtensionDeclaration(
Token? augmentToken, Token extensionKeyword, Token? name) {
super.beginExtensionDeclaration(augmentToken, extensionKeyword, name);
begin('ExtensionDeclaration');
}

Expand Down
Loading

0 comments on commit 51f6973

Please sign in to comment.