Skip to content

Commit

Permalink
Elements. Include analyzer_use_new_elements.txt into the resolved uni…
Browse files Browse the repository at this point in the history
…t signature.

So, when we update this file and restart DAS, we recompute diagnostics.
To prevent stale lint about using old element model.

Change-Id: I4e27231d4fb4d40c181c13e4fa9b81de395b3232
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387609
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Oct 1, 2024
1 parent 6c631c4 commit 1ae08e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
8 changes: 4 additions & 4 deletions pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import 'package:meta/meta.dart';
// TODO(scheglov): Clean up the list of implicitly analyzed files.
class AnalysisDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 387;
static const int DATA_VERSION = 388;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down Expand Up @@ -1840,9 +1840,9 @@ class AnalysisDriver {
String _getResolvedUnitSignature(LibraryFileKind library, FileState file) {
ApiSignature signature = ApiSignature();
signature.addUint32List(_saltForResolution);
if (file.workspacePackage is PubPackage) {
signature.addString(
(file.workspacePackage as PubPackage).pubspecContent ?? '');
if (file.workspacePackage case PubPackage pubPackage) {
signature.addString(pubPackage.pubspecContent ?? '');
signature.addString(pubPackage.analyzerUseNewElementsContent ?? '');
}
signature.addString(library.file.uriStr);
signature.addString(library.libraryCycle.apiSignature);
Expand Down
45 changes: 33 additions & 12 deletions pkg/analyzer/lib/src/workspace/pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ import 'package:meta/meta.dart';
import 'package:path/path.dart';
import 'package:pub_semver/pub_semver.dart';

/// Return the content of the [file], `null` if cannot be read.
String? _fileContentOrNull(File file) {
try {
return file.readAsStringSync();
} catch (_) {
return null;
}
}

/// Check if the given list of path components contains a package build
/// generated directory, it would have the following path segments,
/// '.dart_tool/build/generated'.
Expand Down Expand Up @@ -356,15 +365,6 @@ class PackageConfigWorkspace extends SimpleWorkspace {
return null;
}

/// Return the content of the [file], `null` if cannot be read.
static String? _fileContentOrNull(File file) {
try {
return file.readAsStringSync();
} catch (_) {
return null;
}
}

/// See https://buganizer.corp.google.com/issues/273584249
///
/// Check if `/home/workspace/third_party/dart/my/pubspec.yaml`
Expand Down Expand Up @@ -398,6 +398,9 @@ class PubPackage extends WorkspacePackage {

final String? pubspecContent;

// TODO(scheglov): remove when we are done migrating
final String? analyzerUseNewElementsContent;

final Pubspec? pubspec;

final File pubspecFile;
Expand All @@ -416,11 +419,29 @@ class PubPackage extends WorkspacePackage {
var pubspec = Pubspec.parse(pubspecContent);
var packageName = pubspec.name?.value.text;
return PubPackage._(
root, workspace, pubspecContent, pubspecFile, pubspec, packageName);
root,
workspace,
pubspecContent,
pubspecFile,
pubspec,
packageName,
analyzerUseNewElementsContent: _fileContentOrNull(
pubspecFile.parent.getChildAssumingFile(
'analyzer_use_new_elements.txt',
),
),
);
}

PubPackage._(this.root, this.workspace, this.pubspecContent, this.pubspecFile,
this.pubspec, this._name);
PubPackage._(
this.root,
this.workspace,
this.pubspecContent,
this.pubspecFile,
this.pubspec,
this._name, {
required this.analyzerUseNewElementsContent,
});

/// The version range for the SDK specified for this package , or `null` if
/// it is ill-formatted or not set.
Expand Down

0 comments on commit 1ae08e9

Please sign in to comment.