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

ObsidianTemplate command results in error with telescope #106

Closed
mertnuhoglu opened this issue Mar 21, 2023 · 19 comments · Fixed by #230
Closed

ObsidianTemplate command results in error with telescope #106

mertnuhoglu opened this issue Mar 21, 2023 · 19 comments · Fixed by #230
Labels
bug Something isn't working

Comments

@mertnuhoglu
Copy link

🐛 Describe the bug

:ObsidianTemplate command results in the following error:

Error executing Lua callback: ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:179: bad argument #1 to 'lower' (string expected, got table)
[C]: in function 'lower'
	...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:179: in function 'map'
	...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:275: in function 'attach_mappings'
	...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:187: in function 'apply_keymap'
	...ck/packer/start/telescope.nvim/lua/telescope/pickers.lua:540: in function 'find'
	...ker/start/telescope.nvim/lua/telescope/builtin/files.lua:245: in function 'v'
	...ker/start/telescope.nvim/lua/telescope/builtin/files.lua:458: in function 'v'
	...cker/start/telescope.nvim/lua/telescope/builtin/init.lua:476: in function 'find_files'
	...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:283: in function 'choose_template'
	...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:285: in function 'func'
	...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:549: in function <...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:548>

I disabled the telescope plugin and run the command with fzf-lua. This time the file selection window appeared correctly but template insertion didn't occur.

Versions

❯ nvim --version
NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Monterey

Features: +acl +iconv +tui
See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/local/Cellar/neovim/0.8.3/share/nvim"

Run :checkhealth for more info
❯ nvim --headless -c 'lua print(require("obsidian").VERSION)' -c q

1.8.0

@mertnuhoglu mertnuhoglu added the bug Something isn't working label Mar 21, 2023
@epwalsh
Copy link
Owner

epwalsh commented Mar 22, 2023

FYI @s-cassidy, maybe you can figure this out?

@mertnuhoglu can you tell me which commit of telescope you're on? I'll try to reproduce.

@shakesbeare
Copy link
Contributor

I've also run into this issue, the commit of telescope I'm on is b79cd6c88b3d96b0f49cb7d240807cd59b610cd8 and obsidian commit 26af6981d3217b27704c93b1dd90b22d9bd5e18e, both are just what vim plugged downloaded upon running PlugUpdate. Nvim version for me is NVIM v0.9.0-dev-1265+g410dc3349.

@s-cassidy
Copy link
Contributor

I'll have a look when I get the chance. fzf-lua not inserting is probably that stupid whitespace thing.

@s-cassidy
Copy link
Contributor

@mertnuhoglu could you post your obsidian.nvim config so I can try and reproduce?

@nikbrunner
Copy link

I have a similar error when running :ObsidianTemplate command:

image

This is my config:

return {
    "epwalsh/obsidian.nvim",
    lazy = true,
    event = "VeryLazy",
    dependencies = {
        "nvim-lua/plenary.nvim",
        "hrsh7th/nvim-cmp",
        "nvim-telescope/telescope.nvim",
    },
    opts = {
        dir = "~/Documents/notes/notes", -- no need to call 'vim.fn.expand' here

        -- Optional, if you keep daily notes in a separate directory.
        daily_notes = {
            folder = "Agenda",
        },

        -- Optional, completion.
        completion = {
            nvim_cmp = true, -- if using nvim-cmp, otherwise set to false
        },

        -- Optional, customize how names/IDs for new notes are created.
        -- Optional, for templates (see below).
        templates = {
            subdir = "Templates",
            date_format = "YY.MM.DD — dddd",
            time_format = "HH:mm",
        },

        -- Optional, customize how names/IDs for new notes are created.
        note_id_func = function(title)
            return title
        end,

        finder = "telescope.nvim",
    },
    config = function(_, opts)
        require("obsidian").setup(opts)

        -- Optional, override the 'gf' keymap to utilize Obsidian's search functionality.
        -- see also: 'follow_url_func' config option above.
        vim.keymap.set("n", "gd", function()
            if require("obsidian").util.cursor_on_markdown_link() then
                return "<cmd>ObsidianFollowLink<CR>"
            else
                return "gd"
            end
        end, { noremap = false, expr = true })
    end,
}

@lpanebr
Copy link

lpanebr commented May 21, 2023

I have the same error:

[Obsidian] ...ocal/share/nvim/lazy/obsidian.nvim/lua/obsidian/util.lua:465: 
...hare/nvim/lazy/telescope.nvim/lua/telescope/mappings.lua:308: 
Attach mappings must always return a value. `true` means use default mappings, `false` means only use attached mappings

Versions:

$ nvim --version

NVIM v0.10.0-dev-29+g436e0147f
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=always -fstack-protector-strong -DUNIT_TESTING -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/home/lpanebr/build/neovim/.deps/usr/include/luajit-2.1 -I/usr/include -I/home/lpanebr/build/neovim/.deps/usr/include -I/home/lpanebr/build/neovim/build/src/nvim/auto -I/home/lpanebr/build/neovim/build/include -I/home/lpanebr/build/neovim/build/cmake.config -I/home/lpanebr/build/neovim/src -I/usr/include -I/home/lpanebr/build/neovim/.deps/usr/include -I/home/lpanebr/build/neovim/.deps/usr/include -I/home/lpanebr/build/neovim/.deps/usr/include -I/home/lpanebr/build/neovim/.deps/usr/include -I/home/lpanebr/build/neovim/.deps/usr/include -I/home/lpanebr/build/neovim/.deps/usr/include

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

$ nvim --headless -c 'lua print(require("obsidian").VERSION)' -c q
1.10.0

@evtuhovich
Copy link
Contributor

The same bug, here the fix #137

epwalsh pushed a commit that referenced this issue May 23, 2023
* Fix bug in ObsidianTemplate with telescope

* Fix CHANGELOG for bug (#106) and PR (#137)
epwalsh added a commit that referenced this issue May 30, 2023
* Provide custom format for dailynotes file name

add type for config

* update README: indicate custom date format for daily notes

* Fix bug in ObsidianTemplate with telescope

* Apply suggestions from code review

custom date format: rename variables / adjust doc comments

Co-authored-by: Pete <epwalsh10@gmail.com>

* dailynotes: lint fix

dailynotes: lint fix

dailynotes: update changelog

* Fix CHANGELOG for bug (#106) and PR (#137)

* Fix CHANGELOG and README

* Rename format_date to date_format and change its type to string.

Add support for date_format to :ObsidianYesterday

Fix README and CHANGELOG

* Style fix for PR #138

---------

Co-authored-by: Anthony Balaine <abalaine@nexient.com>
Co-authored-by: Antoine Balaine <54488126+AntoineBalaine@users.noreply.github.com>
Co-authored-by: Pete <epwalsh10@gmail.com>
Co-authored-by: Antoine Balaine <abalaineaccts@gmail.com>
Co-authored-by: epwalsh <petew@allenai.org>
@evtuhovich
Copy link
Contributor

@lpanebr @nikbrunner @mertnuhoglu could you check with new version, this bug was fixed in #137

@nikbrunner
Copy link

Hi there,
yes it works! The only thing I am wondering about is that the placeholders don't get replaced. I don't know if this should work or not.

After insert it looks like this:

##  [[{{date:YY.MM.DD — dddd}}]]

> {{date:HH:mm}} 

...

@evtuhovich
Copy link
Contributor

@nikbrunner I have a same problem due to Obsidian datetime format (https://momentjs.com/docs/#/displaying/format/).

Now Obsidian.nvim supports only {{date}} {{time}} and {{title}}. So I plan to create separate daily journal template for obsidian.nvim

@s-cassidy
Copy link
Contributor

s-cassidy commented Jun 1, 2023

Hi there, yes it works! The only thing I am wondering about is that the placeholders don't get replaced. I don't know if this should work or not.

After insert it looks like this:

##  [[{{date:YY.MM.DD — dddd}}]]

> {{date:HH:mm}} 

...

This is correct; at the moment it only replaces the basic variables. If you set the date and title format in the Obsidian.md template settings you can set the format for all your templates without including the format string in the template. Then you can set an equivalent format in obsidian.nvim config using lua syntax. The same template should then work for both .md and .nvim -- it's only if you want different date/time formats for different templates that you need to format it in the template itself.

Converting in-template moment.js date/time formats to lua for full parity with obsidian.md is something I've started but isn't ready yet.

@lpanebr
Copy link

lpanebr commented Jun 1, 2023

it works. Thanks!

@tjex
Copy link

tjex commented Aug 23, 2023

Getting something similar:

Error executing Lua callback: ...te/pack/packer/start/obsidian.nvim/lua/obsidian/init.lua:443: attempt to index field 'opts' (a nil value)
stack traceback:
        ...te/pack/packer/start/obsidian.nvim/lua/obsidian/init.lua:443: in function '_run_with_finder_backend'
        ...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:297: in function 'func'
        ...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:672: in function <...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:671>

my conf:

require("obsidian").setup({
    -- Required, the path to your vault directory.
    dir = "~/tjroot/obsidian/paradigm-shifted",

    -- Optional, if you keep notes in a specific subdirectory of your vault.
    notes_subdir = "forrest-floor",

    -- Optional, set the log level for obsidian.nvim. This is an integer corresponding to one of the log
    -- levels defined by "vim.log.levels.*" or nil, which is equivalent to DEBUG (1).
    log_level = vim.log.levels.DEBUG,

    daily_notes = {
        -- Optional, if you keep daily notes in a separate directory.
        folder = "diaries",
        -- Optional, if you want to change the date format for daily notes.
        date_format = "%Y-%m-%d"
    },

    disable_frontmatter = true,

    templates = {
        subdir = "extra/templates",
        date_format = "%Y-%m-%d-%a",
        time_format = "%H:%M"
    },
})

Filepath to templates:

Screenshot 2023-08-23 at 18 11 59

@ngunyimacharia
Copy link

ngunyimacharia commented Nov 8, 2023

Got the same bug. Pined the package to https://github.com/epwalsh/obsidian.nvim/releases/tag/v1.11.0 and it works now. Seems a future commit re-introduced the bug

@epwalsh
Copy link
Owner

epwalsh commented Nov 8, 2023

@ngunyimacharia sorry about that, my last PR introduced the issue. Should be fixed now on main.

@ngunyimacharia
Copy link

Works well now, thank you for fixing this @epwalsh. Great work 🙌🏿

@tjex
Copy link

tjex commented Nov 8, 2023

Works for me now too :) Excellent!

@mertnuhoglu should the issue be closed?

@TristanLeclair
Copy link

TristanLeclair commented Nov 11, 2023

Is there any update on the fix for @mertnuhoglu's original problem? I'm getting the same issue.

Error executing Lua callback: ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:288: bad argument #1 to 'lower' (string expected, got table)
stack traceback:
        [C]: in function 'lower'
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:288: in function 'map'
        ...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:318: in function 'attach_mappings'
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:296: in function 'apply_keymap'
        ...ck/packer/start/telescope.nvim/lua/telescope/pickers.lua:561: in function 'find'
        ...r/start/telescope.nvim/lua/telescope/builtin/__files.lua:305: in function 'v'
        ...r/start/telescope.nvim/lua/telescope/builtin/__files.lua:533: in function 'v'
        ...cker/start/telescope.nvim/lua/telescope/builtin/init.lua:510: in function 'find_files'
        ...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:327: in function 'choose_template'
        ...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:330: in function <...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:307>
        .../pack/packer/start/obsidian.nvim/lua/obsidian/client.lua:487: in function '_run_with_finder_backend'
        ...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:306: in function 'func'
        ...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:743: in function <...pack/packer/start/obsidian.nvim/lua/obsidian/command.lua:742>

obsidian.nvim

Versions

OS: Windows 10
using WSL Ubuntu:22.04
uname -r : 5.15.90.1-microsoft-standard-WSL2

nvim --version

NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by runner@fv-az178-366

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/share/nvim"

Run :checkhealth for more info

nvim --headless -c 'lua print(require("obsidian").VERSION)' -c q

1.16.0

On telescope commit 76ea9a898d3307244dce3573392dcf2cc38f340f (have to use old version for nvim 0.8)

@epwalsh
Copy link
Owner

epwalsh commented Nov 12, 2023

@TristanLeclair this is a compatibility issue with old versions of Telescope. I've fixed this in #230.

@epwalsh epwalsh linked a pull request Nov 12, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants