Skip to content

Commit

Permalink
Capture word parts while calculating shellwords (#4632)
Browse files Browse the repository at this point in the history
This fixes an edge case for completing shellwords. With a file
"a b.txt" in the current directory, the sequence `:open a\<tab>`
will result in the prompt containing `:open aa\ b.txt`. This is
because the length of the input which is trimmed when replacing with
completion is calculated on the part of the input which is parsed by
shellwords and then escaped (in a separate operation), which is lossy.
In this case it loses the trailing backslash.

The fix provided here refactors shellwords to track both the _words_
(shellwords with quotes and escapes resolved) and the _parts_ (chunks
of the input which turned into each word, with separating whitespace
removed). When calculating how much of the input to delete when
replacing with the completion item, we now use the length of the last
part.

This also allows us to eliminate the duplicate work done in the
`ends_with_whitespace` check.
  • Loading branch information
the-mikedavis authored Nov 17, 2022
1 parent b474ee1 commit c6b8336
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 170 deletions.
Loading

0 comments on commit c6b8336

Please sign in to comment.