@@ -5,12 +5,13 @@ use std::time::Duration;
5
5
6
6
use ruff_python_ast:: visitor:: Visitor ;
7
7
use ruff_python_ast:: { ModModule , StringLiteral } ;
8
+ use ruff_python_parser:: Parsed ;
8
9
9
10
use crate :: cache:: KeyValueCache ;
10
11
use crate :: db:: { LintDb , LintJar , QueryResult } ;
11
12
use crate :: files:: FileId ;
12
- use crate :: module:: ModuleName ;
13
- use crate :: parse:: { parse, Parsed } ;
13
+ use crate :: module:: { resolve_module , ModuleName } ;
14
+ use crate :: parse:: parse;
14
15
use crate :: source:: { source_text, Source } ;
15
16
use crate :: symbols:: {
16
17
resolve_global_symbol, symbol_table, Definition , GlobalSymbolId , SymbolId , SymbolTable ,
@@ -40,7 +41,7 @@ pub(crate) fn lint_syntax(db: &dyn LintDb, file_id: FileId) -> QueryResult<Diagn
40
41
let parsed = parse ( db. upcast ( ) , * file_id) ?;
41
42
42
43
if parsed. errors ( ) . is_empty ( ) {
43
- let ast = parsed. ast ( ) ;
44
+ let ast = parsed. syntax ( ) ;
44
45
45
46
let mut visitor = SyntaxLintVisitor {
46
47
diagnostics,
@@ -86,7 +87,7 @@ pub(crate) fn lint_semantic(db: &dyn LintDb, file_id: FileId) -> QueryResult<Dia
86
87
let context = SemanticLintContext {
87
88
file_id : * file_id,
88
89
source,
89
- parsed,
90
+ parsed : & parsed ,
90
91
symbols,
91
92
db,
92
93
diagnostics : RefCell :: new ( Vec :: new ( ) ) ,
@@ -144,9 +145,7 @@ fn lint_bad_overrides(context: &SemanticLintContext) -> QueryResult<()> {
144
145
// TODO we should have a special marker on the real typing module (from typeshed) so if you
145
146
// have your own "typing" module in your project, we don't consider it THE typing module (and
146
147
// same for other stdlib modules that our lint rules care about)
147
- let Some ( typing_override) =
148
- resolve_global_symbol ( context. db . upcast ( ) , ModuleName :: new ( "typing" ) , "override" ) ?
149
- else {
148
+ let Some ( typing_override) = context. resolve_global_symbol ( "typing" , "override" ) ? else {
150
149
// TODO once we bundle typeshed, this should be unreachable!()
151
150
return Ok ( ( ) ) ;
152
151
} ;
@@ -194,7 +193,7 @@ fn lint_bad_overrides(context: &SemanticLintContext) -> QueryResult<()> {
194
193
pub struct SemanticLintContext < ' a > {
195
194
file_id : FileId ,
196
195
source : Source ,
197
- parsed : Parsed ,
196
+ parsed : & ' a Parsed < ModModule > ,
198
197
symbols : Arc < SymbolTable > ,
199
198
db : & ' a dyn LintDb ,
200
199
diagnostics : RefCell < Vec < String > > ,
@@ -209,8 +208,8 @@ impl<'a> SemanticLintContext<'a> {
209
208
self . file_id
210
209
}
211
210
212
- pub fn ast ( & self ) -> & ModModule {
213
- self . parsed . ast ( )
211
+ pub fn ast ( & self ) -> & ' a ModModule {
212
+ self . parsed . syntax ( )
214
213
}
215
214
216
215
pub fn symbols ( & self ) -> & SymbolTable {
@@ -234,6 +233,18 @@ impl<'a> SemanticLintContext<'a> {
234
233
pub fn extend_diagnostics ( & mut self , diagnostics : impl IntoIterator < Item = String > ) {
235
234
self . diagnostics . get_mut ( ) . extend ( diagnostics) ;
236
235
}
236
+
237
+ pub fn resolve_global_symbol (
238
+ & self ,
239
+ module : & str ,
240
+ symbol_name : & str ,
241
+ ) -> QueryResult < Option < GlobalSymbolId > > {
242
+ let Some ( module) = resolve_module ( self . db . upcast ( ) , ModuleName :: new ( module) ) ? else {
243
+ return Ok ( None ) ;
244
+ } ;
245
+
246
+ resolve_global_symbol ( self . db . upcast ( ) , module, symbol_name)
247
+ }
237
248
}
238
249
239
250
#[ derive( Debug ) ]
0 commit comments