Skip to content

Commit

Permalink
Version 3.7.0-0.0.dev
Browse files Browse the repository at this point in the history
Merge 6d2200b into dev
  • Loading branch information
Dart CI committed Oct 8, 2024
2 parents 115a3c6 + 6d2200b commit 75bf9e1
Show file tree
Hide file tree
Showing 129 changed files with 4,288 additions and 640 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 3.7.0

## 3.6.0

### Language
Expand Down
24 changes: 12 additions & 12 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ vars = {
# EOL comment after a dependency to disable this and pin it at its current
# revision.

"args_rev": "e623652744c82533829f2e62b1aba1a6cf06e291",
"async_rev": "c0d81f8699682d01d657a9bf827107d11904a247",
"args_rev": "e623652744c82533829f2e62b1aba1a6cf06e291", #
"async_rev": "5f70a996f673d625e3502597084653686c3e754c",
"bazel_worker_rev": "aa3cc9e826350b960e0c5a67e6065bcedba8b0ac",
"benchmark_harness_rev": "44f125ae1d045aa3de09fe88a8dd70cb7352d563",
"boolean_selector_rev": "d6c7c36ae1111f11cc24306d71d3ab2deea8fa68",
"browser_launcher_rev": "e5fc5d488eb5038bfec2a6690c72ab8dd353e101",
"characters_rev": "7633a16a22c626e19ca750223237396315268a06",
"cli_util_rev": "c36b3941e38092d6d6f87ac27d9e88f153d3ac38",
"clock_rev": "7956d60042f4ea979c4554d43eeb57d087627869",
"collection_rev": "24b75d85df6a26aac7be13b56ff1ce4360c04a64",
"convert_rev": "9035cafefc1da4315f26058734d0c2a19d5ab56a",
"crypto_rev": "eede7d6918c51159c1422b7449f40dbac660ee57",
"collection_rev": "887b826b50f48d6a9cd2c0684aa353e8e3a0fad0",
"convert_rev": "d361833e117cb2438d2a2a6d0b0acb28ff0910fb",
"crypto_rev": "3d26ef4cf22d4b218ba30e616544ad3cf52f64a1",
"csslib_rev": "a3700b05bbcc42782e8a7024790dbf019d89c249",
# Note: Updates to dart_style have to be coordinated with the infrastructure
# team so that the internal formatter `tools/sdks/dart-sdk/bin/dart format`
Expand All @@ -153,9 +153,9 @@ vars = {
"html_rev": "6d3bc86cf2ab530ef3fa5f84b5980dc318a02af4",
"http_rev": "f59cd79e1322c6272481e4f2ccfa9afcb37a6525",
"http_multi_server_rev": "e7515b5896b83d522189802a1e14e103e19426c0",
"http_parser_rev": "ce528cf82f3d26ac761e29b2494a9e0c270d4939",
"http_parser_rev": "23d775898ee90be9daf3297e298a8869bc755d84",
"intl_rev": "5d65e3808ce40e6282e40881492607df4e35669f",
"json_rpc_2_rev": "b4810dc7bee5828f240586c81f3f34853cacdbce",
"json_rpc_2_rev": "c9b616bded8cdb5bfdc836ba7648afa6aba40062",
"leak_tracker_rev": "f5620600a5ce1c44f65ddaa02001e200b096e14c", # manually rolled
"lints_rev": "5016d63c889936b2100520f999591d0492d9afe3",
"logging_rev": "6fa056098ceca03d399bff64592822b2ae5dee6e",
Expand All @@ -166,7 +166,7 @@ vars = {
"native_rev": "659511886501bcce638c3966590df04984909ef0", # dart-native-interop-team@ is rolling breaking changes manually while the assets features are in experimental.
"package_config_rev": "bafff8e90be25e1985f7e3ee40ea1d22571a93e6",
"path_rev": "e969f42ed112dd702a9453beb9df6c12ae2d3805",
"pool_rev": "924fb04353cec915d927f9f1aed88e2eda92b98a",
"pool_rev": "7bfc71b39742753a88688e56e55a828a2f5dc0bf",
"protobuf_rev": "ccf104dbc36929c0f8708285d5f3a8fae206343e",
"pub_rev": "1efd3f5e274e153637d99698b0ee454f6f2550ab", # disable tools/rev_sdk_deps.dart
"pub_semver_rev": "8cce9d00431b6653026cdfcf6cf8548078c56f02",
Expand All @@ -184,17 +184,17 @@ vars = {
"test_descriptor_rev": "a3db1efe3dc725dcae9ee61647d3bfc19b3231ac",
"test_process_rev": "52ee3f5ab70ed965bb7122c1d499081fbccd0bde",
"test_reflective_loader_rev": "598af2f503955020af0eaa82558d574a03934078",
"tools_rev": "d4995d47b99d5e9564abfed2218f4a23df75983b",
"typed_data_rev": "2bb9e6ead6394e2d4ec6068c5ece8b2ec0e2b945",
"tools_rev": "d4995d47b99d5e9564abfed2218f4a23df75983b", #
"typed_data_rev": "6abfafdcf661cd8a814619d7e2a3e99edb3a3862",
"vector_math_rev": "2cfbe2c115a57b368ccbc3c89ebd38a06764d3d1",
"watcher_rev": "3b850778ad0b62db3aa2cfe48832870c2461db30",
"web_rev": "8478cd27d574249eca3d41f9135458dfda2762c8",
"web_socket_channel_rev": "0e1d6e2eb5a0bfd62e45b772ac7107d796176cf6",
"web_socket_channel_rev": "40aa29f1d2167467f5934d755891a8beb62a1239",
"webdev_rev": "5f30c560dc4e3df341356c43ec1a766ee6b74a7c",
"webdriver_rev": "accfed557c005c87df56ffb626458f87da9f2125",
"webkit_inspection_protocol_rev": "b459c427b74bf5e0919a083a97a167fb74d8bff1",
"yaml_rev": "e773005ab84e1b4d24132b0a687be7f9a3bfda15",
"yaml_edit_rev": "5c54d455f272bbb83c948ac420c677371e69ae77",
"yaml_edit_rev": "35f4248c7bbba289b3899fa55486e2f31ef1a8c5",

# Windows deps
"crashpad_rev": "bf327d8ceb6a669607b0dbab5a83a275d03f99ed",
Expand Down
2 changes: 1 addition & 1 deletion pkg/_fe_analyzer_shared/lib/src/experiments/flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
// Instead modify 'tools/experimental_features.yaml' and run
// 'dart pkg/front_end/tool/fasta.dart generate-experimental-flags' to update.
const Version defaultLanguageVersion = const Version(3, 6);
const Version defaultLanguageVersion = const Version(3, 7);

/// Enum for experimental flags shared between the CFE and the analyzer.
enum ExperimentalFlag {
Expand Down
50 changes: 33 additions & 17 deletions pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,21 @@ class ExpressionPropertyTarget<Expression extends Object>
/// while visiting the code for type inference.
abstract class FlowAnalysis<Node extends Object, Statement extends Node,
Expression extends Node, Variable extends Object, Type extends Object> {
factory FlowAnalysis(FlowAnalysisOperations<Variable, Type> operations,
AssignedVariables<Node, Variable> assignedVariables,
{required bool respectImplicitlyTypedVarInitializers,
required bool fieldPromotionEnabled}) {
return new _FlowAnalysisImpl(operations, assignedVariables,
respectImplicitlyTypedVarInitializers:
respectImplicitlyTypedVarInitializers,
fieldPromotionEnabled: fieldPromotionEnabled);
factory FlowAnalysis(
FlowAnalysisOperations<Variable, Type> operations,
AssignedVariables<Node, Variable> assignedVariables, {
required bool respectImplicitlyTypedVarInitializers,
required bool fieldPromotionEnabled,
required bool inferenceUpdate4Enabled,
}) {
return new _FlowAnalysisImpl(
operations,
assignedVariables,
respectImplicitlyTypedVarInitializers:
respectImplicitlyTypedVarInitializers,
fieldPromotionEnabled: fieldPromotionEnabled,
inferenceUpdate4Enabled: inferenceUpdate4Enabled,
);
}

factory FlowAnalysis.legacy(FlowAnalysisOperations<Variable, Type> operations,
Expand Down Expand Up @@ -1162,13 +1169,17 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
factory FlowAnalysisDebug(FlowAnalysisOperations<Variable, Type> operations,
AssignedVariables<Node, Variable> assignedVariables,
{required bool respectImplicitlyTypedVarInitializers,
required bool fieldPromotionEnabled}) {
required bool fieldPromotionEnabled,
required bool inferenceUpdate4Enabled}) {
print('FlowAnalysisDebug()');
return new FlowAnalysisDebug._(new _FlowAnalysisImpl(
operations, assignedVariables,
respectImplicitlyTypedVarInitializers:
respectImplicitlyTypedVarInitializers,
fieldPromotionEnabled: fieldPromotionEnabled));
operations,
assignedVariables,
respectImplicitlyTypedVarInitializers:
respectImplicitlyTypedVarInitializers,
fieldPromotionEnabled: fieldPromotionEnabled,
inferenceUpdate4Enabled: inferenceUpdate4Enabled,
));
}

factory FlowAnalysisDebug.legacy(
Expand Down Expand Up @@ -4299,6 +4310,8 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,

final bool fieldPromotionEnabled;

final bool inferenceUpdate4Enabled;

@override
final PromotionKeyStore<Variable> promotionKeyStore;

Expand All @@ -4315,10 +4328,13 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
@override
final List<_Reference<Type>> _cascadeTargetStack = [];

_FlowAnalysisImpl(this.operations, this._assignedVariables,
{required this.respectImplicitlyTypedVarInitializers,
required this.fieldPromotionEnabled})
: promotionKeyStore = _assignedVariables.promotionKeyStore {
_FlowAnalysisImpl(
this.operations,
this._assignedVariables, {
required this.respectImplicitlyTypedVarInitializers,
required this.fieldPromotionEnabled,
required this.inferenceUpdate4Enabled,
}) : promotionKeyStore = _assignedVariables.promotionKeyStore {
if (!_assignedVariables.isFinished) {
_assignedVariables.finish();
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/_fe_analyzer_shared/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: _fe_analyzer_shared
version: 74.0.0
version: 75.0.0
description: Logic that is shared between the front_end and analyzer packages.
repository: https://github.com/dart-lang/sdk/tree/main/pkg/_fe_analyzer_shared

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ main() {
FlowAnalysis<Node, Statement, Expression, Var, SharedTypeView<Type>>(
h.typeOperations, AssignedVariables<Node, Var>(),
respectImplicitlyTypedVarInitializers: true,
fieldPromotionEnabled: true);
fieldPromotionEnabled: true,
inferenceUpdate4Enabled: true);
flow.ifStatement_conditionBegin();
flow.ifStatement_thenBegin(e, s);
expect(() => flow.finish(), _asserts);
Expand Down
18 changes: 16 additions & 2 deletions pkg/_fe_analyzer_shared/test/mini_ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,8 @@ class Harness {

bool? _inferenceUpdate3Enabled;

bool? _inferenceUpdate4Enabled;

bool? _patternsEnabled;

Type? _thisType;
Expand Down Expand Up @@ -1703,6 +1705,9 @@ class Harness {
bool get inferenceUpdate3Enabled =>
_inferenceUpdate3Enabled ?? !operations.legacy;

bool get inferenceUpdate4Enabled =>
_inferenceUpdate4Enabled ?? !operations.legacy;

MiniIRBuilder get irBuilder => typeAnalyzer._irBuilder;

bool get patternsEnabled => _patternsEnabled ?? !operations.legacy;
Expand Down Expand Up @@ -1787,6 +1792,11 @@ class Harness {
_inferenceUpdate3Enabled = false;
}

void disableInferenceUpdate4() {
assert(!_started);
_inferenceUpdate4Enabled = false;
}

void disablePatterns() {
assert(!_started);
_patternsEnabled = false;
Expand Down Expand Up @@ -1879,10 +1889,14 @@ class Harness {
SharedTypeView<Type>>.legacy(
operations, visitor._assignedVariables)
: FlowAnalysis<Node, Statement, Expression, Var,
SharedTypeView<Type>>(operations, visitor._assignedVariables,
SharedTypeView<Type>>(
operations,
visitor._assignedVariables,
respectImplicitlyTypedVarInitializers:
_respectImplicitlyTypedVarInitializers,
fieldPromotionEnabled: _fieldPromotionEnabled);
fieldPromotionEnabled: _fieldPromotionEnabled,
inferenceUpdate4Enabled: inferenceUpdate4Enabled,
);
typeAnalyzer.dispatchStatement(b);
typeAnalyzer.finish();
expect(typeAnalyzer.errors._accumulatedErrors, expectedErrors);
Expand Down
4 changes: 3 additions & 1 deletion pkg/analysis_server/doc/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,9 @@ <h4>parameters:</h4><dl><dt class="field"><b>file: <a href="#type_FilePath">File
</dd><dt class="field"><b>lineLength: int<span style="color:#999999"> (optional)</span></b></dt><dd>

<p>
The line length to be used by the formatter.
The line length to be used by the formatter. This value is ignored if a
<tt>formatter.page_width</tt> has been configured in the relevant
<tt>analysis_options.yaml</tt> file.
</p>
</dd></dl><h4>returns:</h4><dl><dt class="field"><b>edits: List&lt;<a href="#type_SourceEdit">SourceEdit</a>&gt;</b></dt><dd>

Expand Down
4 changes: 3 additions & 1 deletion pkg/analysis_server/lib/protocol/protocol_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5830,7 +5830,9 @@ class EditFormatParams implements RequestParams {
/// The length of the current selection in the file.
int selectionLength;

/// The line length to be used by the formatter.
/// The line length to be used by the formatter. This value is ignored if a
/// formatter.page_width has been configured in the relevant
/// analysis_options.yaml file.
int? lineLength;

EditFormatParams(this.file, this.selectionOffset, this.selectionLength,
Expand Down
14 changes: 11 additions & 3 deletions pkg/analysis_server/lib/src/handler/legacy/edit_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:async';
import 'package:analysis_server/protocol/protocol.dart';
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analysis_server/src/handler/legacy/legacy_handler.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:dart_style/src/dart_formatter.dart';
import 'package:dart_style/src/exceptions.dart';
Expand Down Expand Up @@ -50,10 +51,17 @@ class EditFormatHandler extends LegacyHandler {
);

var driver = server.getAnalysisDriver(file);
var library = await driver?.getResolvedLibrary(file);
var unit = await driver?.getResolvedUnit(file);
var (pageWidth, effectiveLanguageVersion) = switch (unit) {
ResolvedUnitResult() => (
unit.analysisOptions.formatterOptions.pageWidth,
unit.libraryElement2.effectiveLanguageVersion,
),
(_) => (null, null),
};
var formatter = DartFormatter(
pageWidth: params.lineLength,
languageVersion: library.effectiveLanguageVersion);
pageWidth: pageWidth ?? params.lineLength,
languageVersion: effectiveLanguageVersion);
SourceCode formattedResult;
try {
formattedResult = formatter.formatSource(code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analysis_server/src/legacy_analysis_server.dart';
import 'package:analysis_server/src/protocol/protocol_internal.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
import 'package:analyzer/src/util/performance/operation_performance.dart';
Expand Down Expand Up @@ -100,6 +101,14 @@ abstract class LegacyHandler {
}
}

extension LibraryElement2Extension on LibraryElement2 {
// TODO(dantup): Remove this once we can use `languageVersion.effective`
// in element-model-migrated files without triggering the lint.
Version get effectiveLanguageVersion {
return languageVersion.effective;
}
}

extension SomeResolvedLibraryResultExtension on SomeResolvedLibraryResult? {
Version get effectiveLanguageVersion {
var self = this;
Expand Down
3 changes: 2 additions & 1 deletion pkg/analysis_server/lib/src/lsp/client_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ class LspResourceClientConfiguration {
true;
}

/// The line length used when formatting documents.
/// The line length used when formatting documents if not specified in
/// `analysis_options.yaml`.
///
/// If null, the formatters default will be used.
int? get lineLength =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FormatOnTypeHandler extends SharedMessageHandler<
}

var lineLength = server.lspClientConfiguration.forResource(path).lineLength;
return generateEditsForFormatting(result, lineLength);
return generateEditsForFormatting(result, defaultPageWidth: lineLength);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class FormatRangeHandler extends SharedMessageHandler<
}

var lineLength = server.lspClientConfiguration.forResource(path).lineLength;
return generateEditsForFormatting(result, lineLength, range: range);
return generateEditsForFormatting(result,
defaultPageWidth: lineLength, range: range);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FormattingHandler
}

var lineLength = server.lspClientConfiguration.forResource(path).lineLength;
return generateEditsForFormatting(result, lineLength);
return generateEditsForFormatting(result, defaultPageWidth: lineLength);
}

@override
Expand Down
22 changes: 17 additions & 5 deletions pkg/analysis_server/lib/src/lsp/source_edits.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,25 @@ ErrorOr<({String content, List<plugin.SourceEdit> edits})>
return ErrorOr.success((content: newContent, edits: serverEdits));
}

/// Generates a list of [TextEdit]s to format the code for [result].
///
/// [defaultPageWidth] will be used as the default page width if [result] does
/// not have an analysis_options file that defines a page width.
///
/// If [range] is provided, only edits that intersect with this range will be
/// returned.
ErrorOr<List<TextEdit>?> generateEditsForFormatting(
ParsedUnitResult result,
int? lineLength, {
ParsedUnitResult result, {
int? defaultPageWidth,
Range? range,
}) {
var unformattedSource = result.content;

// The analysis options page width always takes priority over the default from
// the LSP configuration.
var effectivePageWidth =
result.analysisOptions.formatterOptions.pageWidth ?? defaultPageWidth;

var code = SourceCode(unformattedSource);
SourceCode formattedResult;
try {
Expand All @@ -94,9 +106,9 @@ ErrorOr<List<TextEdit>?> generateEditsForFormatting(
var languageVersion =
result.unit.declaredElement?.library.languageVersion.effective ??
DartFormatter.latestLanguageVersion;
formattedResult =
DartFormatter(pageWidth: lineLength, languageVersion: languageVersion)
.formatSource(code);
var formatter = DartFormatter(
pageWidth: effectivePageWidth, languageVersion: languageVersion);
formattedResult = formatter.formatSource(code);
} on FormatterException {
// If the document fails to parse, just return no edits to avoid the
// use seeing edits on every save with invalid code (if LSP gains the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class AnalysisOptionsGenerator extends YamlCompletionGenerator {
AnalyzerOptions.codeStyle: MapProducer({
AnalyzerOptions.format: BooleanProducer(),
}),
AnalyzerOptions.formatter: MapProducer({
AnalyzerOptions.pageWidth: EmptyProducer(),
}),
// TODO(brianwilkerson): Create a producer to produce `package:` URIs.
AnalyzerOptions.include: EmptyProducer(),
// TODO(brianwilkerson): Create constants for 'linter' and 'rules'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ class BulkFixProcessor {
continue;
}

var formatResult = generateEditsForFormatting(result, null);
var formatResult = generateEditsForFormatting(result);
await formatResult.mapResult((formatResult) async {
var edits = formatResult ?? [];
if (edits.isNotEmpty) {
Expand Down
Loading

0 comments on commit 75bf9e1

Please sign in to comment.