zk-org / zk-nvim

Neovim extension for zk
https://github.com/zk-org/zk
GNU General Public License v3.0
503 stars 41 forks source link

link-format with auto completion #26

Closed zhengpd closed 2 years ago

zhengpd commented 2 years ago

I tried to insert wiki link by typing [[, and the completion menu pops up. After selecting a file, the generated text became [[[Untitled](4vyz)]], which I would expect to be [Untitled](4vyz) or [[4vyz]]. Am I missing something or this is intended behavior? The README doesn't talk about this.

# actual text after completion:
[[[Untitled](4vyz)]]

# expected:
[Untitled](4vyz)
zhengpd commented 2 years ago

I updated zk config to link-format = "{{filename}}" to make it compatible with nvim-cmp & nvim-autopairs. For anyone stumble across this issue, you could take a look at https://github.com/mickael-menu/zk/issues/22.

kabouzeid commented 2 years ago

Must be an issue with nvim-autopairs then. This doesn't happen with nvim-cmp and delimitmate.

mickael-menu commented 2 years ago

I merged in a PR that should fix this issue without resorting to the hack with nvim-autopairs (although it was a smart workaround @zhengpd!) https://github.com/mickael-menu/zk/pull/160

Let me know if it works for you.

tim-hilt commented 2 years ago

Hm.. The opening brackets are deleted for me, but not the closing ones, that are presumably added by my auto-pair-plugin (smart-pairs in my case). Instead they are prepended to the link?! I don't really undrestand what's happening there! To make things even weirder, it works correctly if the link is the first String in the current line. Is this the error @zhengpd described, or is the autopair-plugin at fault here?

Peek 2022-02-18 20-54

mickael-menu commented 2 years ago

I added something in the LSP server to remove extra ]] when the editor auto-pair brackets, but it's not guaranteed to work depending on the implementation of the completion plugin in the LSP client.

https://github.com/mickael-menu/zk/blob/e037befdf1e6080c1a103c5d48d47145bace514a/internal/adapter/lsp/server.go#L844-L850

I suggest disabling smart-pairs for Markdown files if you can, or maybe try nvim-autopairs and/or a different completion plugin.

tim-hilt commented 2 years ago

I initially installed smart-pairs because nvim-autopairs had this issue! Would be curious to know if @zhengpd still doesn’t see this issue when using nvim-autopairs. Disabling the the autopair-plug-in would be kind of a bummer but a last resort I would be ok with. Moving backwards to remove the brackets each time would be more annoying I guess.

kabouzeid commented 2 years ago

definitely works with delimitmate, which is what I use

tim-hilt commented 2 years ago

@kabouzeid I'm a delemitmate convert now! Works flawlessly. Grüße nach Aachen!

tim-hilt commented 2 years ago

Hey @kabouzeid, at this point I feel like I'm a bit annoying. But I still have a small request, if I may: Can you test what happens, if you add some links one after the other? Basically the same thing that is shown in the gif above. I still see the same behavior as in the screencast. It's working fine, when adding links in normal sentences, where there are other words in between the links.

However, I oftentimes add multiple tags at the top of a file, when I know the link-text won't appear in the actual text of the note. @mickael-menu this might be due to the nature of the fix you provided, if I'm not mistaken?

kabouzeid commented 2 years ago

hmm works for me no problem, not sure what is happening on your end. my dotfiles are public if you want to take a look

tim-hilt commented 2 years ago

It's really weird! Sometimes it works without any problems, sometimes it looks like the gif above. Also, it doesn't seem to be dependant on the actual autopairs-plugin, as I've tried three different plugins to date. Looks kind of like an initialization error to me. I try to find a way to reproduce it and will be taking a look at your dotfiles. I can't open-source my whole dotfiles right now, but at least I have my nvim-config in a public repo, if you're interested.

rafi commented 2 years ago

The use-additional-text-edits setting doesn't work for me (cmp + nvim-autopairs), I ended up disabling the [ rule in markdown files:

local autopairs = require('nvim-autopairs')
local cond = require('nvim-autopairs.conds')

autopairs.get_rule('['):with_pair(cond.not_filetypes({ 'markdown' }))
thecontinium commented 2 years ago

Maybe this latest commit helps ?