Skip to content
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

Closed
wants to merge 4 commits into from
Closed

add buffer completion source when no lsp #2403

wants to merge 4 commits into from

Conversation

QiBaobin
Copy link
Contributor

@QiBaobin QiBaobin commented May 5, 2022

No description provided.

@QiBaobin
Copy link
Contributor Author

QiBaobin commented May 5, 2022

#1015 add this simplest completion source as a start

Copy link
Member

@archseer archseer left a 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

let start_offset = cursor.saturating_sub(offset);
let prefix = text.slice(start_offset..cursor).to_string();

let text_str = text.to_string();
Copy link
Member

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()

Comment on lines 3636 to 3662
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(),
};
Copy link
Member

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?

https://github.com/helix-editor/helix/blob/c4e700cf9e539038239d62c2748cc48e4a1d93db/helix-term/src/commands.rs#L106-L112=

Comment on lines 3638 to 3639
let candidates: std::collections::HashSet<_> =
text_str.split(|c: char| !c.is_alphanumeric()).collect();
Copy link
Member

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.

@QiBaobin
Copy link
Contributor Author

QiBaobin commented May 5, 2022

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

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();
Copy link
Member

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.

@pickfire pickfire mentioned this pull request May 8, 2022
@the-mikedavis the-mikedavis added the S-waiting-on-review Status: Awaiting review from a maintainer. label May 18, 2022
@the-mikedavis the-mikedavis linked an issue May 27, 2022 that may be closed by this pull request
@kirawi kirawi added the A-helix-term Area: Helix term improvements label Sep 13, 2022
@pickfire pickfire self-requested a review September 29, 2022 15:39
@QiBaobin
Copy link
Contributor Author

close per #4816

@QiBaobin QiBaobin closed this Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants