Skip to content

Commit 5780d2b

Browse files
gkorlandCopilot
andcommitted
fix(analyzers): guard against KeyError for ignored files in second_pass
Files skipped by first_pass() via the ignore list are not added to self.files, but second_pass() iterated the same files list and dereferenced self.files[file_path] unconditionally. This would raise KeyError for any ignored file. Add a membership check before accessing self.files and reorder the guards so both the membership check and NullLanguageServer skip happen before dereferencing. Addresses review comment: coderabbitai suggested adding a guard to skip files not in self.files before indexing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent bbad52d commit 5780d2b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

api/analyzers/source_analyzer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,13 @@ def second_pass(self, graph: Graph, files: list[Path], path: Path) -> None:
149149
with lsps[".java"].start_server(), lsps[".py"].start_server(), lsps[".cs"].start_server(), lsps[".js"].start_server():
150150
files_len = len(self.files)
151151
for i, file_path in enumerate(files):
152-
file = self.files[file_path]
153-
logging.info(f'Processing file ({i + 1}/{files_len}): {file_path}')
152+
if file_path not in self.files:
153+
continue
154154
# Skip symbol resolution when no real LSP is available
155155
if isinstance(lsps.get(file_path.suffix), NullLanguageServer):
156156
continue
157+
file = self.files[file_path]
158+
logging.info(f'Processing file ({i + 1}/{files_len}): {file_path}')
157159
for _, entity in file.entities.items():
158160
entity.resolved_symbol(lambda key, symbol, fp=file_path: analyzers[fp.suffix].resolve_symbol(self.files, lsps[fp.suffix], fp, path, key, symbol))
159161
for key, symbols in entity.symbols.items():

0 commit comments

Comments
 (0)