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

<c-n> on some LSP completion options triggers an "Item not found ... ParseMarkdown" error #508

Closed
ghost opened this issue May 3, 2024 · 11 comments

Comments

@ghost
Copy link

ghost commented May 3, 2024

H, there. I'm not sure when this started happening, but I typed:

<style>
.title {
    border-

and then hit <c-n> to scroll through the list of completions. It seems to scroll correctly, but there is this error for every time I scroll:

Error detected while compiling CompleteChanged Autocommands for "<buffer=1>"..function <SNR>43_LspResolve[11]..<SNR>43_ShowCompletionDocumentatio
n[59]..FileType Autocommands for "*"..function <SNR>19_LoadFTPlugin[18]..script /nix/store/9ywm4gggqcwacn30qbjp5apqwk57zzkc-lsp/ftplugin/lspgfm.v
im[76]..function <SNR>123_RenderGitHubMarkdownText:
line   16:
E1048: Item not found in script: ParseMarkdown

ft is set to html in this file.

@ghost
Copy link
Author

ghost commented May 9, 2024

This only occurs on LSP items in the completion list.

@Konfekt
Copy link
Contributor

Konfekt commented May 10, 2024

Same issue here calling :LspHover with clangd.

@Konfekt
Copy link
Contributor

Konfekt commented May 10, 2024

I am not sure where the issue is as

document = md.ParseMarkdown(bnr->getbufline(1, '$'), winId->winwidth())
,
import autoload 'lsp/markdown.vim' as md

and
export def ParseMarkdown(data: list<string>, width: number = 80): dict<list<any>>
show that the function is defined

@ghost ghost changed the title <c-n> on CSS attributes within HTML files print an error <c-n> on some LSP completion options triggers an "Item not found ... ParseMarkdown" error May 10, 2024
@odormond
Copy link

I've encountered the same issue and managed to track it down to the way vim handle autoloading and compilation.

The simplest way to reproduce the issue is to run vim -c 'setf lspgfm'.

This trigger the filetype plugin lspgfm that import as an autoloaded module lsp/markdown.vim aliased as md. Due to the autoloading, md turns out to be empty as the compilation of lsp/markdown.vim is delayed until it's used. When RenderGitHubMarkdownText() is called at the end of the filetype plugin, it tries to access the ParseMarkdown function that is supposed to be present in md. One would expect that to trigger the loading and compilation of the lsp/markdown.vim but that's not the case (and in a sense that would defeat the purpose of using an import autoload).

If something triggers the autoloading of lsp/markdown.vim before the filetype plugin is run, everything works fine as shown by running: vim -c 'echo lsp#markdown#list_pattern' -c 'setf lspgfm'.

Grepping for autoload in the code base return just a few hits:

ftplugin/lspgfm.vim:import autoload 'lsp/markdown.vim' as md
plugin/lsp.vim:import '../autoload/lsp/options.vim'
plugin/lsp.vim:import autoload '../autoload/lsp/lsp.vim'
test/markdown_tests.vim:import '../autoload/lsp/markdown.vim' as md

So it looks like autoloading is already bypassed in both the tests and the main plugin. Following these examples, I tried the following patch that fixes the issue for me:

diff --git a/ftplugin/lspgfm.vim b/ftplugin/lspgfm.vim
index 2e9bf76..8050184 100644
--- a/ftplugin/lspgfm.vim
+++ b/ftplugin/lspgfm.vim
@@ -1,6 +1,6 @@
 vim9script
 
-import autoload 'lsp/markdown.vim' as md
+import '../autoload/lsp/markdown.vim' as md
 
 # Update the preview window with the github flavored markdown text
 def UpdatePreviewWindowContents(bnr: number, contentList: list<dict<any>>)

@ghost
Copy link
Author

ghost commented May 14, 2024

@yegappan the patch above is working for me to fix this issue entirely

@Konfekt
Copy link
Contributor

Konfekt commented May 14, 2024

Regarding

One would expect that to trigger the loading and compilation of the lsp/markdown.vim but that's not the case (and in a sense that would defeat the purpose of using an import autoload).

and

plugin/lsp.vim:import '../autoload/lsp/options.vim'
plugin/lsp.vim:import autoload '../autoload/lsp/lsp.vim'
test/markdown_tests.vim:import '../autoload/lsp/markdown.vim' as md

I am wondering what the purpose of the autoload folder is.
I thought it to be what you claim is not the case

@odormond
Copy link

Regarding

One would expect that to trigger the loading and compilation of the lsp/markdown.vim but that's not the case (and in a sense that would defeat the purpose of using an import autoload).

and

plugin/lsp.vim:import '../autoload/lsp/options.vim'
plugin/lsp.vim:import autoload '../autoload/lsp/lsp.vim'
test/markdown_tests.vim:import '../autoload/lsp/markdown.vim' as md

I am wondering what the purpose of the autoload folder is. I thought it to be what you claim is not the case

The autoload folder is used to look for files whose loading is delayed until they are needed and it works as intended when using mappings.

As I'm thinking this is a vim bug. It can be reproduced even without involving filetype plugins. I've opened an issue for it: vim/vim#14775

@Shane-XB-Qian
Copy link
Contributor

github.com/vim/vim/pull/14565#issuecomment-2062967639

@jacobwhall
Copy link

Not seeing this issue, I opened #511 describing the same bug. My setup is described there, as well as the same fix @odormond came up with above. I'll close that issue in favor of this one.

@julien
Copy link

julien commented May 29, 2024

@odormond that change fixes it for me, thanks.

@ghost
Copy link
Author

ghost commented Jun 5, 2024

Fixed by vim/vim#14885

@ghost ghost closed this as completed Jun 5, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants