@@ -125,26 +125,36 @@ def resolve_symbol(self, files: dict[Path, File], lsp: SyncLanguageServer, file_
125125 def add_file_imports (self , file : File ) -> None :
126126 """
127127 Extract and add import statements from the file.
128- """
129- import warnings
130- with warnings .catch_warnings ():
131- warnings .simplefilter ("ignore" )
132- # Query for both import types
133- import_query = self .language .query ("""
134- (import_statement) @import
135- (import_from_statement) @import_from
136- """ )
137-
138- captures = import_query .captures (file .tree .root_node )
139-
140- # Add all import statement nodes to the file
141- if 'import' in captures :
142- for import_node in captures ['import' ]:
143- file .add_import (import_node )
144128
145- if 'import_from' in captures :
146- for import_node in captures ['import_from' ]:
147- file .add_import (import_node )
129+ Supports:
130+ - import module
131+ - import module as alias
132+ - from module import name
133+ - from module import name1, name2
134+ - from module import name as alias
135+ """
136+ try :
137+ import warnings
138+ with warnings .catch_warnings ():
139+ warnings .simplefilter ("ignore" )
140+ # Query for both import types
141+ import_query = self .language .query ("""
142+ (import_statement) @import
143+ (import_from_statement) @import_from
144+ """ )
145+
146+ captures = import_query .captures (file .tree .root_node )
147+
148+ # Add all import statement nodes to the file
149+ if 'import' in captures :
150+ for import_node in captures ['import' ]:
151+ file .add_import (import_node )
152+
153+ if 'import_from' in captures :
154+ for import_node in captures ['import_from' ]:
155+ file .add_import (import_node )
156+ except Exception as e :
157+ logger .debug (f"Failed to extract imports from { file .path } : { e } " )
148158
149159 def resolve_import (self , files : dict [Path , File ], lsp : SyncLanguageServer , file_path : Path , path : Path , import_node : Node ) -> list [Entity ]:
150160 """
0 commit comments