[red-knot] Add filename and source location for diagnostics (#12842)

## Summary

I'm not sure if this is useful but this is a hacky implementation to add
the filename and row / column numbers to the current Red Knot
diagnostics.
This commit is contained in:
Dhruv Manilawala 2024-08-12 21:26:30 +05:30 committed by GitHub
parent 540023262e
commit 99dc208b00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 74 additions and 12 deletions

View file

@ -1,6 +1,8 @@
use ruff_db::files::File;
use ruff_db::files::{File, FilePath};
use ruff_db::source::line_index;
use ruff_python_ast as ast;
use ruff_python_ast::{Expr, ExpressionRef, StmtClassDef};
use ruff_source_file::LineIndex;
use crate::module_name::ModuleName;
use crate::module_resolver::{resolve_module, Module};
@ -25,6 +27,14 @@ impl<'db> SemanticModel<'db> {
self.db
}
pub fn file_path(&self) -> &FilePath {
self.file.path(self.db)
}
pub fn line_index(&self) -> LineIndex {
line_index(self.db.upcast(), self.file)
}
pub fn resolve_module(&self, module_name: ModuleName) -> Option<Module> {
resolve_module(self.db, module_name)
}