Skip to content

Migrate hover, signature help, and completions to ArkFile#1264

Merged
lionel- merged 3 commits into
mainfrom
oak/salsa-24-rewire-handlers
Jun 19, 2026
Merged

Migrate hover, signature help, and completions to ArkFile#1264
lionel- merged 3 commits into
mainfrom
oak/salsa-24-rewire-handlers

Conversation

@lionel-

@lionel- lionel- commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Branched from #1263
Progress towards #1212

The handlers migrated use a slightly different approach because they use r_task() heavily and the Oak DB shouldn't be touched from an r_task() because of the risk of cancellation panics, which would be UB over the R stack. We could catch panics in r_task() and unwind for cancellation but I didn't want to think through the various implications.

  • DocumentContext drops Document and stores the pieces it needs from the ArkDb and LSP state (tree, contents, line_index, encoding). This way the DB is not sent over an r_task().

  • Add LSP <> TS position/range converters as methods on DocumentContext (parallel to the ones on ArkFile, also replacements for the Document methods).

  • Migrate hover, signature help, and completion to the refactored DocumentContext.

@lionel- lionel- changed the title Reshape DocumentContext and migrate hover and completions to ArkFile Migrate hover, signature help, and completions to ArkFile Jun 11, 2026

@DavisVaughan DavisVaughan left a comment

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.

Looks good, my main comments are about reducing duplication and noise

Comment thread crates/ark/src/fixtures/utils.rs Outdated
Comment thread crates/ark/src/lsp/document_context.rs Outdated
Comment thread crates/ark/src/lsp/document_context.rs
Comment thread crates/ark/src/lsp/document_context.rs Outdated
use crate::treesitter::NodeTypeExt;

#[derive(Debug)]
pub struct DocumentContext<'a> {

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.

Should it be renamed to ArkFileContext at some point?

Comment on lines +20 to +22
/// We store extracted components of `&ArkFile` + `&dyn ArkDb` here because
/// the latter can't be sent over an `r_task()`.
pub tree: &'a tree_sitter::Tree,

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 would like to point out that we have

    // TODO(oak/completions): Clone so the closure captures by value. `r_task()`
    // sends the closure across threads, and `&WorldState` isn't `Send` because
    // `OakDatabase`'s salsa storage keeps thread-local query state.
    let state = state.clone();
    let completions = r_task(move || provide_completions(&context, &state))?;

So is something wrong here?

It's pretty odd to me that we:

  • Are creating DocumentContext to make context here because of ArkDb issues
  • Then we send over WorldState, which has those exact issues

Something feels off

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.

Like, isn't this us using a salsa db inside an r_task? Which we definitely aren't supposed to do in case it panics?

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.

The completion handler runs on the main loop and thus can't be cancelled.

That said I agree this state of things is not great, but it's actually "fixed" in this PR: #1269

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.

completion handler runs on the main loop and thus can't be cancelled

ah because it blocks the next request/notification handler from running at all, so we can't process a did_change() that might result in us being cancelled. gotcha.

@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-24-rewire-handlers branch from ac1ede7 to 05ab753 Compare June 16, 2026 16:06
@lionel- lionel- force-pushed the oak/salsa-23-ark-file branch from 820ae96 to 0e8e3d5 Compare June 19, 2026 13:59
Base automatically changed from oak/salsa-23-ark-file to main June 19, 2026 14:00
@lionel- lionel- force-pushed the oak/salsa-24-rewire-handlers branch from 4b1e9b3 to 112e465 Compare June 19, 2026 14:01
@lionel- lionel- merged commit 09f4b1f into main Jun 19, 2026
17 checks passed
@lionel- lionel- deleted the oak/salsa-24-rewire-handlers branch June 19, 2026 14:01
@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