Skip to content

Add ArkDb, ArkFile, and tree_sitter() query for legacy handlers#1263

Merged
lionel- merged 20 commits into
mainfrom
oak/salsa-23-ark-file
Jun 19, 2026
Merged

Add ArkDb, ArkFile, and tree_sitter() query for legacy handlers#1263
lionel- merged 20 commits into
mainfrom
oak/salsa-23-ark-file

Conversation

@lionel-

@lionel- lionel- commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Branched from #1260
Progress towards #1212

This PR starts migrating legacy Ark handlers to the Oak database so that we get one source of truth and remove redundancy of representations (source, syntax trees) in the LSP to save on memory.

Introduces ArkFile in the process. Note this is meant as a convenient temporary vessel until we fully migrate handlers to Oak.

  • Add ArkFile which bundles an Oak File with some metadata used by Ark handlers (version, wire url, encoding). This is meant to replace Document in a subsequent PR. The LSP <> TS position converters are now methods on ArkFile (previously on Document).

  • Add ArkDb and FileExt as extension traits for Oak.
    The main addition is a tree-sitter query, capped at 128 trees (like the Rowan trees).

  • spawn_blocking() now catches Salsa cancellations when reads on backaground tasks (e.g. diagnostics) are cancelled by a concurrent write.

  • Start migrating a bunch of handlers to that new Oak infra.

Comment thread crates/ark/src/lsp.rs
Comment thread crates/ark/src/r_task.rs
Comment on lines +195 to +197
// Don't run oak (salsa) queries inside `f`. `f` executes on the R thread, and a
// `salsa::Cancelled` unwind there would cross R's C frames, which is UB. Pull
// whatever you need out of oak before the `r_task()`, on the calling thread.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬, no way to guard against this i guess?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's coming up! #1269

Comment thread crates/ark/src/lsp/db.rs Outdated
Comment on lines +21 to +25
pub(crate) trait FileExt {
fn tree_sitter(self, db: &dyn ArkDb) -> &tree_sitter::Tree;
}

impl FileExt for File {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub(crate) trait FileExt {
fn tree_sitter(self, db: &dyn ArkDb) -> &tree_sitter::Tree;
}
impl FileExt for File {
pub(crate) trait FileTreeSitterExt {
fn tree_sitter(self, db: &dyn ArkDb) -> &tree_sitter::Tree;
}
impl FileTreeSitterExt for File {

?

idk how i feel about having uninformative FileExt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would also probably be fine with just exposing tree_sitter_query as tree_sitter directly and not having it as a method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or more like FileArkExt? It's not necessarily about tree-sitter (although it now is)

let mut actions = CodeActions::new();

roxygen_documentation(&mut actions, uri, document, range, capabilities);
roxygen_documentation(db, file, &mut actions, range, capabilities);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did like having &mut actions up front

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense too, but context params go first by convention.

pub(crate) version: Option<i32>,
pub(crate) config: DocumentConfig,
pub(crate) url: Url,
pub(crate) encoding: PositionEncoding,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hoping this encoding field goes away entirely, see a review of a previous pr that i left

@lionel- lionel- Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArkFile in general goes away entirely once we update Ark handlers to Oak layering

}

#[cfg(test)]
mod tests {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really want tests in main_loop.rs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for super::

fn test_line_indent_oob() {
let doc = test_doc("");
assert_match!(indent_edit(&doc, 1), Err(_));
let (db, ark_file) = crate::lsp::ark_file::test_ark_file("");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you just use crate::lsp::ark_file to make this cleaner?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(here and in all other files)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you ask me I don't think we should spend much time on test styling.

Comment thread crates/ark/src/lsp/handlers.rs Outdated
Comment on lines +48 to 52
pub(crate) db: &'a dyn ArkDb,
pub(crate) file: &'a ArkFile,

/// The symbols currently defined and available in the session.
pub session_symbols: HashSet<String>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use consistent pub and spacing and comments as in the rest of the struct?

Comment on lines +1175 to +1180
let url = url::Url::parse("file:///test.R").unwrap();
let file = oak_db::File::new(&state.db, FilePath::from_url(&url), code.to_string(), None);
let ark_file = ArkFile {
file,
version: None,
config: DocumentConfig::default(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this not your test_ark_file() thing?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm i guess not because WorldState is required

i wonder if you can get rid of current_state()? or at least this console_inputs() thing in favor of just empty vectors for console_scopes and installed_packages? not sure. if you could do that, you could probably remove the r_task() from all of these tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I want to spend too much time on this right now

@lionel- lionel- force-pushed the oak/salsa-22-testthat branch from 79df227 to cac4c04 Compare June 16, 2026 14:26
@lionel- lionel- force-pushed the oak/salsa-23-ark-file branch from c3744b4 to bac9a5f Compare June 16, 2026 14:54
@lionel- lionel- force-pushed the oak/salsa-22-testthat branch from 17a154b to 2ebe7c4 Compare June 19, 2026 13:58
Base automatically changed from oak/salsa-22-testthat to main June 19, 2026 13:58
@lionel- lionel- force-pushed the oak/salsa-23-ark-file branch from 820ae96 to 0e8e3d5 Compare June 19, 2026 13:59
@lionel- lionel- merged commit 362ca82 into main Jun 19, 2026
17 checks passed
@lionel- lionel- deleted the oak/salsa-23-ark-file branch June 19, 2026 14:00
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants