aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-05 14:28:32 +0100
committerGitHub <[email protected]>2021-04-05 14:28:32 +0100
commitfab1c066464022613729a6d714dc83b7d698ece5 (patch)
tree4e17e20186bad116272c7260f120630365b95ab9 /crates/ide_completion/src
parent8a18f23df068dd8e3cfaea15391610dbda418aab (diff)
parent1f00191de28cf53c54936ee843c39b0d91ced43c (diff)
Merge #8343
8343: internal: document hypothetical completion problem r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide_completion/src')
-rw-r--r--crates/ide_completion/src/lib.rs28
1 files changed, 28 insertions, 0 deletions
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::{
106/// `foo` *should* be present among the completion variants. Filtering by 106/// `foo` *should* be present among the completion variants. Filtering by
107/// identifier prefix/fuzzy match should be done higher in the stack, together 107/// identifier prefix/fuzzy match should be done higher in the stack, together
108/// with ordering of completions (currently this is done by the client). 108/// with ordering of completions (currently this is done by the client).
109///
110/// # Hypothetical Completion Problem
111///
112/// There's a curious unsolved problem in the current implementation. Often, you
113/// want to compute completions on a *slightly different* text document.
114///
115/// In the simplest case, when the code looks like `let x = `, you want to
116/// insert a fake identifier to get a better syntax tree: `let x = complete_me`.
117///
118/// We do this in `CompletionContext`, and it works OK-enough for *syntax*
119/// analysis. However, we might want to, eg, ask for the type of `complete_me`
120/// variable, and that's where our current infrastructure breaks down. salsa
121/// doesn't allow such "phantom" inputs.
122///
123/// Another case where this would be instrumental is macro expansion. We want to
124/// insert a fake ident and re-expand code. There's `expand_hypothetical` as a
125/// work-around for this.
126///
127/// A different use-case is completion of injection (examples and links in doc
128/// comments). When computing completion for a path in a doc-comment, you want
129/// to inject a fake path expression into the item being documented and complete
130/// that.
131///
132/// IntelliJ has CodeFragment/Context infrastructure for that. You can create a
133/// temporary PSI node, and say that the context ("parent") of this node is some
134/// existing node. Asking for, eg, type of this `CodeFragment` node works
135/// correctly, as the underlying infrastructure makes use of contexts to do
136/// analysis.
109pub fn completions( 137pub fn completions(
110 db: &RootDatabase, 138 db: &RootDatabase,
111 config: &CompletionConfig, 139 config: &CompletionConfig,