Add FuzzyCommandComp fallback completion type#640
Conversation
HalFrgrd
left a comment
There was a problem hiding this comment.
obviously refactor the common code between FuzzyCommandComp and CommandComp into a new function.
Done in 84ec4f3. Extracted two helpers used by both arms: |
| // the completion using only the first character of the word | ||
| // so we get a broader candidate pool, then fuzzy-match those | ||
| // candidates against the entire word. | ||
| let AliasExpandedCompletion { |
There was a problem hiding this comment.
this should be in the common function.
There was a problem hiding this comment.
Done in 0449ed2. The alias expansion now happens once inside run_command_completion.
| completion_context.context_until_cursor.as_ref(), | ||
| ); | ||
|
|
||
| if command_word == "flyline" { |
There was a problem hiding this comment.
nothign special about flyline. it should be handled in the common function.
There was a problem hiding this comment.
Done in 0449ed2. The flyline branch now lives in run_command_completion and applies to both modes — in fuzzy mode it just fuzzy-filters the clap candidates against the original wuc instead of bailing out.
| let wuc_start_in_full = word_under_cursor_end - wuc_byte_len; | ||
| let mut new_full_command = | ||
| String::with_capacity(full_command.len() - wuc_byte_len + first_char_len); | ||
| new_full_command.push_str(&full_command[..wuc_start_in_full]); |
There was a problem hiding this comment.
there is no need to handle the text after word under cursor.
we should be able to use context_until_cursor and truncate more off of it and use that as the "context"
There was a problem hiding this comment.
Done in 0449ed2. In fuzzy mode the function now starts from context_until_cursor, truncates the wuc-before-cursor portion off the end, and appends the first character of the wuc — no after-cursor text is touched, and the splice math on full_command is gone.
HalFrgrd
left a comment
There was a problem hiding this comment.
Now rebase your changes onto origin/master.
I want you to create a method for completion context called with_wuc_replaced(new_wuc) which returns a new completion context with the word under cursor replaced much like how the alias expansion logic works. Don't update comp types.
Use this to create a temporary completioncontext with wuc replaced by the first char of wuc.
Create lib tests to test the replacement logic.
And use this temporary completioncontext for fuzzycompletioncomp
Agent-Logs-Url: https://github.com/HalFrgrd/flyline/sessions/cb774252-d1b1-41bf-84f8-79ae6f898879 Co-authored-by: HalFrgrd <4559349+HalFrgrd@users.noreply.github.com>
Done in 9f40344. Rebased onto |
HalFrgrd
left a comment
There was a problem hiding this comment.
You rebased in one commit and the merged after that . The branch could be merged into master after the rebase but it can't now after the merge commit. U do the merge commit or fix it some other way.
You're right, sorry about that — the merge commit |
2df785e to
9f40344
Compare
Adds a new completion type,
FuzzyCommandComp, that runs afterCommandCompwhenever the latter doesn't produce any results.Behavior
FuzzyCommandCompre-issues the bash programmable completion using only the first character of the word under cursor as the prefix (so the completion function returns a much wider set of candidates), then fuzzy-matches those candidates against the full word under cursor.FuzzyCommandCompfalls through to the next completion type — there's nothing meaningful to fuzzy-match against a single character.FuzzyCommandCompis appended right afterCommandCompinCompletionContext::new, mirroring the existingFirstWord→FuzzyFirstWordandFilenameExpansion→FuzzyFilenameExpansionpairings.Changes
src/tab_completion_context.rs:CompType::FuzzyCommandComp { command_word }variant; pushed alongsideCommandComp. Updated the 14 vec-equality test assertions to include the new variant.CompletionContext::with_wuc_replaced(new_wuc) -> CompletionContext<'static>method, modeled onwith_expanded_alias. It rebuildscontextwith the wuc bytes swapped fornew_wuc, preservescontext.startandword_under_cursor.start, and adjustscursor_byte_pos(shift by the length delta when the cursor was at/past the end of the old wuc, otherwise clamp to the end of the new wuc).comp_typesis intentionally not recomputed.context.startpreserved when the wuc is not at offset 0, andcomp_typesleft unchanged.src/app/tab_completion.rs: Both theCommandCompandFuzzyCommandComparms ingen_completions_internalnow dispatch to a single sharedrun_command_completion(ctx, initial_command_word, fuzzy_match_against)function that owns the entire body of both modes:CompletionContext::with_expanded_aliasfuzzy_match_with_thresholdagainst the original wuc in fuzzy mode instead of bailing out)run_programmable_completionscallcompletion_context.with_wuc_replaced(&first_char_of_wuc)and passes the original wuc asfuzzy_match_against; the function then fuzzy-filters and sorts the bash candidates against the original wucActiveSuggestionsBuilderThe two arms are now ~10 lines each — they just call
run_command_completionand propagate the resulting suggestions / flags via aCommandCompletionResultenum (Found/NoneWithFlags/None).Validation
cargo build --libcargo build --features integration-testscargo test --lib(567 passed)cargo fmt