lervag / wiki.vim

A wiki plugin for Vim
MIT License
642 stars 69 forks source link

List index out of range for `wiki#graph#find_backlinks` #373

Closed diskfault closed 1 month ago

diskfault commented 1 month ago

Description

First of all, I just wanted to say thank you very much for this plugin. It is incredibly good, simple, and fast. I was hoping not to file an issue, as I really have had none and found most of my answers through the manual but this one has stumped me, unfortunately. All the same, thank you again for making this, it's very useful.

Description of steps leading to issue

  1. Files created in wiki root
  2. Initialised as git folder
  3. Links are in markdown format
  4. One file, _sidebar.md contains a link, in wiki format, to /folder_a/a1.md (herein a1.md); please see minimal working example below for folder structure
  5. /folder_a/index.md and /_sidebar.md both point to /folder_a/a1.md
  6. /_sidebar.md also points to /folder_a/index.md
  7. a1.md is renamed, using <leader>wr, to foo.md
  8. _sidebar.md does not update
  9. /folder_a/index.md does update
  10. Manually update link in _sidebar.md
  11. Delete _sidebar.md
  12. <leader>wgb within a1.md throws an error (interestingly, /folder_a/index.md does not, using the same shortcut, but was not renamed at all); I believe it references this line
  13. Error does not occur if _sidebar.md is created again, with at least the link to a1.md present (no other links required)

Expected behaviour

Ideally, deletion of files has no effect; I am not sure where or how the existing backlinks per wiki are stored but perhaps that it removes the file if it is not found, or asks the user to confirm it has been deleted, perhaps.

Barring this, I am happy to delete a1.md and restore a back up, but I would like the ability to rename files using the shortcut and subsequently delete files the backlink to the current file without error, if possible.

Minimal working example

Please provide a minimal working example, for instance something like this:

/path/to/minimal-working-example-wiki
├── index.md
├── folder a
│   └── index.md
│   └── a1.md
└── test.md

The file contents should of course also be included if necessary. Please also provide a minimal vimrc file, e.g.

call plug#begin()

" for goyo
Plug 'vim-voom/VOoM'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'

" for writing
Plug 'kana/vim-textobj-user'
Plug 'preservim/vim-pencil'
Plug 'preservim/vim-textobj-quote'
Plug 'preservim/vim-textobj-sentence'
Plug 'preservim/vim-wordchipper'

" for text highlighting
Plug 'inkarkat/vim-mark'
Plug 'inkarkat/vim-ingo-library'

" for formatting
Plug 'lervag/lists.vim'
Plug 'dhruvasagar/vim-table-mode'

" for markdown
Plug 'vim-pandoc/vim-pandoc'
Plug 'vim-pandoc/vim-pandoc-syntax'

" for wiki
Plug 'lervag/wiki.vim'

" for telescope
Plug 'nvim-telescope/telescope.nvim' ", { 'tag': '0.1.8' }
Plug 'nvim-lua/plenary.nvim'
Plug 'BurntSushi/ripgrep'
Plug 'nvim-telescope/telescope-fzf-native.nvim'
Plug 'nvim-treesitter/nvim-treesitter'

" for colour scheme
Plug 'https://git.sr.ht/~leon_plickat/paige'

call plug#end()

" for meta use
set nocompatible
filetype plugin on
filetype plugin indent on

" for colours
syntax on

:colorscheme pablo

set termguicolors

" for writing
let g:pencil#wrapModeDefault = 'soft'

augroup pencil
    autocmd!
    autocmd FileType markdown,mkd   call pencil#init()
    autocmd FileType text       call pencil#init({'wrap': 'hard'})
augroup END

augroup textobj_quote
    autocmd!
    autocmd FileType markdown call textobj#quote#init()
augroup END

" for markdown
set conceallevel=2
let g:pandoc#syntax#conceal#urls = 1

" for wiki
let g:wiki_root = '~/wiki/doc/pages'

let g:wiki_link_creation = {
            \ 'md': {
            \   'link_type': 'md',
            \   'url_extension': '',
            \   'url_transform': { x ->
            \       substitute(tolower(x), '\s\+', '-', 'g')},
            \ }
            \}
diskfault commented 1 month ago

Closing as this was fixed by restarting (perhaps just by closing all nvim instances). A new UI issue arose during subsequent testing, however;

  1. Rename file using <leader>wr
  2. wiki: Updated 1 links in 1 file
  3. <leader>wgb; wiki: No other file links to this file
  4. Rename file using <leader>wr
  5. wiki: Updated 1 links in 1 file
  6. <leader>wgb; wiki: No other file links to this file
  7. Check /folder_a/index.md for link; change has been made
  8. (after some time) <leader>wgb shows backlinks correctly

Note especially steps 3 and 6 (and possibly 8). Whilst, after checking, this is not really a cause for concern (as the function of the renaming works), it does cause some confusion, especially when not familiar with the current UI functionality. I can make a new issue for this, if that would help?

lervag commented 1 month ago

First of all, I just wanted to say thank you very much for this plugin. It is incredibly good, simple, and fast.

Thanks for the kind words! ♥️

I was hoping not to file an issue,

Don't worry, I don't mind issues! They help me improve the plugin!

as I really have had none and found most of my answers through the manual but this one has stumped me, unfortunately.

Based on your last comment, I understand that the following part was no longer an issue. Let me know if I understood wrong.

Regarding your config:

call plug#begin()

" …

call plug#end()

" for meta use
set nocompatible
filetype plugin on
filetype plugin indent on

" for colours
syntax on

You can remove the lines after plug#end above. set nocompatible is not necessary in vimrc files and filetype ... and syntax on is done by plug#end().

lervag commented 1 month ago

A new UI issue arose during subsequent testing, however;

  1. Rename file using <leader>wr
  2. wiki: Updated 1 links in 1 file
  3. <leader>wgb; wiki: No other file links to this file

Ok, so, given two files foo.wiki and bar.wiki, where foo has a link to bar. Then you do <leader>wr in bar.wiki and rename it to baz.wiki. Your point is that <leader>wgb now unexpectedly shows "No other file links to this file"? While, at the same time, the renaming did work as expected, right?

  1. (after some time) <leader>wgb shows backlinks correctly

The <leader>wgb is a graph feature, and the graph uses caching. So if the graph becomes "wrong" it should correct itself.

However, the specific case here seems to be something we should be able to avoid. I would be happy if you could open a new issue for it; I'll then try to reproduce locally and fix it.

diskfault commented 1 month ago

Hi @lervag, thank you very much for your response and glad to know that my issue was welcome!

As per your understanding, yes that is correct. Insofar as I can tell, the issue may have been due to have one too many nvim instances open (and perhaps having _sidebar.md in ls after following the wikilink from there to another file).

Thank you also for your comments regarding my init.vim; I have now cleaned that up. Always nice to lose lines wherever possible.

Regarding the subsequent behaviour described, that is good to know why it may not immediately update the graph. As per your description of the process;

Ok, so, given two files foo.wiki and bar.wiki, where foo has a link to bar. Then you do <leader>wr in bar.wiki and rename it to baz.wiki. Your point is that <leader>wgb now unexpectedly shows "No other file links to this file"? While, at the same time, the renaming did work as expected, right?

That is a correct summation of what occurs. As you note, this does eventually correct itself. All the same, I shall open a new issue to this effect, referencing this one.

Thanks again!

lervag commented 1 month ago

Thank you also for your comments regarding my init.vim; I have now cleaned that up. Always nice to lose lines wherever possible.

My pleasure; and yes, I also like to keep things as short as possible. :)

That is a correct summation of what occurs. As you note, this does eventually correct itself. All the same, I shall open a new issue to this effect, referencing this one.

Great, I'll look at it when I get the time!