Skip to content

Commit b06b7da

Browse files
committed
Use wire_url() with indexer-based handlers
1 parent 24f47aa commit b06b7da

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

crates/ark/src/lsp/completions/sources/composite/workspace.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ fn completions_from_workspace(
6969
let token = token.as_str();
7070

7171
// get entries from the index
72-
indexer::map(&state.db, |uri, symbol, entry| {
72+
indexer::map(&state.db, |file, symbol, entry| {
7373
if !symbol.fuzzy_matches(token) {
7474
return;
7575
}
7676

7777
match &entry.data {
7878
indexer::IndexEntryData::Function { name, .. } => {
79+
let uri = state.wire_url(file);
80+
7981
let fun_context = match completion_context.function_context() {
8082
Ok(fun_context) => fun_context,
8183
Err(err) => {

crates/ark/src/lsp/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub(crate) fn generate_diagnostics(
171171
context.document_symbols.push(HashMap::new());
172172

173173
// Add the current workspace symbols.
174-
indexer::map(db, |_uri, _symbol, entry| match &entry.data {
174+
indexer::map(db, |_file, _symbol, entry| match &entry.data {
175175
indexer::IndexEntryData::Function { name, arguments: _ } => {
176176
context.workspace_symbols.insert(name.to_string());
177177
},

crates/ark/src/lsp/indexer.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use stdext::unwrap;
1414
use stdext::unwrap::IntoResult;
1515
use tree_sitter::Node;
1616
use tree_sitter::Query;
17-
use url::Url;
1817

1918
use crate::lsp;
2019
use crate::lsp::db::ArkDb;
@@ -124,15 +123,16 @@ fn file_index(db: &dyn ArkDb, file: File) -> FileIndex {
124123
FileIndex { symbols }
125124
}
126125

127-
/// Visit every workspace symbol across all indexable files.
128-
pub(crate) fn map(db: &dyn ArkDb, mut callback: impl FnMut(&Url, &str, &IndexEntry)) {
126+
/// Visit every workspace symbol across all indexable files. Callers that need a
127+
/// URL for messages to the frontend can resolve it from `File` via
128+
/// `WorldState::wire_url`.
129+
pub(crate) fn map(db: &dyn ArkDb, mut callback: impl FnMut(File, &str, &IndexEntry)) {
129130
for &file in oak_db::workspace_files(db) {
130131
if !is_indexable(db, file) {
131132
continue;
132133
}
133-
let url = file.path(db).to_url();
134134
for (symbol, entry) in file_index(db, file).symbols.iter() {
135-
callback(&url, symbol, entry);
135+
callback(file, symbol, entry);
136136
}
137137
}
138138
}
@@ -344,6 +344,7 @@ mod tests {
344344
use assert_matches::assert_matches;
345345
use insta::assert_debug_snapshot;
346346
use oak_scan::DbScan;
347+
use url::Url;
347348

348349
use super::*;
349350
use crate::lsp::ark_file::test_ark_file;

crates/ark/src/lsp/symbols.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::result::Result::Ok;
1111

1212
use aether_lsp_utils::proto::to_proto;
1313
use aether_lsp_utils::proto::PositionEncoding;
14-
use aether_path::FilePath;
14+
use oak_db::File;
1515
use stdext::unwrap::IntoResult;
1616
use tower_lsp::lsp_types::DocumentSymbol;
1717
use tower_lsp::lsp_types::DocumentSymbolParams;
@@ -21,7 +21,6 @@ use tower_lsp::lsp_types::SymbolInformation;
2121
use tower_lsp::lsp_types::SymbolKind;
2222
use tower_lsp::lsp_types::WorkspaceSymbolParams;
2323
use tree_sitter::Node;
24-
use url::Url;
2524

2625
use crate::lsp::ark_file::ArkFile;
2726
use crate::lsp::db::ArkDb;
@@ -68,15 +67,17 @@ pub(crate) fn symbols(
6867
let encoding = state.config.position_encoding;
6968
let mut info: Vec<SymbolInformation> = Vec::new();
7069

71-
indexer::map(db, |uri, symbol, entry| {
70+
indexer::map(db, |file, symbol, entry| {
7271
if !symbol.fuzzy_matches(query) {
7372
return;
7473
}
7574

76-
let Some(range) = index_range_to_lsp_range(db, uri, entry.range, encoding) else {
75+
let Some(range) = index_range_to_lsp_range(db, file, entry.range, encoding) else {
7776
return;
7877
};
7978

79+
let uri = state.wire_url(file);
80+
8081
match &entry.data {
8182
IndexEntryData::Function { name, arguments: _ } => {
8283
info.push(SymbolInformation {
@@ -142,16 +143,14 @@ pub(crate) fn symbols(
142143
}
143144

144145
/// 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.
146+
/// the file's line index from the db. Returns `None` if the points fall outside
147+
/// the line index, in which case the symbol is dropped from the results.
148148
fn index_range_to_lsp_range(
149149
db: &dyn ArkDb,
150-
uri: &Url,
150+
file: File,
151151
range: indexer::IndexRange,
152152
encoding: PositionEncoding,
153153
) -> Option<Range> {
154-
let file = db.file_by_path(&FilePath::from_url(uri))?;
155154
let line_index = file.line_index(db);
156155

157156
let to_position = |point: indexer::IndexPoint| {

0 commit comments

Comments
 (0)