diff options
author | Blaž Hrastnik | 2021-03-21 05:13:49 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-03-21 05:13:49 +0000 |
commit | a32806b4901dfbb85fdc6c043515033afcbdb9a7 (patch) | |
tree | 0888cb1be221964a5ac0486953fc9f35d53e4c7a /helix-term/src/commands.rs | |
parent | f29f01858d1b8c9e54b3293879796a4650823f60 (diff) |
Improve completion: src/<tab> will now correctly complete to src/main.rs
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index f84bb16e..54fea453 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -723,20 +723,26 @@ pub fn command_mode(cx: &mut Context) { // simple heuristic: if there's no space, complete command. // if there's a space, file completion kicks in. We should specialize by command later. if parts.len() <= 1 { + use std::{borrow::Cow, ops::Range}; + let end = 0..; COMMAND_LIST .iter() .filter(|command| command.contains(input)) - .map(|command| std::borrow::Cow::Borrowed(*command)) + .map(|command| (end.clone(), Cow::Borrowed(*command))) .collect() } else { let part = parts.last().unwrap(); ui::completers::filename(part) + .into_iter() + .map(|(range, file)| { + // offset ranges to input + let offset = input.len() - part.len(); + let range = (range.start + offset)..; + (range, file) + }) + .collect() // TODO - // completion needs to be more advanced: need to return starting index for replace - // for example, "src/" completion application.rs needs to insert after /, but "hx" - // completion helix-core needs to replace the text. - // // additionally, completion items could have a info section that would get // displayed in a popup above the prompt when items are tabbed over } |