From 1f00191de28cf53c54936ee843c39b0d91ced43c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 5 Apr 2021 16:27:45 +0300 Subject: internal: document hypothetical completion problem --- crates/ide_completion/src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index 831d543bb..6f3d5c5c5 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs @@ -106,6 +106,34 @@ pub use crate::{ /// `foo` *should* be present among the completion variants. Filtering by /// identifier prefix/fuzzy match should be done higher in the stack, together /// with ordering of completions (currently this is done by the client). +/// +/// # Hypothetical Completion Problem +/// +/// There's a curious unsolved problem in the current implementation. Often, you +/// want to compute completions on a *slightly different* text document. +/// +/// In the simplest case, when the code looks like `let x = `, you want to +/// insert a fake identifier to get a better syntax tree: `let x = complete_me`. +/// +/// We do this in `CompletionContext`, and it works OK-enough for *syntax* +/// analysis. However, we might want to, eg, ask for the type of `complete_me` +/// variable, and that's where our current infrastructure breaks down. salsa +/// doesn't allow such "phantom" inputs. +/// +/// Another case where this would be instrumental is macro expansion. We want to +/// insert a fake ident and re-expand code. There's `expand_hypothetical` as a +/// work-around for this. +/// +/// A different use-case is completion of injection (examples and links in doc +/// comments). When computing completion for a path in a doc-comment, you want +/// to inject a fake path expression into the item being documented and complete +/// that. +/// +/// IntelliJ has CodeFragment/Context infrastructure for that. You can create a +/// temporary PSI node, and say that the context ("parent") of this node is some +/// existing node. Asking for, eg, type of this `CodeFragment` node works +/// correctly, as the underlying infrastructure makes use of contexts to do +/// analysis. pub fn completions( db: &RootDatabase, config: &CompletionConfig, -- cgit v1.2.3