The owner's first-level cache, realized on the carrier the index already had: DeclLines (name line + detail line) on every Decl/Def, computed at index time from the LineIndex the analysis already holds — tens of KB for 20k modules, FACTS_FORMAT 3->4, old stores discarded whole. A closed file's hover heading now costs zero I/O (it survives the file being deleted), and the snippet's one remaining read is served from a bounded FileView LRU (4 entries / 8 MiB, newest kept, dropped on set_document/close/update_one/rebuild): repeat hovers into a 12 MB file go 5.8 ms -> ~1 us, cross-file hover means 40/157 us -> 4.7/12.9 us. Ports ride the same member entries, so their lines came free. Stale-disk edits leave heading and snippet stale together, the spells_exactly guard still omits rather than lies, and QA pinned the pair. Measured and filed, not fixed here: the first request of a session waits 287-780 ms behind the startup scan (handshake for the next round). Co-Authored-By: Claude Fable 5 <[email protected]>
52 lines
2.2 KiB
Rust
52 lines
2.2 KiB
Rust
//! Turning a `(file, byte span)` pair into an LSP `Location`.
|
|
//!
|
|
//! The workspace index deliberately keeps no file contents
|
|
//! (`docs/features/workspace-index/README.md`), so a span in another file has
|
|
//! to be converted against that file's text, fetched here with the same
|
|
//! open-buffer-beats-disk precedence the index rebuild uses — from the
|
|
//! buffer's own line index when there is one, and otherwise through
|
|
//! `Workspace::file_view`, which reads a closed file at most once per
|
|
//! generation of it rather than once per question about it.
|
|
|
|
use std::path::Path;
|
|
|
|
use lsp_types::Location;
|
|
use vlog_parser::TextRange;
|
|
|
|
use crate::convert::Positions;
|
|
use crate::state::Workspace;
|
|
use crate::uri::path_to_uri;
|
|
|
|
/// The location of a byte span inside a workspace file.
|
|
pub fn location(ws: &Workspace, path: &Path, span: TextRange) -> Option<Location> {
|
|
let uri = path_to_uri(path)?;
|
|
if let Some(doc) = ws.document_for_path(path) {
|
|
return Some(Location { uri, range: doc.positions().range(span) });
|
|
}
|
|
let view = ws.file_view(path)?;
|
|
Some(Location { uri, range: Positions::new(&view.text, &view.lines).range(span) })
|
|
}
|
|
|
|
/// The 1-based line a byte offset falls on, for hover text that names a file
|
|
/// and a line rather than jumping to it.
|
|
///
|
|
/// An open buffer answers from the line index it already carries; a closed
|
|
/// file answers from the shared view cache. **An indexed declaration should
|
|
/// not come here at all** — `Def::lines` already holds its line, recorded when
|
|
/// the file was indexed, and that answer costs nothing
|
|
/// (`docs/features/hover-line-index/README.md`). What is left for this
|
|
/// function is the spans the index records no line for, which today is a
|
|
/// `` `define``'s.
|
|
pub fn line_number(ws: &Workspace, path: &Path, offset: u32) -> Option<u32> {
|
|
if let Some(doc) = ws.document_for_path(path) {
|
|
return Some(doc.line_index.line_col(offset).0);
|
|
}
|
|
Some(ws.file_view(path)?.lines.line_col(offset).0)
|
|
}
|
|
|
|
/// How a file is named in hover text: its file name, which is what a Verilog
|
|
/// author recognizes, since absolute paths in a hover card are unreadable.
|
|
pub fn display_name(path: &Path) -> String {
|
|
path.file_name().and_then(|n| n.to_str()).unwrap_or("?").to_string()
|
|
}
|