Skip to content

Commit

Permalink
add a file property to FileResults
Browse files Browse the repository at this point in the history
Change-Id: Ibec62da4552da3124d85f6020f4e8e1dac8a757b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333588
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Phil Quitslund <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
pq authored and Commit Queue committed Nov 6, 2023
1 parent 9b17a1b commit 18c8a50
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 109 deletions.
11 changes: 7 additions & 4 deletions pkg/analysis_server/lib/src/handler/legacy/edit_get_fixes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class EditGetFixesHandler extends LegacyHandler
var lineInfo = LineInfo.fromContent(content);
var result = engine.ErrorsResultImpl(
session: session,
path: file,
uri: Uri.file(file),
file: optionsFile,
uri: optionsFile.toUri(),
lineInfo: lineInfo,
isAugmentation: false,
isLibrary: true,
Expand Down Expand Up @@ -232,10 +232,13 @@ error.errorCode: ${error.errorCode}
if (fixes.isNotEmpty) {
fixes.sort(Fix.compareFixes);
var lineInfo = LineInfo.fromContent(content);
// TODO(pq) package:analyzer results are specific to *.dart files and we
// shouldn't use them to represent errors in non-Dart files.
// see: https://dart-review.googlesource.com/c/sdk/+/333588
var result = engine.ErrorsResultImpl(
session: session,
path: file,
uri: Uri.file(file),
file: pubspecFile,
uri: pubspecFile.toUri(),
lineInfo: lineInfo,
isAugmentation: false,
isLibrary: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef CodeActionWithPriorityAndIndex = ({
/// A base for classes that produce [CodeAction]s for the LSP handler.
abstract class AbstractCodeActionsProducer
with RequestHandlerMixin<LspAnalysisServer> {
final String path;
final File file;
final LineInfo lineInfo;
final int offset;
final int length;
Expand All @@ -41,7 +41,7 @@ abstract class AbstractCodeActionsProducer

AbstractCodeActionsProducer(
this.server,
this.path,
this.file,
this.lineInfo, {
required this.offset,
required this.length,
Expand All @@ -51,6 +51,8 @@ abstract class AbstractCodeActionsProducer

String get name;

String get path => file.path;

Set<DiagnosticTag> get supportedDiagnosticTags => capabilities.diagnosticTags;

bool get supportsApplyEdit => capabilities.applyEdit;
Expand Down Expand Up @@ -130,7 +132,7 @@ abstract class AbstractCodeActionsProducer
AnalysisSession session, LineInfo lineInfo, List<AnalysisError> errors) {
return engine.ErrorsResultImpl(
session: session,
path: path,
file: file,
uri: server.pathContext.toUri(path),
lineInfo: lineInfo,
isAugmentation: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:yaml/yaml.dart';
class AnalysisOptionsCodeActionsProducer extends AbstractCodeActionsProducer {
AnalysisOptionsCodeActionsProducer(
super.server,
super.path,
super.file,
super.lineInfo, {
required super.offset,
required super.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {

DartCodeActionsProducer(
super.server,
super.path,
super.file,
super.lineInfo,
this.docIdentifier,
this.library,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class PluginCodeActionsProducer extends AbstractCodeActionsProducer {

PluginCodeActionsProducer(
super.server,
super.path,
super.file,
super.lineInfo, {
required super.offset,
required super.length,
required super.shouldIncludeKind,
required super.capabilities,
}) : driver = server.getAnalysisDriver(path);
}) : driver = server.getAnalysisDriver(file.path);

@override
String get name => 'PluginActionsComputer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:yaml/yaml.dart';
class PubspecCodeActionsProducer extends AbstractCodeActionsProducer {
PubspecCodeActionsProducer(
super.server,
super.path,
super.file,
super.lineInfo, {
required super.offset,
required super.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class CodeActionHandler
if (isDart && libraryResult != null && unit != null)
DartCodeActionsProducer(
server,
unitPath,
unit.file,
lineInfo,
docIdentifier,
range: params.range,
Expand All @@ -160,7 +160,8 @@ class CodeActionHandler
if (isPubspec)
PubspecCodeActionsProducer(
server,
unitPath,
// TODO(pq) can we do better?
server.resourceProvider.getFile(unitPath),
lineInfo,
offset: offset,
length: length,
Expand All @@ -170,7 +171,8 @@ class CodeActionHandler
if (isAnalysisOptions)
AnalysisOptionsCodeActionsProducer(
server,
unitPath,
// TODO(pq) can we do better?
server.resourceProvider.getFile(unitPath),
lineInfo,
offset: offset,
length: length,
Expand All @@ -179,7 +181,8 @@ class CodeActionHandler
),
PluginCodeActionsProducer(
server,
unitPath,
// TODO(pq) can we do better?
server.resourceProvider.getFile(unitPath),
lineInfo,
offset: offset,
length: length,
Expand Down
4 changes: 4 additions & 0 deletions pkg/analyzer/lib/dart/analysis/results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type_provider.dart';
import 'package:analyzer/dart/element/type_system.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/generated/source.dart';

/// The result of performing some kind of analysis on a single file. Every
Expand Down Expand Up @@ -83,6 +84,9 @@ abstract class ErrorsResult
///
/// Clients may not extend, implement or mix-in this class.
abstract class FileResult implements SomeFileResult, AnalysisResult {
/// The file resource.
File get file;

/// Whether the file is a library augmentation.
/// When `true`, [isLibrary] and [isPart] are `false`.
bool get isAugmentation;
Expand Down
46 changes: 9 additions & 37 deletions pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -747,12 +747,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
FileState file = _fsState.getFileForPath(path);
return FileResultImpl(
session: currentSession,
path: path,
uri: file.uri,
lineInfo: file.lineInfo,
isAugmentation: file.kind is AugmentationFileKind,
isLibrary: file.kind is LibraryFileKind,
isPart: file.kind is PartFileKind,
fileState: file,
);
}

Expand Down Expand Up @@ -1046,13 +1041,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
CompilationUnit unit = file.parse(listener);
return ParsedUnitResultImpl(
session: currentSession,
path: file.path,
uri: file.uri,
content: file.content,
lineInfo: file.lineInfo,
isAugmentation: file.kind is AugmentationFileKind,
isLibrary: file.kind is LibraryFileKind,
isPart: file.kind is PartFileKind,
fileState: file,
unit: unit,
errors: listener.errors,
);
Expand Down Expand Up @@ -1540,12 +1529,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
var element = libraryContext.computeUnitElement(library, file);
return UnitElementResultImpl(
session: currentSession,
path: path,
uri: file.uri,
lineInfo: file.lineInfo,
isAugmentation: file.kind is AugmentationFileKind,
isLibrary: file.kind is LibraryFileKind,
isPart: file.kind is PartFileKind,
fileState: file,
element: element,
);
});
Expand All @@ -1557,9 +1541,9 @@ class AnalysisDriver implements AnalysisDriverGeneric {
}) {
return ErrorsResultImpl(
session: currentSession,
path: file.path,
uri: file.uri,
file: file.resource,
lineInfo: file.lineInfo,
uri: file.uri,
isAugmentation: file.kind is AugmentationFileKind,
isLibrary: file.kind is LibraryFileKind,
isPart: file.kind is PartFileKind,
Expand Down Expand Up @@ -1611,14 +1595,8 @@ class AnalysisDriver implements AnalysisDriverGeneric {
}) {
return ResolvedUnitResultImpl(
session: currentSession,
path: file.path,
uri: file.uri,
exists: file.exists,
fileState: file,
content: file.content,
lineInfo: file.lineInfo,
isAugmentation: file.kind is AugmentationFileKind,
isLibrary: file.kind is LibraryFileKind,
isPart: file.kind is PartFileKind,
unit: unitResult.unit,
errors: unitResult.errors,
);
Expand Down Expand Up @@ -1723,14 +1701,8 @@ class AnalysisDriver implements AnalysisDriverGeneric {
if (content != null && resolvedUnit != null) {
var resolvedUnitResult = ResolvedUnitResultImpl(
session: currentSession,
path: file.path,
uri: file.uri,
exists: file.exists,
fileState: file,
content: content,
lineInfo: file.lineInfo,
isAugmentation: file.kind is AugmentationFileKind,
isLibrary: file.kind is LibraryFileKind,
isPart: file.kind is PartFileKind,
unit: resolvedUnit,
errors: errors,
);
Expand Down Expand Up @@ -1815,9 +1787,9 @@ class AnalysisDriver implements AnalysisDriverGeneric {
// TODO(scheglov) Find a better way to report this.
var errorsResult = ErrorsResultImpl(
session: currentSession,
path: file.path,
uri: file.uri,
file: file.resource,
lineInfo: file.lineInfo,
uri: file.uri,
isAugmentation: file.kind is AugmentationFileKind,
isLibrary: file.kind is LibraryFileKind,
isPart: file.kind is PartFileKind,
Expand Down
Loading

0 comments on commit 18c8a50

Please sign in to comment.