1
1
import 'package:analyzer/dart/ast/ast.dart' ;
2
2
import 'package:analyzer/dart/ast/visitor.dart' ;
3
3
import 'package:analyzer/dart/element/element.dart' ;
4
+ import 'package:analyzer/error/error.dart' ;
4
5
import 'package:analyzer/source/line_info.dart' ;
5
6
import 'package:package_config/package_config.dart' ;
6
7
import 'package:pubspec_parse/pubspec_parse.dart' ;
@@ -17,6 +18,7 @@ class ScipVisitor extends GeneralizingAstVisitor {
17
18
final String _relativePath;
18
19
final String _projectRoot;
19
20
final LineInfo _lineInfo;
21
+ final List <AnalysisError > _analysisErrors;
20
22
21
23
final SymbolGenerator _symbolGenerator;
22
24
@@ -27,6 +29,7 @@ class ScipVisitor extends GeneralizingAstVisitor {
27
29
this ._relativePath,
28
30
this ._projectRoot,
29
31
this ._lineInfo,
32
+ this ._analysisErrors,
30
33
PackageConfig packageConfig,
31
34
Pubspec pubspec,
32
35
) : _symbolGenerator = SymbolGenerator (
@@ -71,6 +74,7 @@ class ScipVisitor extends GeneralizingAstVisitor {
71
74
72
75
_registerAsDefinition (
73
76
element,
77
+ node,
74
78
relationships: relationships,
75
79
);
76
80
}
@@ -91,12 +95,13 @@ class ScipVisitor extends GeneralizingAstVisitor {
91
95
final fieldElement = (element as FieldFormalParameterElement ).field;
92
96
_registerAsReference (
93
97
fieldElement! ,
98
+ node,
94
99
offset: node.thisKeyword.offset,
95
100
length: node.thisKeyword.length,
96
101
);
97
102
}
98
103
99
- _registerAsDefinition (element);
104
+ _registerAsDefinition (element, node );
100
105
}
101
106
102
107
void _visitSimpleIdentifier (SimpleIdentifier node) {
@@ -135,10 +140,11 @@ class ScipVisitor extends GeneralizingAstVisitor {
135
140
if (element == null || element.source == null ) return ;
136
141
137
142
if (node.inDeclarationContext ()) {
138
- _registerAsDefinition (element);
143
+ _registerAsDefinition (element, node );
139
144
} else {
140
145
_registerAsReference (
141
146
element,
147
+ node,
142
148
offset: node.offset,
143
149
length: node.name.length,
144
150
);
@@ -153,22 +159,25 @@ class ScipVisitor extends GeneralizingAstVisitor {
153
159
/// If [element] exists outside of the projects source, it will be added to the
154
160
/// [globalExternalSymbols] .
155
161
void _registerAsReference (
156
- Element element, {
162
+ Element element,
163
+ AstNode node, {
157
164
required int offset,
158
165
required int length,
159
166
}) {
160
167
final symbol = _symbolGenerator.symbolFor (element);
161
168
if (symbol != null ) {
169
+ final meta = getSymbolMetadata (element, node, _analysisErrors);
162
170
occurrences.add (Occurrence (
163
171
range: _lineInfo.getRange (offset, length),
164
172
symbol: symbol,
173
+ diagnostics: meta.diagnostics,
165
174
));
166
175
167
176
if (! element.source! .fullName.startsWith (_projectRoot)) {
168
177
if (! globalExternalSymbols.any (
169
178
(symbolInfo) => symbolInfo.symbol == symbol,
170
179
)) {
171
- final meta = getSymbolMetadata (element);
180
+ final meta = getSymbolMetadata (element, node, _analysisErrors );
172
181
globalExternalSymbols.add (SymbolInformation (
173
182
symbol: symbol,
174
183
documentation: meta.documentation,
@@ -183,12 +192,13 @@ class ScipVisitor extends GeneralizingAstVisitor {
183
192
/// This adds both a symbol, and an occurrence for the element and it's
184
193
/// name
185
194
void _registerAsDefinition (
186
- Element element, {
195
+ Element element,
196
+ AstNode node, {
187
197
List <Relationship >? relationships,
188
198
}) {
189
199
final symbol = _symbolGenerator.symbolFor (element);
190
200
if (symbol != null ) {
191
- final meta = getSymbolMetadata (element);
201
+ final meta = getSymbolMetadata (element, node, _analysisErrors );
192
202
symbols.add (SymbolInformation (
193
203
symbol: symbol,
194
204
documentation: meta.documentation,
@@ -199,6 +209,7 @@ class ScipVisitor extends GeneralizingAstVisitor {
199
209
range: _lineInfo.getRange (element.nameOffset, element.nameLength),
200
210
symbol: symbol,
201
211
symbolRoles: SymbolRole .Definition .value,
212
+ diagnostics: meta.diagnostics,
202
213
));
203
214
}
204
215
}
0 commit comments