Migrate hover, signature help, and completions to ArkFile#1264
Conversation
DocumentContext and migrate hover and completions to ArkFileArkFile
DavisVaughan
left a comment
There was a problem hiding this comment.
Looks good, my main comments are about reducing duplication and noise
| use crate::treesitter::NodeTypeExt; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct DocumentContext<'a> { |
There was a problem hiding this comment.
Should it be renamed to ArkFileContext at some point?
| /// 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, |
There was a problem hiding this comment.
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
DocumentContextto makecontexthere because ofArkDbissues - Then we send over
WorldState, which has those exact issues
Something feels off
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
c3744b4 to
bac9a5f
Compare
ac1ede7 to
05ab753
Compare
820ae96 to
0e8e3d5
Compare
4b1e9b3 to
112e465
Compare
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 anr_task()because of the risk of cancellation panics, which would be UB over the R stack. We could catch panics inr_task()and unwind for cancellation but I didn't want to think through the various implications.DocumentContextdropsDocumentand stores the pieces it needs from theArkDband LSP state (tree,contents,line_index,encoding). This way the DB is not sent over anr_task().Add LSP <> TS position/range converters as methods on
DocumentContext(parallel to the ones onArkFile, also replacements for theDocumentmethods).Migrate hover, signature help, and completion to the refactored
DocumentContext.