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

Commit 4a6764b

Browse files
author
Dart CI
committed
Version 2.12.0-244.0.dev
Merge commit '15cd98f5119833d36a24faab71bb770d8a84450c' into 'dev'
2 parents df8b9bb + 15cd98f commit 4a6764b

File tree

8 files changed

+108
-46
lines changed

8 files changed

+108
-46
lines changed

pkg/analysis_server/lib/src/computer/computer_highlights.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ class DartUnitHighlightsComputer {
380380
var type = node.inDeclarationContext()
381381
? HighlightRegionType.PARAMETER_DECLARATION
382382
: HighlightRegionType.PARAMETER_REFERENCE;
383-
return _addRegion_node(node, type);
383+
var modifiers =
384+
node.parent is Label ? {CustomSemanticTokenModifiers.label} : null;
385+
return _addRegion_node(node, type, semanticTokenModifiers: modifiers);
384386
}
385387

386388
bool _addIdentifierRegion_typeParameter(SimpleIdentifier node) {
@@ -459,10 +461,21 @@ class DartUnitHighlightsComputer {
459461
}
460462
}
461463

462-
bool _addRegion_node(AstNode node, HighlightRegionType type) {
464+
bool _addRegion_node(
465+
AstNode node,
466+
HighlightRegionType type, {
467+
SemanticTokenTypes semanticTokenType,
468+
Set<SemanticTokenModifiers> semanticTokenModifiers,
469+
}) {
463470
var offset = node.offset;
464471
var length = node.length;
465-
_addRegion(offset, length, type);
472+
_addRegion(
473+
offset,
474+
length,
475+
type,
476+
semanticTokenType: semanticTokenType,
477+
semanticTokenModifiers: semanticTokenModifiers,
478+
);
466479
return true;
467480
}
468481

pkg/analysis_server/lib/src/lsp/constants.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,23 @@ abstract class CustomMethods {
100100
}
101101

102102
abstract class CustomSemanticTokenModifiers {
103-
// A modifier applied to control keywords like if/for/etc. so they can be
104-
// coloured differently to other keywords (void, import, etc), matching the
105-
// original Dart textmate grammar.
106-
// https://github.com/dart-lang/dart-syntax-highlight/blob/84a8e84f79bc917ebd959a4587349c865dc945e0/grammars/dart.json#L244-L261
103+
/// A modifier applied to control keywords like if/for/etc. so they can be
104+
/// coloured differently to other keywords (void, import, etc), matching the
105+
/// original Dart textmate grammar.
106+
/// https://github.com/dart-lang/dart-syntax-highlight/blob/84a8e84f79bc917ebd959a4587349c865dc945e0/grammars/dart.json#L244-L261
107107
static const control = SemanticTokenModifiers('control');
108108

109+
/// A modifier applied to parameter references to indicate they are the name/label
110+
/// to allow theming them differently to the values. For example in the code
111+
/// `foo({String a}) => foo(a: a)` the a's will be differentiated as:
112+
/// - parameter.declaration
113+
/// - parameter.label
114+
/// - parameter
115+
static const label = SemanticTokenModifiers('label');
116+
109117
/// All custom semantic token modifiers, used to populate the LSP Legend which must
110118
/// include all used modifiers.
111-
static const values = [control];
119+
static const values = [control, label];
112120
}
113121

114122
abstract class CustomSemanticTokenTypes {

pkg/analysis_server/test/lsp/semantic_tokens_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,33 @@ class MyClass {}
600600
expect(decoded, equals(expected));
601601
}
602602

603+
Future<void> test_namedArguments() async {
604+
final content = '''
605+
f({String a}) {
606+
f(a: a);
607+
}
608+
''';
609+
610+
final expected = [
611+
_Token('f', SemanticTokenTypes.function,
612+
[SemanticTokenModifiers.declaration, SemanticTokenModifiers.static]),
613+
_Token('String', SemanticTokenTypes.class_),
614+
_Token('a', SemanticTokenTypes.parameter,
615+
[SemanticTokenModifiers.declaration]),
616+
_Token('f', SemanticTokenTypes.function),
617+
_Token('a', SemanticTokenTypes.parameter,
618+
[CustomSemanticTokenModifiers.label]),
619+
_Token('a', SemanticTokenTypes.parameter),
620+
];
621+
622+
await initialize();
623+
await openFile(mainFileUri, withoutMarkers(content));
624+
625+
final tokens = await getSemanticTokens(mainFileUri);
626+
final decoded = decodeSemanticTokens(content, tokens);
627+
expect(decoded, equals(expected));
628+
}
629+
603630
Future<void> test_range() async {
604631
final content = '''
605632
/// class docs

pkg/nnbd_migration/lib/migration_cli.dart

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -813,25 +813,7 @@ sources' action.
813813
/// return additional paths that aren't inside the user's project, but doesn't
814814
/// override this method, then those additional paths will be analyzed but not
815815
/// migrated.
816-
bool shouldBeMigrated(String path) => shouldBeMigrated2(path);
817-
818-
/// Determines whether a migrated version of the file at [path] should be
819-
/// output by the migration too. May be overridden by a derived class.
820-
///
821-
/// This method should return `false` for files that are being considered by
822-
/// the migration tool for information only (for example generated files, or
823-
/// usages of the code-to-be-migrated by one one of its clients).
824-
///
825-
/// By default returns `true` if the file is contained within the context
826-
/// root. This means that if a client overrides [computePathsToProcess] to
827-
/// return additional paths that aren't inside the user's project, but doesn't
828-
/// override this method, then those additional paths will be analyzed but not
829-
/// migrated.
830-
///
831-
/// Note: in a future version of the code, this method will be removed;
832-
/// clients that are overriding this method should switch to overriding
833-
/// [shouldBeMigrated] instead.
834-
bool shouldBeMigrated2(String path) {
816+
bool shouldBeMigrated(String path) {
835817
return analysisContext.contextRoot.isAnalyzed(path);
836818
}
837819

pkg/nnbd_migration/lib/src/preview/preview_site.dart

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ class IncrementalPlan {
179179

180180
var index = 0;
181181

182+
// Returns the next line and updates [index].
183+
//
184+
// After this function returns, [index] points to the character after the
185+
// end of the line which was returned.
182186
String getLine() {
183187
var nextIndex = code.indexOf('\n', index);
184188
if (nextIndex < 0) {
@@ -220,24 +224,37 @@ class IncrementalPlan {
220224
// [code] consists _only_ of one comment line.
221225
return '$code$newline$newline// @dart=2.9$newline';
222226
}
223-
line = getLine();
224-
lineStart = line.indexOf(_nonWhitespaceChar);
225-
while (lineStart >= 0 &&
226-
line.length > lineStart + 1 &&
227-
line.codeUnitAt(lineStart) == $slash &&
228-
line.codeUnitAt(lineStart + 1) == $slash) {
229-
// Another comment line.
227+
var previousLineIndex = index;
228+
while (true) {
229+
previousLineIndex = index;
230230
line = getLine();
231-
if (index == length) {
232-
// [code] consists _only_ of this block comment.
233-
return '$code$newline$newline// @dart=2.9$newline';
234-
}
235231
lineStart = line.indexOf(_nonWhitespaceChar);
232+
if (lineStart < 0) {
233+
// Line of whitespace; end of block comment.
234+
break;
235+
}
236+
if (line.length <= lineStart + 1) {
237+
// Only one character; not a comment; end of block comment.
238+
break;
239+
}
240+
if (line.codeUnitAt(lineStart) == $slash &&
241+
line.codeUnitAt(lineStart + 1) == $slash) {
242+
// Comment line.
243+
if (index == length) {
244+
// [code] consists _only_ of this block comment.
245+
return '$code$newline$newline// @dart=2.9$newline';
246+
}
247+
continue;
248+
} else {
249+
// Non-blank, non-comment line.
250+
break;
251+
}
236252
}
237-
// [index] points to the start of [line], which is the first
253+
// [previousLineIndex] points to the start of [line], which is the first
238254
// non-comment line following the first comment.
239-
return '${code.substring(0, index)}$newline// @dart=2.9$newline$newline'
240-
'${code.substring(index)}';
255+
return '${code.substring(0, previousLineIndex)}$newline'
256+
'// @dart=2.9$newline$newline'
257+
'${code.substring(previousLineIndex)}';
241258
} else {
242259
// [code] does not start with a block comment.
243260
return '// @dart=2.9$newline$newline$code';

pkg/nnbd_migration/test/migration_cli_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ class _MigrationCliRunner extends MigrationCliRunner {
185185
}
186186

187187
@override
188-
bool shouldBeMigrated2(String path) =>
188+
bool shouldBeMigrated(String path) =>
189189
cli._test.overrideShouldBeMigrated?.call(path) ??
190-
super.shouldBeMigrated2(path);
190+
super.shouldBeMigrated(path);
191191

192192
/// Sorts the paths in [paths] for repeatability of migration tests.
193193
Set<String> _sortPaths(Set<String> paths) {

pkg/nnbd_migration/test/preview/preview_site_test.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,29 @@ void main(List args) {
156156
void test_optOutOfNullSafety_commentThenCode() {
157157
expect(
158158
IncrementalPlan.optCodeOutOfNullSafety('// comment\n\nvoid main() {}'),
159-
equals('// comment\n\n\n// @dart=2.9\n\nvoid main() {}'));
159+
equals('// comment\n\n// @dart=2.9\n\n\nvoid main() {}'));
160160
}
161161

162162
void test_optOutOfNullSafety_commentThenCode_windows() {
163163
expect(
164164
IncrementalPlan.optCodeOutOfNullSafety(
165165
'// comment\r\n\r\nvoid main() {}'),
166-
equals('// comment\r\n\r\n\r\n// @dart=2.9\r\n\r\nvoid main() {}'));
166+
equals('// comment\r\n\r\n// @dart=2.9\r\n\r\n\r\nvoid main() {}'));
167+
}
168+
169+
void test_optOutOfNullSafety_commentThenDirective() {
170+
expect(
171+
IncrementalPlan.optCodeOutOfNullSafety(
172+
'// comment\nimport "dart:core";'),
173+
equals('// comment\n\n// @dart=2.9\n\nimport "dart:core";'));
174+
}
175+
176+
void test_optOutOfNullSafety_commentThenDirective_multiLine() {
177+
expect(
178+
IncrementalPlan.optCodeOutOfNullSafety(
179+
'// comment\n// comment\nimport "dart:core";'),
180+
equals(
181+
'// comment\n// comment\n\n// @dart=2.9\n\nimport "dart:core";'));
167182
}
168183

169184
void test_optOutOfNullSafety_empty() {

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 12
2929
PATCH 0
30-
PRERELEASE 243
30+
PRERELEASE 244
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)