Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern crate rustc_driver as _;

pub use salsa;
pub use salsa_macros;
use span::TextSize;

// FIXME: Rename this crate, base db is non descriptive
mod change;
Expand Down Expand Up @@ -280,6 +281,8 @@ pub trait SourceDatabase: salsa::Database {
fn crates_map(&self) -> Arc<CratesMap>;

fn nonce_and_revision(&self) -> (Nonce, salsa::Revision);

fn line_column(&self, file: FileId, offset: TextSize) -> Result<(u32, u32), ()>;
}

static NEXT_NONCE: AtomicUsize = AtomicUsize::new(0);
Expand Down
4 changes: 4 additions & 0 deletions crates/hir-def/src/test_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ impl SourceDatabase for TestDB {
fn nonce_and_revision(&self) -> (Nonce, salsa::Revision) {
(self.nonce, salsa::plumbing::ZalsaDatabase::zalsa(self).current_revision())
}

fn line_column(&self, _file: FileId, _offset: syntax::TextSize) -> Result<(u32, u32), ()> {
Err(())
}
}

impl TestDB {
Expand Down
4 changes: 4 additions & 0 deletions crates/hir-ty/src/test_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ impl SourceDatabase for TestDB {
fn nonce_and_revision(&self) -> (Nonce, salsa::Revision) {
(self.nonce, salsa::plumbing::ZalsaDatabase::zalsa(self).current_revision())
}

fn line_column(&self, _file: FileId, _offset: syntax::TextSize) -> Result<(u32, u32), ()> {
Err(())
}
}

#[salsa_macros::db]
Expand Down
4 changes: 4 additions & 0 deletions crates/ide-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ impl SourceDatabase for RootDatabase {
fn nonce_and_revision(&self) -> (Nonce, salsa::Revision) {
(self.nonce, salsa::plumbing::ZalsaDatabase::zalsa(self).current_revision())
}

fn line_column(&self, file: FileId, offset: syntax::TextSize) -> Result<(u32, u32), ()> {
line_index(self, file).try_line_col(offset).map(|lc| (lc.line, lc.col)).ok_or(())
}
}

impl Default for RootDatabase {
Expand Down
8 changes: 3 additions & 5 deletions crates/load-cargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,9 @@ impl ProcMacroExpander for Expander {
SubRequest::LineColumn { file_id, ast_id, offset } => {
let range =
resolve_sub_span(db, file_id, ast_id, TextRange::empty(TextSize::from(offset)));
let source = db.file_text(range.file_id.file_id(db)).text(db);
let line_index = ide_db::line_index::LineIndex::new(source);
let (line, column) = line_index
.try_line_col(range.range.start())
.map(|lc| (lc.line + 1, lc.col + 1))
let (line, column) = db
.line_column(range.file_id.file_id(db), range.range.start())
.map(|(line, col)| (line + 1, col + 1))
.unwrap_or((1, 1));
// proc_macro::Span line/column are 1-based
Ok(SubResponse::LineColumnResult { line, column })
Expand Down