Reduce tokenizer/parser overhead#4
Conversation
| /// ("ls /usr/loc", 11) => Ok((3, vec!["/usr/local/"])) | ||
| fn complete( | ||
| &self, // FIXME should be `&mut self` | ||
| &mut self, // FIXME should be `&mut self` |
| )* | ||
| } | ||
| } | ||
| // macro_rules! box_completer { |
| let width = candidate.width(); | ||
| if let Some(highlighter) = s.highlighter() { | ||
| ab.push_str(&highlighter.highlight_candidate(candidate, CompletionType::List)); | ||
| if s.out.colors_enabled() { |
There was a problem hiding this comment.
Wrong: duplicated code (previously this logic was factorized in s.highlighter() method).
| /// | ||
| /// You can put the tokenizer/parser here so that other APIs can directly use | ||
| /// results generate here, and reduce the overhead. | ||
| fn update_after_edit(&mut self, line: &str, pos: usize, forced_refresh: bool) { |
There was a problem hiding this comment.
I would have prefer a dedicated component and an API compatible with tree-sitter incremental parsing.
See https://github.com/gwenn/rustyline-notes/blob/master/src/syntax.md
There was a problem hiding this comment.
And this may conflict with another feature: autocorrection.
See kkawakam#593 (comment)
And kkawakam#656 (comment)
| /// | ||
| /// You can put the tokenizer/parser here so that other APIs can directly use | ||
| /// results generate here, and reduce the overhead. | ||
| fn update_after_move_cursor(&mut self, line: &str, pos: usize) { |
|
If possible, I would prefer a dedicated PR for mutable helper based on rustyline master branch instead of the highlight branch. |
|
Thx for inform me https://github.com/gwenn/rustyline-notes/blob/master/src/syntax.md, which is exactly what I want. But for
This requirement will make traits messy. Like pub trait Helper
where
Self: Completer<Parsed = <Self as Helper>::Parsed>
+ Hinter<Parsed = <Self as Helper>::Parsed>
+ Highlighter<Parsed = <Self as Helper>::Parsed>
+ Parser<Parsed = <Self as Helper>::Parsed>
+ Validator<Parsed = <Self as Helper>::Parsed>,
{
type Parsed;
}
pub trait Completer {
type Parsed;
}
...And also, thanks a lot for reviewing. I will make a commit directly to master branch, under your suggestions. |
Make
helpermutable inhighlight,validate,complete, ...as you have mentioned at
https://github.com/gwenn/rustyline/blob/highlight/src/completion.rs#L93
https://github.com/gwenn/rustyline/blob/highlight/src/lib.rs#L543
Now the
Helperbecomes torustyline/src/lib.rs
Lines 544 to 573 in 6e08e81
And APIs like
completebecome torustyline/src/completion.rs
Lines 81 to 106 in 6e08e81
User can put the tokenizer/parser at
update_after_edit, which will be called just after the line is modified, to update context. Then use the parsed context inhighlight,validate,complete, ...The
examples/continuation_prompt.rsis just a prototype to demo this featrue, and will be updated during thecontinuation_promptwith new layout.