Skip to content

Commit 26f55c8

Browse files
committed
Address code review
1 parent 49d3d49 commit 26f55c8

2 files changed

Lines changed: 38 additions & 37 deletions

File tree

crates/ark/src/lsp/indexer.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
use std::result::Result::Ok;
99
use std::sync::LazyLock;
1010

11+
use aether_lsp_utils::proto::to_proto;
12+
use aether_lsp_utils::proto::PositionEncoding;
13+
use aether_path::FilePath;
1114
use oak_db::File;
1215
use regex::Regex;
16+
use stdext::result::ResultExt;
1317
use stdext::unwrap;
1418
use stdext::unwrap::IntoResult;
19+
use tower_lsp::lsp_types::Range;
1520
use tree_sitter::Node;
1621
use tree_sitter::Query;
1722
use url::Url;
@@ -47,7 +52,7 @@ pub enum IndexEntryData {
4752
/// A position in a file as a tree-sitter point: zero-based row, and column in
4853
/// bytes within that row. Encoding-free, so the per-file index stays a pure
4954
/// salsa query. Consumers that need an LSP position convert via the file's
50-
/// line index and the session encoding (see `symbols.rs`).
55+
/// line index and the session encoding (see `index_range_to_lsp_range`).
5156
#[derive(Clone, Copy, Debug, PartialEq, Eq, salsa::Update)]
5257
pub struct IndexPoint {
5358
pub row: u32,
@@ -76,6 +81,37 @@ pub struct IndexEntry {
7681
pub data: IndexEntryData,
7782
}
7883

84+
/// Convert an index entry's tree-sitter point range to an LSP range, resolving
85+
/// the file's line index from the db. Returns `None` if the file is no longer
86+
/// in the db or the points fall outside it, in which case the symbol is
87+
/// dropped from the results.
88+
pub(crate) fn index_range_to_lsp_range(
89+
db: &dyn ArkDb,
90+
uri: &Url,
91+
range: IndexRange,
92+
encoding: PositionEncoding,
93+
) -> Option<Range> {
94+
let file = db.file_by_path(&FilePath::from_url(uri))?;
95+
let line_index = file.line_index(db);
96+
97+
let to_position = |point: IndexPoint| {
98+
to_proto::position_from_line_col(
99+
biome_line_index::LineCol {
100+
line: point.row,
101+
col: point.column,
102+
},
103+
line_index,
104+
encoding,
105+
)
106+
.log_err()
107+
};
108+
109+
Some(Range::new(
110+
to_position(range.start)?,
111+
to_position(range.end)?,
112+
))
113+
}
114+
79115
pub static RE_COMMENT_SECTION: LazyLock<Regex> =
80116
LazyLock::new(|| Regex::new(r"^\s*(#+)\s*(.*?)\s*[#=-]{4,}\s*$").unwrap());
81117

crates/ark/src/lsp/symbols.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
use std::result::Result::Ok;
1111

12-
use aether_lsp_utils::proto::to_proto;
13-
use aether_lsp_utils::proto::PositionEncoding;
14-
use aether_path::FilePath;
1512
use stdext::unwrap::IntoResult;
1613
use tower_lsp::lsp_types::DocumentSymbol;
1714
use tower_lsp::lsp_types::DocumentSymbolParams;
@@ -21,7 +18,6 @@ use tower_lsp::lsp_types::SymbolInformation;
2118
use tower_lsp::lsp_types::SymbolKind;
2219
use tower_lsp::lsp_types::WorkspaceSymbolParams;
2320
use tree_sitter::Node;
24-
use url::Url;
2521

2622
use crate::lsp::ark_file::ArkFile;
2723
use crate::lsp::db::ArkDb;
@@ -73,7 +69,7 @@ pub(crate) fn symbols(
7369
return;
7470
}
7571

76-
let Some(range) = index_range_to_lsp_range(db, uri, entry.range, encoding) else {
72+
let Some(range) = indexer::index_range_to_lsp_range(db, uri, entry.range, encoding) else {
7773
return;
7874
};
7975

@@ -141,37 +137,6 @@ pub(crate) fn symbols(
141137
Ok(info)
142138
}
143139

144-
/// Convert an index entry's tree-sitter point range to an LSP range, resolving
145-
/// the file's line index from the db. Returns `None` if the file is no longer
146-
/// in the db or the points fall outside it, in which case the symbol is
147-
/// dropped from the results.
148-
fn index_range_to_lsp_range(
149-
db: &dyn ArkDb,
150-
uri: &Url,
151-
range: indexer::IndexRange,
152-
encoding: PositionEncoding,
153-
) -> Option<Range> {
154-
let file = db.file_by_path(&FilePath::from_url(uri))?;
155-
let line_index = file.line_index(db);
156-
157-
let to_position = |point: indexer::IndexPoint| {
158-
to_proto::position_from_line_col(
159-
biome_line_index::LineCol {
160-
line: point.row,
161-
col: point.column,
162-
},
163-
line_index,
164-
encoding,
165-
)
166-
.ok()
167-
};
168-
169-
Some(Range::new(
170-
to_position(range.start)?,
171-
to_position(range.end)?,
172-
))
173-
}
174-
175140
/// Represents a section in the document with its title, level, range, and children
176141
#[derive(Debug)]
177142
struct Section {

0 commit comments

Comments
 (0)