-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add buffer completion source when no lsp #2403
Conversation
#1015 add this simplest completion source as a start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea but this will need some performance work to be viable.
Maybe we can consider implementing this via tree-sitter queries (or tree-sitter-tags) instead? https://github.com/tree-sitter/tree-sitter/tree/master/tags
helix-term/src/commands.rs
Outdated
let start_offset = cursor.saturating_sub(offset); | ||
let prefix = text.slice(start_offset..cursor).to_string(); | ||
|
||
let text_str = text.to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is extremely expensive and will be very costly on large documents. It's better to iterate on text.chunks()
helix-term/src/commands.rs
Outdated
cx.callback( | ||
async move { | ||
let candidates: std::collections::HashSet<_> = | ||
text_str.split(|c: char| !c.is_alphanumeric()).collect(); | ||
helix_lsp::Result::Ok(serde_json::Value::Array( | ||
candidates | ||
.into_iter() | ||
.map(|r| serde_json::json!({"label": r.to_string()})) | ||
.collect(), | ||
)) | ||
}, | ||
move |editor, compositor, response: Option<lsp::CompletionResponse>| { | ||
let doc = doc!(editor); | ||
if doc.mode() != Mode::Insert { | ||
// we're not in insert mode anymore | ||
return; | ||
} | ||
|
||
let mut items = match response { | ||
Some(lsp::CompletionResponse::Array(items)) => items, | ||
// TODO: do something with is_incomplete | ||
Some(lsp::CompletionResponse::List(lsp::CompletionList { | ||
is_incomplete: _is_incomplete, | ||
items, | ||
})) => items, | ||
None => Vec::new(), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is serializing to json, then immediately unserializing. Use jobs.callback
directly and avoid the extra future/parsing?
helix-term/src/commands.rs
Outdated
let candidates: std::collections::HashSet<_> = | ||
text_str.split(|c: char| !c.is_alphanumeric()).collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an intensive call to make, especially on documents with 10MB+ sizes. It's eagerly collecting lots of words, and this happens on each idle timeout right now, duplicating the work.
tree-sitter-tags is a very good source, but I think we still need text sources when there is no syntax type, or we need other completion types like lines in future. |
|
||
use helix_core::chars; | ||
let mut iter = text.chars_at(cursor); | ||
iter.reverse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I'm able to gather, I think the intention of this is to find the chars that the user has typed so far by going backwards from the cursor. But according to the docs, chars_at
Creates an iterator over the chars of the Rope, starting at char char_idx.
If I'm understanding this right, if we have the text and cursor:
I can eat glas[s], it will not hurt me
Then chars_at(cursor)
would be "it will not hurt me", and the reverse would be "em truh ton lliw ti". And so going from here, the offset would be 2, which would make the prefix ass
instead of glass
.
Also yeah, echoing archseer, repeating all the work of collecting words on every single idle timeout is going to be a problem. I think we'll need to do this a different way.
close per #4816 |
No description provided.