Skip to content

Commit 18c8a50

Browse files
pqCommit Queue
authored and
Commit Queue
committed
add a file property to FileResults
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]>
1 parent 9b17a1b commit 18c8a50

File tree

13 files changed

+101
-109
lines changed

13 files changed

+101
-109
lines changed

pkg/analysis_server/lib/src/handler/legacy/edit_get_fixes.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class EditGetFixesHandler extends LegacyHandler
123123
var lineInfo = LineInfo.fromContent(content);
124124
var result = engine.ErrorsResultImpl(
125125
session: session,
126-
path: file,
127-
uri: Uri.file(file),
126+
file: optionsFile,
127+
uri: optionsFile.toUri(),
128128
lineInfo: lineInfo,
129129
isAugmentation: false,
130130
isLibrary: true,
@@ -232,10 +232,13 @@ error.errorCode: ${error.errorCode}
232232
if (fixes.isNotEmpty) {
233233
fixes.sort(Fix.compareFixes);
234234
var lineInfo = LineInfo.fromContent(content);
235+
// TODO(pq) package:analyzer results are specific to *.dart files and we
236+
// shouldn't use them to represent errors in non-Dart files.
237+
// see: https://dart-review.googlesource.com/c/sdk/+/333588
235238
var result = engine.ErrorsResultImpl(
236239
session: session,
237-
path: file,
238-
uri: Uri.file(file),
240+
file: pubspecFile,
241+
uri: pubspecFile.toUri(),
239242
lineInfo: lineInfo,
240243
isAugmentation: false,
241244
isLibrary: true,

pkg/analysis_server/lib/src/lsp/handlers/code_actions/abstract_code_actions_producer.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef CodeActionWithPriorityAndIndex = ({
2929
/// A base for classes that produce [CodeAction]s for the LSP handler.
3030
abstract class AbstractCodeActionsProducer
3131
with RequestHandlerMixin<LspAnalysisServer> {
32-
final String path;
32+
final File file;
3333
final LineInfo lineInfo;
3434
final int offset;
3535
final int length;
@@ -41,7 +41,7 @@ abstract class AbstractCodeActionsProducer
4141

4242
AbstractCodeActionsProducer(
4343
this.server,
44-
this.path,
44+
this.file,
4545
this.lineInfo, {
4646
required this.offset,
4747
required this.length,
@@ -51,6 +51,8 @@ abstract class AbstractCodeActionsProducer
5151

5252
String get name;
5353

54+
String get path => file.path;
55+
5456
Set<DiagnosticTag> get supportedDiagnosticTags => capabilities.diagnosticTags;
5557

5658
bool get supportsApplyEdit => capabilities.applyEdit;
@@ -130,7 +132,7 @@ abstract class AbstractCodeActionsProducer
130132
AnalysisSession session, LineInfo lineInfo, List<AnalysisError> errors) {
131133
return engine.ErrorsResultImpl(
132134
session: session,
133-
path: path,
135+
file: file,
134136
uri: server.pathContext.toUri(path),
135137
lineInfo: lineInfo,
136138
isAugmentation: false,

pkg/analysis_server/lib/src/lsp/handlers/code_actions/analysis_options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'package:yaml/yaml.dart';
1616
class AnalysisOptionsCodeActionsProducer extends AbstractCodeActionsProducer {
1717
AnalysisOptionsCodeActionsProducer(
1818
super.server,
19-
super.path,
19+
super.file,
2020
super.lineInfo, {
2121
required super.offset,
2222
required super.length,

pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
3434

3535
DartCodeActionsProducer(
3636
super.server,
37-
super.path,
37+
super.file,
3838
super.lineInfo,
3939
this.docIdentifier,
4040
this.library,

pkg/analysis_server/lib/src/lsp/handlers/code_actions/plugins.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class PluginCodeActionsProducer extends AbstractCodeActionsProducer {
1818

1919
PluginCodeActionsProducer(
2020
super.server,
21-
super.path,
21+
super.file,
2222
super.lineInfo, {
2323
required super.offset,
2424
required super.length,
2525
required super.shouldIncludeKind,
2626
required super.capabilities,
27-
}) : driver = server.getAnalysisDriver(path);
27+
}) : driver = server.getAnalysisDriver(file.path);
2828

2929
@override
3030
String get name => 'PluginActionsComputer';

pkg/analysis_server/lib/src/lsp/handlers/code_actions/pubspec.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'package:yaml/yaml.dart';
1515
class PubspecCodeActionsProducer extends AbstractCodeActionsProducer {
1616
PubspecCodeActionsProducer(
1717
super.server,
18-
super.path,
18+
super.file,
1919
super.lineInfo, {
2020
required super.offset,
2121
required super.length,

pkg/analysis_server/lib/src/lsp/handlers/handler_code_actions.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class CodeActionHandler
145145
if (isDart && libraryResult != null && unit != null)
146146
DartCodeActionsProducer(
147147
server,
148-
unitPath,
148+
unit.file,
149149
lineInfo,
150150
docIdentifier,
151151
range: params.range,
@@ -160,7 +160,8 @@ class CodeActionHandler
160160
if (isPubspec)
161161
PubspecCodeActionsProducer(
162162
server,
163-
unitPath,
163+
// TODO(pq) can we do better?
164+
server.resourceProvider.getFile(unitPath),
164165
lineInfo,
165166
offset: offset,
166167
length: length,
@@ -170,7 +171,8 @@ class CodeActionHandler
170171
if (isAnalysisOptions)
171172
AnalysisOptionsCodeActionsProducer(
172173
server,
173-
unitPath,
174+
// TODO(pq) can we do better?
175+
server.resourceProvider.getFile(unitPath),
174176
lineInfo,
175177
offset: offset,
176178
length: length,
@@ -179,7 +181,8 @@ class CodeActionHandler
179181
),
180182
PluginCodeActionsProducer(
181183
server,
182-
unitPath,
184+
// TODO(pq) can we do better?
185+
server.resourceProvider.getFile(unitPath),
183186
lineInfo,
184187
offset: offset,
185188
length: length,

pkg/analyzer/lib/dart/analysis/results.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:analyzer/dart/element/element.dart';
88
import 'package:analyzer/dart/element/type_provider.dart';
99
import 'package:analyzer/dart/element/type_system.dart';
1010
import 'package:analyzer/error/error.dart';
11+
import 'package:analyzer/file_system/file_system.dart';
1112
import 'package:analyzer/src/generated/source.dart';
1213

1314
/// The result of performing some kind of analysis on a single file. Every
@@ -83,6 +84,9 @@ abstract class ErrorsResult
8384
///
8485
/// Clients may not extend, implement or mix-in this class.
8586
abstract class FileResult implements SomeFileResult, AnalysisResult {
87+
/// The file resource.
88+
File get file;
89+
8690
/// Whether the file is a library augmentation.
8791
/// When `true`, [isLibrary] and [isPart] are `false`.
8892
bool get isAugmentation;

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
747747
FileState file = _fsState.getFileForPath(path);
748748
return FileResultImpl(
749749
session: currentSession,
750-
path: path,
751-
uri: file.uri,
752-
lineInfo: file.lineInfo,
753-
isAugmentation: file.kind is AugmentationFileKind,
754-
isLibrary: file.kind is LibraryFileKind,
755-
isPart: file.kind is PartFileKind,
750+
fileState: file,
756751
);
757752
}
758753

@@ -1046,13 +1041,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
10461041
CompilationUnit unit = file.parse(listener);
10471042
return ParsedUnitResultImpl(
10481043
session: currentSession,
1049-
path: file.path,
1050-
uri: file.uri,
1051-
content: file.content,
1052-
lineInfo: file.lineInfo,
1053-
isAugmentation: file.kind is AugmentationFileKind,
1054-
isLibrary: file.kind is LibraryFileKind,
1055-
isPart: file.kind is PartFileKind,
1044+
fileState: file,
10561045
unit: unit,
10571046
errors: listener.errors,
10581047
);
@@ -1540,12 +1529,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
15401529
var element = libraryContext.computeUnitElement(library, file);
15411530
return UnitElementResultImpl(
15421531
session: currentSession,
1543-
path: path,
1544-
uri: file.uri,
1545-
lineInfo: file.lineInfo,
1546-
isAugmentation: file.kind is AugmentationFileKind,
1547-
isLibrary: file.kind is LibraryFileKind,
1548-
isPart: file.kind is PartFileKind,
1532+
fileState: file,
15491533
element: element,
15501534
);
15511535
});
@@ -1557,9 +1541,9 @@ class AnalysisDriver implements AnalysisDriverGeneric {
15571541
}) {
15581542
return ErrorsResultImpl(
15591543
session: currentSession,
1560-
path: file.path,
1561-
uri: file.uri,
1544+
file: file.resource,
15621545
lineInfo: file.lineInfo,
1546+
uri: file.uri,
15631547
isAugmentation: file.kind is AugmentationFileKind,
15641548
isLibrary: file.kind is LibraryFileKind,
15651549
isPart: file.kind is PartFileKind,
@@ -1611,14 +1595,8 @@ class AnalysisDriver implements AnalysisDriverGeneric {
16111595
}) {
16121596
return ResolvedUnitResultImpl(
16131597
session: currentSession,
1614-
path: file.path,
1615-
uri: file.uri,
1616-
exists: file.exists,
1598+
fileState: file,
16171599
content: file.content,
1618-
lineInfo: file.lineInfo,
1619-
isAugmentation: file.kind is AugmentationFileKind,
1620-
isLibrary: file.kind is LibraryFileKind,
1621-
isPart: file.kind is PartFileKind,
16221600
unit: unitResult.unit,
16231601
errors: unitResult.errors,
16241602
);
@@ -1723,14 +1701,8 @@ class AnalysisDriver implements AnalysisDriverGeneric {
17231701
if (content != null && resolvedUnit != null) {
17241702
var resolvedUnitResult = ResolvedUnitResultImpl(
17251703
session: currentSession,
1726-
path: file.path,
1727-
uri: file.uri,
1728-
exists: file.exists,
1704+
fileState: file,
17291705
content: content,
1730-
lineInfo: file.lineInfo,
1731-
isAugmentation: file.kind is AugmentationFileKind,
1732-
isLibrary: file.kind is LibraryFileKind,
1733-
isPart: file.kind is PartFileKind,
17341706
unit: resolvedUnit,
17351707
errors: errors,
17361708
);
@@ -1815,9 +1787,9 @@ class AnalysisDriver implements AnalysisDriverGeneric {
18151787
// TODO(scheglov) Find a better way to report this.
18161788
var errorsResult = ErrorsResultImpl(
18171789
session: currentSession,
1818-
path: file.path,
1819-
uri: file.uri,
1790+
file: file.resource,
18201791
lineInfo: file.lineInfo,
1792+
uri: file.uri,
18211793
isAugmentation: file.kind is AugmentationFileKind,
18221794
isLibrary: file.kind is LibraryFileKind,
18231795
isPart: file.kind is PartFileKind,

0 commit comments

Comments
 (0)