Closed PowerUser64 closed 2 years ago
Same here, if i use with cmp-cmdline, :e ~/
it does't add the slash, if i try to use just :e /some/path
it adds the slash, super annoying
I think current cmp-path
is triggered only by /
or .
.
So you should start with one of these characters to use this plugin's feature.
For example, without these characters, it behaves like below, adding trailing slash.
The type of completion candidates becomes Variable
because cmp-path
doesn't work properly.
To make it works properly, you should start with ./
, like below.
The type of completion candidates becomes File/Folder, which means cmp-path
is working.
Also, cmp-path
works with leading /
and ~/
.
After doing some messing around, I determined my configuration was wrong. I took a look at what you have in your configuration @iwataka, and I discovered I had put some things in the wrong places (lua is confusing lol).
The cmdline
parts of my config had things that should have been called as functions, but I put them in the cmp.setup{}
table.
Here's what I had:
cmp.setup {
-- ...
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
}),
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' },
{ name = 'cmdline' }
}),
}),
-- ...
}
And here's what I have now:
cmp.setup {
-- ...
}
-- Thanks to iwataka on github for this bit
local search_config = {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' },
}
}
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', search_config)
cmp.setup.cmdline('?', search_config)
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
Thanks, @iwataka!
Upon further inspection, adopting part of iwataka's config was only part of the solution. I believe the real problem demonstrated here is that cmp-cmdline
is completing the path, rather than cmp-path
, and cmp-cmdline
is not well-equipped to complete paths. So, when additional /
characters are added and then deleted, it returns double the number of completions because doing //
on UNIX systems is usually interpreted as a single /
.
I have no idea how to keep cmp-cmdline
from trying to do cmp-path
's job, but if there is a way to do such a thing, I'm pretty sure it would solve this problem.
I have opened issue hrsh7th/cmp-cmdline#60 to discuss this further, as I can now confirm it is not a problem with cmp-path
.
:exploding_head:
I have noticed that quite frequently I will get trailing slashes appended to the completions.
Steps to reproduce:
Notice there is a slash appended to the result
But wait, now it's trying to complete from the root directory?
Wait, now there are two of every file
This doesn't happen in the buffer, only in the cmdline. I have noticed that it works properly sometimes, but it is rare and I don't know what causes it to work properly. Although, I'm pretty sure it has to do with the trailing slash because in the cmdline, a slash is appended, and in the buffer, a slash is not appended.
Is this a known bug or is there a way to solve this?