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

WikiTags can't work under gvim 9.1 or neovim 0.10 + win 10 pro #365

Open
VimWei opened this issue Jun 7, 2024 · 19 comments
Open

WikiTags can't work under gvim 9.1 or neovim 0.10 + win 10 pro #365

VimWei opened this issue Jun 7, 2024 · 19 comments

Comments

@VimWei
Copy link

VimWei commented Jun 7, 2024

gvim 9.1.0429 under win10 pro

  1. restart gvim 9.1.0429
  2. :WikiTags open a dialog with tag-page list
  3. filter with any text such as 'wiki' and enter
  4. Error messages:
Error detected while processing function 88[30]..<SNR>87_callback[25]..function 88[30]..<SNR>87_callback:
line   23:
Vim(let):E687: Less targets than List items

wikitags

neovim 0.10 with telescope under win10 pro

  • :WikiTags can work with default setting but not telescope under neovim 0.10 + win 10 pro, but neovim's default vim.ui.select haven't filter.

  • With telescope:

  1. restart nvim 0.10
  2. :WikiTags open a dialog with tag-page list
  3. filter with any text such as 'wiki' and enter
  4. Nothing happen but change the buffer name to 'd'

telescope

compare:

  1. :WikiTagSearch and :WikiPages can work both gvim and neovim(Regardless of whether Telescope is used) under win10 pro.
@VimWei
Copy link
Author

VimWei commented Jun 7, 2024

my VIMRC:

    Plug 'lervag/wiki.vim'
    Plug 'junegunn/fzf'
    Plug 'bullets-vim/bullets.vim'
    if has('nvim')
        Plug 'nvim-lua/plenary.nvim'
        Plug 'nvim-telescope/telescope.nvim'
    endif

and related plugin config:

@VimWei
Copy link
Author

VimWei commented Jun 7, 2024

About g:wiki_select_method help doc:

  1. For the Lua backend and Telescope section, should there not be parentheses () at the end?
  2. For the Telescope section, is there an extra ` symbol at the beginning?

image

@VimWei
Copy link
Author

VimWei commented Jun 7, 2024

If let g:wiki_fzf_tags_opts = '--preview "bat --color=always {2..}"', some garbled text appears here, corrupting the screen.

image

but let g:wiki_fzf_pages_opts = '--preview "cat {1}"' is working:

image

Update: Under windows, there is cat but no bat. Ignore this.

lervag added a commit that referenced this issue Jun 7, 2024
@lervag
Copy link
Owner

lervag commented Jun 7, 2024

First, I would be very glad if you could try and improve your grammar. I don't say that to be rude, it's just that some of your sentences are very difficult to understand. I think there are many great tools available today, e.g. Google translate and ChatGPT and similar.

gvim 9.1.0429 under win10 pro

  1. restart gvim 9.1.0429
  2. :WikiTags open a dialog with tag-page list
  3. filter with any text such as 'wiki' and enter
  4. Error messages:
Error detected while processing function 88[30]..<SNR>87_callback[25]..function 88[30]..<SNR>87_callback:
line   23:
Vim(let):E687: Less targets than List items

My first question is: what is the related configuration here? Is it the one you posted afterwards, i.e. https://github.com/VimWei/vim-init/blob/master/init/plugins.config/wiki.vim.vim? I'll assume so for the rest of my reply.

The error message you are seeing is from fzf, I think here:

https://github.com/junegunn/fzf/blob/590060a16b85270c19c605e8758cda16c4517086/plugin/fzf.vim#L1006

And it is quite hard to immediately understand what went wrong here. But I think it is this line:

let [l:tag, l:file, l:lnum] = split(a:input[1], ':')

Perhaps you could help verify that. If you add the following code in that file on your side:

  function! s:accept_tag(input) abort "{{{1
    let l:key = a:input[0]
+   let g:__test = [a:input]
    let [l:tag, l:file, l:lnum] = split(a:input[1], ':')
+   let g:__test += ["done"]

Then you repeat the steps you had to reproduce the error. After reproducing the error, can you report the output of :echo g:__test?

neovim 0.10 with telescope under win10 pro

I know it seems trivial, but it is very good if you can be fully explicit about the config you are using. E.g., in this case, I believe you changed g:wiki_select_method - but this is not in your wiki.vim.vim config file.

  • :WikiTags can work with default setting but not telescope under neovim 0.10 + win 10 pro, but neovim's default vim.ui.select haven't filter.

I believe you are saying that WikiTags work as expected on Neovim with default settings, but that it does not work if you use Telescope. That is, it does not work with this config:

    vim.g.wiki_select_method = {
      pages = require("wiki.telescope").pages,
      tags = require("wiki.telescope").tags,
      toc = require("wiki.telescope").toc,
      links = require("wiki.telescope").links,
    }

Is my understanding correct?

@VimWei
Copy link
Author

VimWei commented Jun 8, 2024

My first question is: what is the related configuration here? Is it the one you posted afterwards, i.e.

Yes, the related configuration is detailed in the following link: #365 (comment).

After incorporating the g:__test lines and replicating the steps, the resulting output from :echo g:__test is:
[['', 'Wiki: d:/WeirdData/wiki/Vim/neorg.md:2']]

Is my understanding correct?

Yes, your understanding is entirely correct.

I organize my vimrc in the following way: Each plugin's related configuration is stored in a file with the same name as the plugin, followed by a .vim extension, located in the vim-init/init/plugins.config/ directory. When I disable/enable a certain plugin, its related configuration is also disabled/enabled accordingly. This method makes it easier to enable or disable particular plugins and their configuration, preventing them from interfering with each other. For specific implementation, see:
https://github.com/VimWei/vim-init/blob/a4d8896cc91e9c4e7b29da1c4d62543d7761bdb3/init/plugins.vim#L241-L249

Therefore, I don't need to change any configurations in plugins.config/wiki.vim.vim and plugins.config/telescope.nvim.vim. I only need to modify whether the telescope plugin is enabled or not.

  1. g:wiki_select_method use wiki.vim's default setting: Vim utilizes fzf, while Neovim employs wiki.ui_select. Because there is no configuration for g:wiki_select_method in plugins.config/wiki.vim.vim. In this case, :WikiTags can work normally in Neovim but will cause errors in gvim.

    Plug 'lervag/wiki.vim'
    Plug 'junegunn/fzf'
    Plug 'bullets-vim/bullets.vim'
  2. Vim continues to utilize fzf, while Neovim has switched to using telescope. Because in plugins.config/telescope.nvim.vim, there is a configuration for g:wiki_select_method. In this case, :WikiTags will cause errors in both Neovim and gvim.

    Plug 'lervag/wiki.vim'
    Plug 'junegunn/fzf'
    Plug 'bullets-vim/bullets.vim'
    if has('nvim')
        Plug 'nvim-lua/plenary.nvim'
        Plug 'nvim-telescope/telescope.nvim'
    endif

I would be very glad if you could try and improve your grammar.

Thanks for your patience and understanding with my unclear expressions. Many of my previous expressions were actually completed with the help of ChatGPT, ^_^

@lervag
Copy link
Owner

lervag commented Jul 3, 2024

Sorry for my very late reply - it's been a very busy month!

My first question is: what is the related configuration here? Is it the one you posted afterwards, i.e.

Yes, the related configuration is detailed in the following link: #365 (comment).

After incorporating the g:__test lines and replicating the steps, the resulting output from :echo g:__test is: [['', 'Wiki: d:/WeirdData/wiki/Vim/neorg.md:2']]

Ah, thanks, that explains the problem! Since you are on Windows, and since Windows uses the d:/ to specify the drive and root instead of the unix variant which is simply /, the logic in this function breaks down. I've pushed an attempt at a fix!

Is my understanding correct?

Yes, your understanding is entirely correct.

:)

I organize my vimrc in the following way: Each plugin's related configuration is stored in a file with the same name as the plugin, followed by a .vim extension, located in the vim-init/init/plugins.config/ directory. When I disable/enable a certain plugin, its related configuration is also disabled/enabled accordingly. This method makes it easier to enable or disable particular plugins and their configuration, preventing them from interfering with each other. For specific implementation, see: https://github.com/VimWei/vim-init/blob/a4d8896cc91e9c4e7b29da1c4d62543d7761bdb3/init/plugins.vim#L241-L249

Yes, that sounds like a reasonable config concept.

  1. g:wiki_select_method use wiki.vim's default setting: Vim utilizes fzf, while Neovim employs wiki.ui_select. Because there is no configuration for g:wiki_select_method in plugins.config/wiki.vim.vim. In this case, :WikiTags can work normally in Neovim but will cause errors in gvim.

Yes, I think you're right.

  1. Vim continues to utilize fzf, while Neovim has switched to using telescope. Because in plugins.config/telescope.nvim.vim, there is a configuration for g:wiki_select_method. In this case, :WikiTags will cause errors in both Neovim and gvim. …

Let me know if my latest patch fixes things for you now.

I would be very glad if you could try and improve your grammar.

Thanks for your patience and understanding with my unclear expressions. Many of my previous expressions were actually completed with the help of ChatGPT, ^_^

No problem 😸

@VimWei
Copy link
Author

VimWei commented Jul 4, 2024

Thanks! I've upgraded the plugin and performed the same tests on Windows 10 Pro:

  1. gVim 9.1 with fzf: It is now functioning properly (there were errors before the update, but now there are none)!
  2. neoVim 0.10 with wiki.ui_select: It works normally (just as it did before the update).
  3. neoVim 0.10 with telescope.nvim: It still doesn't work, showing the same error as before the update—the buffer name changes to 'd' and the content is empty, instead of displaying the file corresponding to the wikitag.

@lervag
Copy link
Owner

lervag commented Jul 4, 2024

Thanks! I've upgraded the plugin and performed the same tests on Windows 10 Pro:

  1. gVim 9.1 with fzf: It is now functioning properly (there were errors before the update, but now there are none)!

  2. neoVim 0.10 with wiki.ui_select: It works normally (just as it did before the update).

Great!

  1. neoVim 0.10 with telescope.nvim: It still doesn't work, showing the same error as before the update—the buffer name changes to 'd' and the content is empty, instead of displaying the file corresponding to the wikitag.

Huh. I think I missed this in your original report. I'll look into it.

@lervag
Copy link
Owner

lervag commented Jul 4, 2024

Again I think it is because of the Windows path thing. But I'm not immediately sure how to fix it.

@lervag
Copy link
Owner

lervag commented Jul 4, 2024

The problem is here:

entry_maker = function(entry)
return {
value = entry[2],
display = entry[1],
ordinal = entry[1],
lnum = entry[3],
}

In line 72, we pass the file path to the value. The path is a full path and the value is what is used by telescope to open the file. Perhaps you could help investigate by adding something like this above the return {...?

vim.g.__test = entry

Then you can inspect the value afterwards with :echo g:__test and report the output here?

@lervag
Copy link
Owner

lervag commented Jul 4, 2024

To be clear, it is somewhat hard for me to debug this because I don't use Windows.

@lervag
Copy link
Owner

lervag commented Jul 4, 2024

I would expect that entry is a list/table with three entries, where the second one is a full path like this:

d:\WeirdData\wiki\IT\TiddlyWiki.md

Perhaps it will look like this instead:

d:/WeirdData/wiki/IT/TiddlyWiki.md

And if it does, then that might be the problem here.

Do you have shellslash enabled?

@VimWei
Copy link
Author

VimWei commented Jul 4, 2024

Do you have shellslash enabled?

Yes, I have shellslash enabled.

:echo g:__test

  1. Add vim.g.__test = entry above the return {.... in line 72.
  2. Restart nvim.
  3. :WikiTags, then search tag wiki and select the item TiddlyWiki.md.
  4. :echo g:__test, and return the following message which is not about TiddlyWiki.md.

['python Python/Python-Module-of-the-Week/Python-Module-of-the-Week.md:2', 'd:/WeirdData/wiki/Python/Python-Module-of-the-Week/Python-Module-of-the-Week.md', 2]

@lervag
Copy link
Owner

lervag commented Jul 4, 2024

Do you have shellslash enabled?

Yes, I have shellslash enabled.

Can you check if you have the same problem if you disable shellslash?

:echo g:__test

1. Add `vim.g.__test = entry` above the `return {....` in line 72.

2. Restart nvim.

3. `:WikiTags`, then search tag `wiki` and select the item `TiddlyWiki.md`.

4. `:echo g:__test`, and return the following message which is not about `TiddlyWiki.md`.

['python Python/Python-Module-of-the-Week/Python-Module-of-the-Week.md:2', 'd:/WeirdData/wiki/Python/Python-Module-of-the-Week/Python-Module-of-the-Week.md', 2]

This does in fact confirm my suspicion. I think, if you disable shellslash, that the path may become like a regular windows path with \ instead of /, and that this may fix the problem.

@lervag
Copy link
Owner

lervag commented Jul 4, 2024

Alternatively, you could try to make the following change here:

value = entry[2],

-           value = entry[2],
+           value = vim.fn.tr(entry[2], '/', '\\'),

@VimWei
Copy link
Author

VimWei commented Jul 5, 2024

Can you check if you have the same problem if you disable shellslash?

Disable shellslash, and test with :set shellslash?, display noshellslash.

  1. Add vim.g.__test = entry above the return {.... in line 72.
  2. Restart nvim.
  3. :WikiTags, then search tag wiki and select the item TiddlyWiki.md.
    • The result is displayed as before: buffer name changes to 'd' and the content is empty.
  4. :echo g:__test, and return the following message:
    • ['PDF Vim/Logseq.md:2', 'd:\WeirdData\wiki\Vim\Logseq.md', 2]

@lervag
Copy link
Owner

lervag commented Jul 5, 2024

Ok, thanks. So, shellslash is not relevant here. I assume my suggested solution to apply the vim.fn.tr() function also does not help?

@VimWei
Copy link
Author

VimWei commented Jul 5, 2024

I assume my suggested solution to apply the vim.fn.tr() function also does not help?

It does not help.

@lervag
Copy link
Owner

lervag commented Jul 7, 2024

Bummer. To be honest, I don't really have a clear idea of what is wrong here. I think we will need to debug this from your end.

Are you familiar with Lua and some programming already? I believe the solution will require a small modification to the code in the picker function, here:

function M.tags(opts)
local tags_with_locations = vim.fn["wiki#tags#get_all"]()
local length = 0
for tag, _ in pairs(tags_with_locations) do
if #tag > length then
length = #tag
end
end
local root = vim.fn["wiki#get_root"]()
local items = {}
for tag, locations in pairs(tags_with_locations) do
for _, loc in pairs(locations) do
local path_rel = vim.fn["wiki#paths#relative"](loc[1], root)
local str =
string.format("%-" .. length .. "s %s:%s", tag, path_rel, loc[2])
table.insert(items, { str, loc[1], loc[2] })
end
end
opts = opts or {}
local telescope_opts = vim.tbl_deep_extend("force", {
prompt_title = "Wiki Tags",
sorter = conf.generic_sorter(opts),
previewer = conf.grep_previewer(opts),
}, opts)
pickers
.new(telescope_opts, {
finder = finders.new_table {
results = items,
entry_maker = function(entry)
return {
value = entry[2],
display = entry[1],
ordinal = entry[1],
lnum = entry[3],
}
end,
},
})
:find()
end

I think the code until line 66 should be fine, really, and that this is related to the telescope API. But it's impossible to debug it for me since I can't reproduce it.

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

No branches or pull requests

2 participants