serenevoid / kiwi.nvim

A stripped down VimWiki for neovim
https://serenevoid.github.io/blog/my-note-taking-plugin
GNU General Public License v3.0
166 stars 9 forks source link

Duplication of path on new entry creation (MacOS) #21

Open avastmick opened 2 months ago

avastmick commented 2 months ago

While this plugin looks promising, I cannot get it work as expected with more than one notes location.

My configuration:

return {
    'serenevoid/kiwi.nvim',
    dependencies = {
        "nvim-lua/plenary.nvim"
    },
    opts = {
        {
            name = "work",
            path = "/Users/avastmick/notes/edu-docs"
        },
        {
            name = "personal",
            path = "/Users/avastmick/notes/local-notes"
        }
    },
    keys = {
        { "<leader>kw", ":lua require(\"kiwi\").open_wiki_index(\"work\")<cr>",     desc = "Open Wiki index" },
        { "<leader>kp", ":lua require(\"kiwi\").open_wiki_index(\"personal\")<cr>", desc = "Open index of personal wiki" },
        { "T",          ":lua require(\"kiwi\").todo.toggle()<cr>",                 desc = "Toggle Markdown Task" }
    },
    lazy = true
}

Usage:

I open the personal and add in a line 'Daily Plan', select words and , I get the following path (see the status line)

image

I hit Ctrl+o to return to index.md, hovered link does not show duplicated path elements:

image

If I remove the leading ./ from the new link, navigates to a new file in the directory I opened nvim.

avastmick commented 2 months ago

Sorry, update, the behaviour is now regardless of the number of wiki locations: I thought it was working for one, but it was actually creating files in the wrong place.

serenevoid commented 2 months ago

Hi @avastmick! Thanks for reporting this issue. I have two questions though.

avastmick commented 2 months ago

Hi @avastmick! Thanks for reporting this issue. I have two questions though.

  • Is the index file created in the correct location for these two wiki locations?
  • This path trimming is failing only when the notes are created from the wiki note?

Firstly, yes, an index.md is created. Secondly, yes, when I create a new note the path is duplicated as per the screenshot in the OP.

I spent a bit of time trying to reproduce and when I create two empty wiki, the path handling is consistent with your GH README. In fact, I thought that the issue was resolved and all good. However, when I return to either wiki with an index.md created (say in a new nvim session), any new pages show the path duplication issue.

The path issue only occurs on an existing wiki. The behaviour is consistent. Have an index.md, create a new page, and the page is created in a nonexistent path that is duplicated.

Could this be a plugin clash? My list of plugins are as follows:

.
├── alpha-nvim.lua
├── cmp.lua
├── db-ui.lua
├── harpoon.lua
├── init.lua
├── kiwi.lua
├── leap.lua
├── lsp.lua
├── lualine.lua
├── neogit.lua
├── no-neck-pain.lua
├── noice.lua
├── oil.lua
├── rustaceanvim.lua
├── surround.lua
├── telescope.lua
├── themes.lua
├── todo-comments.lua
├── treesitter.lua
├── undotree.lua
└── which-key.lua

Thanks for the work on this and getting back so promptly on the issue I raised. The issue may be found between the computer and the chair 😀

serenevoid commented 2 months ago

Thank you for the details! I could reproduce the issue. Will update the plugin soon! And to answer your questions,

avastmick commented 2 months ago

Thanks for resolving. Great stuff!

tarurata commented 3 weeks ago

@avastmick

It seems the variable "relative_path" includes "config.path", which is the absolute path to each wiki, such as "path like path = '/Users/testuser/personal-wiki'" on Mac. Therefore, "relative_path" works as an absolute path.

To bypass this issue for now, I overwrote the method "utils.get_relative_path" as shown below in "init.vim". (Of course, you can simplify it further by returning empty strings without an if clause.)

lua << EOF
-- https://github.com/serenevoid/kiwi.nvim/issues/21
local utils = require'kiwi.utils'

local is_windows = vim.loop.os_uname().version:match('Windows')

utils.get_relative_path = function (config)
    local relative_path = vim.fs.dirname(vim.fn.expand('%:p'))
    if is_windows then
        -- For Windows, replace backslashes with forward slashes in the config path
        return relative_path:gsub(config.path:gsub("\\", "/"), "")
    else
        -- For macOS, return the relative path directly
        return ""
    end
end
EOF
serenevoid commented 1 week ago

@avastmick @tarurata I have added a new commit for fixing this issue. Please have a look when you find time. Hope to hear from you soon.

mlwarner commented 1 week ago

The latest change broke my setup using Obsidian and iCloud. I think this line in ensure_directories:

props.path = props.path:gsub("$HOME", get_home()):gsub("~", get_home())

conflicts with my config:

local wikiPath = '/Users/mwarner/Library/Mobile Documents/iCloud~md~obsidian/Documents/my_notes'
require('kiwi').setup({
    {
        name = 'personal',
        path = wikiPath,
    },
})
serenevoid commented 1 week ago

@mlwarner Thanks for your response. I have rolled back the plugin. Please try updating the plugin again. If update fails, try reinstalling the plugin.

mlwarner commented 1 week ago

Thanks! I unpinned the commit and it is working as expected.

I think you are looking for path expansion here rather than a substitution. Quick scan through vim help docs has vim.fn.expand. Testing with :lua =vim.fn.expand("/Users/mwarner/Library/Mobile Documents/iCloud~md~obsidian/Documents/my_notes") yields the same path, and :lua =vim.fn.expand("~/wiki") also works as expected.