Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown links render as wikilinks when inserted via completion #436

Closed
2 tasks done
tjex opened this issue Jul 15, 2024 · 15 comments
Closed
2 tasks done

Markdown links render as wikilinks when inserted via completion #436

tjex opened this issue Jul 15, 2024 · 15 comments
Labels
can't reproduce The bug can't be reproduced by one or more maintainers

Comments

@tjex
Copy link
Member

tjex commented Jul 15, 2024

Check if applicable

  • I have searched the existing issues (required)
  • I'm willing to help fix the problem and contribute a pull request

Describe the bug

No doubt related / see also #435 .

Despite using wikilink syntax to trigger completion ([[), when selecting a link from the lsp link completion menu, the link should be rendered as a regular markdown link provided the user has link-format = "markdown" in their config.toml.

This however only happens for me if I select an initial completion option.

If I type, to filter the list, and select an option, the link is inserted as a regular wiki link.

Here a starting point:

func (s *Server) buildTriggerCompletionList(notebook *core.Notebook, doc *document, position protocol.Position) ([]protocol.CompletionItem, error) {

How to reproduce?

  1. have link-format = "markdown" set in config
  2. open a note
  3. type [[ and accept a completion

Link should render as a markdown link (and it does for me)

On a separate line:

  1. type [[
  2. filter for a different note by typing a note title
  3. accept a completion option

Link should render as markdown link (and it does not for me, it renders as a wikilink)

zk configuration

na

Environment

zk 0.14.1
system: Darwin 23.4.0 arm64
@WhyNotHugo
Copy link
Contributor

I cannot reproduce this; I trigger completion with [[, but the link is inserted in markdown format for me.

Using the LSP via neovim + nvim-cmp.

@tjex
Copy link
Member Author

tjex commented Jul 24, 2024

But what if you filter the list, and then accept a completion option?

i.e, this:

  1. type [[
  2. filter for a different note by typing a note title
  3. accept a completion option

Link should render as markdown link (and it does not for me, it renders as a wikilink)

@WhyNotHugo
Copy link
Contributor

Following those steps, the link renders as markdown for me.

Accepting/confirming the completion replaces the placeholder with a markdown link for me.


If instead of accepting the first choice, I pick another, the placeholder text is replaced as soon as I pick another.

@tjex tjex added the can't reproduce The bug can't be reproduced by one or more maintainers label Aug 4, 2024
@tjex
Copy link
Member Author

tjex commented Aug 5, 2024

Here an asciicast: https://asciinema.org/a/4lvriIlQLHMCKF33ms155QAs8

So it's actually a slightly different step (second and last link attempt in video):

  1. type [[
  2. start typing some text of a title
  3. trigger completion
  4. select completion

Link renders as wikilink.

@WhyNotHugo can you see if that can be reproduced on your end?
I also just dissabled my autopairs plugin, in case that was causing issues. But the behaviour is the same.

@WhyNotHugo
Copy link
Contributor

WhyNotHugo commented Aug 6, 2024

What completion plugin is this?

When you do the second (failing) insertion, what mapping do you use? What function does this call? I have an impression that you may not be properly triggering the completion and that this is an IDE configuration issue.

Personally, I use nvim-cmp, and I mapped C-o to cmp.mapping.confirm({ select = true }),, which will auto-select the first entry and insert that.

@tjex
Copy link
Member Author

tjex commented Aug 6, 2024

So after typing a few chars, I hit cmp.mapping.complete() (to bring up the pop up) and then cmp.mapping.confirm({ select = true }).

So yeah, I'm also using nvim-cmp. But maybe you spot something amiss? I'll also check through your dotfiles and see.
It's a really annoying issue... 🫨

nvim-cmp conf

@tjex
Copy link
Member Author

tjex commented Aug 6, 2024

Hmm, you don't even have a keybind for cmd.mapping.complete() 🧐
https://git.sr.ht/~whynothugo/dotfiles/tree/main/item/home/.config/nvim/init.lua#L64

I also don't see a setting for autocomplete. What is this sorcery; How do you invoke the pop-up? haha

@tjex
Copy link
Member Author

tjex commented Aug 6, 2024

ugh, ok I (half) figured it out.

When I'm typing, and open completion, the only completion results I get are plain text completion results, and not lsp files.

Even in a (freshly saved) blank document (where the text "untitled 2") is not present, cmp still supplies me with a completion buffer text option, "untitled 2".

Stranger still, after typing unt|, the lsp completion result for the file (that will actually correctly insert a markdown link) disappears! In other words, after I type, I seemingly only get text results, or the lsp / cmp is getting the type of the completion result incorrect 🤷‍♂️

I guess this is what was throwing me off, I had no reason to expect a text completion when the only text in the document was # Untitled 1, so I overlooked the little Tt symbol in the cmp popup.. As I dont have buffer as a completion source. I guess nvim_lsp completion source grabs all text from other files? Or maybe headings, caus its seeing a markdown document...

It's still behaving strangely though. But it needs more investigating from my end.

In other, other words

  2 # Untitled 1
  1
3   [[]]
~  ╭────────────────────╮
~  │ Untitled 1 󰈇 [LSP] │ <- lsp file
~  │ Untitled 2 󰈇 [LSP] │ <- lsp file
~  │ {{title}}  󰉿 [LSP] │ <- why it pics this up, i dno.
~  │ Untitled 2 󰉿 [LSP] │ <- buffer text (that doesn't exist in this buffer 🤷‍♂️)
~  ╰────────────────────╯
  2 # Untitled 1
  1
3   [[un]]
~    ╭────────────────────╮
~    │ Untitled 2 󰉿 [LSP] │ <- the buffer text option, _not_ the lsp file option.
~    ╰────────────────────╯

@tjex
Copy link
Member Author

tjex commented Aug 6, 2024

...Right. Got it:

incorrect:

			sources = cmp.config.sources({
				{ name = "nvim_lsp" },
				{ name = "luasnip" },
				-- { name = "nvim_lua", keyword_length = 6 },
				{ name = "path" },
				{ name = "buffer" },
			}),

correct:

			sources = cmp.config.sources({
				{ name = "nvim_lsp" },
				{ name = "luasnip" },
				-- { name = "nvim_lua", keyword_length = 6 },
				{ name = "path" },
			}, {
				{ name = "buffer" },
			}),

This slight change was meaning that my completion results were disappearing when I began to type..
As I never have autocomplete on, I never considered this strange, as I always hit complete() manually, to invoke the pop-up.

If I do type (whereby the lsp file and text completions stay in place), but then hit complete(), I still only get the text completion. This I think is the core source of the 'bug' then, in our implentation of completion / lsp somewhere.

Because I expect that after typing, that re-executing complete() which brings up the pop-up (so, not select()) that I should be shown the exact same results as when I finished typing.

Here asciinema showing this

In any case, will close this for now, as if there is a bug. It's definitely worth starting a new issue for it. This one got busy!! Thanks for your extra eyes Hugo.

@tjex tjex closed this as completed Aug 6, 2024
@WhyNotHugo
Copy link
Contributor

Hmm, you don't even have a keybind for cmd.mapping.complete() 🧐

Completion triggers automatically when I type.

I had no idea about this syntax using cmp.config.sources. I use { name = "buffer", priority = 1 }, which just keeps buffer suggestions at the lowest priority (e.g.: last in the list).

For me, the LSP only shows suggestions of type Reference. Not sure what 󰈇 and 󰉿 mean, but I only have one type of suggestions. Maybe my LSP is configured different? Can you confirm that you don't have some other LSP running with :LspInfo?

@tjex
Copy link
Member Author

tjex commented Aug 7, 2024

I also have marksman lsp running, but it makes no difference. If I dissable markdman, I don't get the Tt completion results when cmp triggers after typing [[. But, if I type some chars and then hit complete() I still only get one singular result with Tt symbol, when there was previously an lsp result to create the link.

I also didn't know about this syntax for cmp.config.sources, I'm quite sure I copy and pasted the config from setup when I first installed, so maybe it was a change at some point...

@WhyNotHugo
Copy link
Contributor

I realised that I'm using [[ to trigger link completions even though I'm using markdown style links.

I configured ["<C-s>"] = cmp.mapping.complete(). If I press ctrl+S follows by some letters, I only get dictionary completion but no suggestions from the LSP.

I think that the LSP does not send any completions unless I have previously typed [[.

@WhyNotHugo
Copy link
Contributor

The completion provider only yields results in the two preceding characters are [[[:

if strings.HasPrefix(doc.LookBehind(position, len(currentWord)+2), "[[") {

This is why manually invoking completion yields no results.

@WhyNotHugo
Copy link
Contributor

This is called from internal/adapter/lsp/server.go:204

I think when params.Context.TriggerKind == protocol.CompletionTriggerKindInvoked, we ought to always provide results.

@WhyNotHugo
Copy link
Contributor

I'll open a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce The bug can't be reproduced by one or more maintainers
Projects
None yet
Development

No branches or pull requests

2 participants