nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
3.03k stars 134 forks source link

Error collapsing heading after refreshing agenda #243

Closed schultzter closed 8 months ago

schultzter commented 2 years ago

Describe the bug

I get the error message attempt to index local 'file' (a nil value) when trying to collapse a TODO heading I have opened prior to refreshing (r) the agenda view.

I noticed this in :checkhealth but the missing file, highlights.scm, is there when I check in the directory (as well as injections.scm).

## The following errors have been detected:
  - ERROR: org(highlights): ...s\Neovim\share\nvim\runtime/lua/vim/treesitter/query.lua:161: query: error at position 672
    org(highlights) is concatenated from the following files:
    | [ERROR]:"C:\Users\redacted\AppData\Local\nvim-data\site\pack\paqs\start\orgmode\queries\org\highlights.scm", failed to load: ...s\Neovim\share\nvim\runtime/lua/vim/treesitter/query.lua:161: query: error at position 672

...

vim.treesitter: require("vim.treesitter.health").check()
========================================================================
  - INFO: Runtime ABI version : 13
  - OK: Loaded parser for org: ABI version 13
  - OK: Loaded parser for c: ABI version 13

Steps to reproduce

  1. open an org file
  2. expand at least one TODO headline
  3. view the agenda
  4. refresh the agenda
  5. attempt to collapse the TODO headline previously expanded
  6. expand any other TODO headline
  7. attempt to collapse those TODO headlines

Expected behavior

Headlines will collapse without error.

Emacs functionality

It works!

Minimal init.lua

-- Load custom tree-sitter grammar for org filetyp\ require('orgmode').setup_ts_grammar()

-- Tree-sitter configuration require'nvim-treesitter.configs'.setup { -- If TS highlights are not enabled at all, or disabled via disable prop, highlighting will fallback to default Vim syntax highlighting highlight = { enable = true, disable = {'org'}, -- Remove this to use TS highlighter for some of the highlights (Experimental) additional_vim_regex_highlighting = {'org'}, -- Required since TS highlighter doesn't support all syntax features (conceal) }, ensure_installed = {'org'}, -- Or run :TSUpdate org }

require('orgmode').setup({ org_agenda_files = 'C:/Users/redact/Documents/Notebooks/*', org_default_notes_file = 'C:/Users/redact/Documents/Notebooks/refile.org', org_todo_keywords = {'TODO', 'INPROGRESS', 'WAITING','DONE'} })

Screenshots and recordings

image

OS / Distro

Windows 10

Neovim version/commit

0.6.1

Additional context

My home directory, ~, is different when working from home (local c:\users\redacted) vs at the office (network mounted m:)

kristijanhusak commented 2 years ago

Did this start to happen recently? If yes, could you try changing back to commit https://github.com/nvim-orgmode/orgmode/commit/e1f3054987ce054525258d9a3cc5837bf6e75212 and test to see if it happens there (you will have to o ":TSUpdate org" because that commit uses older tree-sitter parser)

schultzter commented 2 years ago

I only noticed it this morning, my first morning back in the office. But I've only been using orgmode since a few days last week (at home).

I googled some git commands but I can't figure out how to change back to a specific commit. Would you mind explaining to me how to do that using the Paq package manager? Or specific git commands. Sorry, but I feel as though git was specifically engineered to befuddled me.

kristijanhusak commented 2 years ago

I'm not sure where WIndows puts the plugins, but I'm assuming this section will help you. Once you find nvim-orgmode folder, go into it and do git reset --hard e1f3054987ce054525258d9a3cc5837bf6e75212. That should put you on the older commit. Then open up Neovim, execute :TSUpdate org, and restart Neovim. Then give it a try.

schultzter commented 2 years ago

Thanks. I tried that but it doesn't work!

Can I just download that commit, in a zip, and overwrite my Paq installation? Or remove it from Paq and manage it manually for now?

schultzter@host MINGW64 /c/Users/schultzter/AppData/Local/nvim-data/site/pack/paqs/start/orgmode (master)
$ git reset --hard e1f3054987ce054525258d9a3cc5837bf6e75212
fatal: Could not parse object 'e1f3054987ce054525258d9a3cc5837bf6e75212'.
kristijanhusak commented 2 years ago

Can you try doing git fetch --depth 999 first and then try the same command? I think Paq is not fetching history when installed, that's why it didn't work.

schultzter commented 2 years ago

Ok, that last suggestion got it working.

And then I ran :TSUpdate org but I still get the error message.

image

kristijanhusak commented 2 years ago

Ok, i think you misunderstood the order of commands. Do it in this order:

schultzter commented 2 years ago

Ok, I did all those steps and I still get the same error (originally I didn't restart Neovim after updating the treesitter).

schultzter@host MINGW64 ~/AppData/Local/nvim-data/site/pack/paqs/start/orgmode (master)
$ git fetch --depth 999
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0

schultzter@host MINGW64 ~/AppData/Local/nvim-data/site/pack/paqs/start/orgmode (master)
$ git reset --hard e1f3054987ce054525258d9a3cc5837bf6e75212
HEAD is now at e1f3054 Merge pull request #231 from jgollenz/fix/open-template-by-shortcut

schultzter@host MINGW64 ~/AppData/Local/nvim-data/site/pack/paqs/start/orgmode (master)
$

image

kristijanhusak commented 2 years ago

Thanks for testing it out. Does other things work when you do this, like changing todo state or adding tags?

schultzter commented 2 years ago

No, other things don't work either after I refresh the Agenda!

<leader>cit gave me this error: Failed to parse current file... image

<leader>ot, ois, and oid all gave me the same error!

If I reload the file, with :e! then all those commands work again until I go to my Agenda window and hit r to rebuild it.

Here's a copy of that org:

#+TITLE: Personal

* Agenda                                                            :@agenda:
  Things to discuss
* Call                                                                :@call:
  Calls to make
** DONE Call about Easter Brunch
   CLOSED: [2022-04-06 Wed 17:17] SCHEDULED: <2022-04-06 Wed>
   Bring the berry/fruit salad
   They will bring their own bread
** DONE Call aunt about Easter Brunch
   CLOSED: [2022-04-06 Wed 14:23] SCHEDULED: <2022-04-06 Wed>
   Make sure she has a ride
** INPROGRESS Call clinic to make follow appointment 
   SCHEDULED: <2022-04-07 Thu>
   Follow-up with doctor for excessive nostril hair
* Computer                                                        :@computer:
  Things to do on the computer/internet
** TODO Shop for headphone 6' cable with r-angle plug
   To connect from back of docking station to headphones
* Errand                                                            :@errand:
  Things to go and do somewhere, including printing stuff out
** DONE Print calendars 
   CLOSED: [2022-04-06 Wed 15:28] SCHEDULED: <2022-04-06 Wed>
   Start with April
cheif commented 2 years ago

I'm also experiencing this exact problem, this is my machine:

OS / Distro

MacOS 12.3.1

Neovim version/commit

0.6.1 & 0.7.0

I hope that I'll be able to look into this a bit more myself as well, but can't promise anything 😉

kristijanhusak commented 2 years ago

Are you guys using latest master and latest tree-sitter version? TS grammar got some update last night, so it might fix some of these issues. I can't reproduce them. Just try with latest master, and do :TSUpdate org to get latest grammar version.

cheif commented 2 years ago

I just tested with latest master/NVIM 0.7.0 and updated grammar, and the symptoms are still there, but it seems like the crash has moved.

I'm getting an error in lua/orgmode/parser/mappings.lua:100, saying that file is nil. /lua/orgmode/org/mappings.lua:100: attempt to index local 'file' (a nil value)

I'm using a symlink for my orgfiles (and have them on iCloud drive), and I think this might be the culprit. As far as I understood @schultzter had a similar setup. I tried adding some print logging around in files.lua, and it seems like it's using different paths when trying to update Files.orgfiles vs. when retriving them.

An example is that it's setting: Files.orgfiles[/Users/cheif/org/my.org] = 0x00a9a09a and then trying to read: Files.orgfiles[/Users/cheif/Library/Mobile Documents/com~apple~CloudDocs/org/my.org which is the resolved symlink.

kristijanhusak commented 2 years ago

@cheif could you just give it a try and see if it works properly when you are using it directly (without symlink)? Symlinks seems to work fine on Linux for me, but I'm not sure about Windows/Mac Os.

cheif commented 2 years ago

Ok, so I tried some more, and setting org_agenda_files and org_default_notes_file to the non-symlinked version seems to do the trick, so something is fishy with symlinks on Windows/MacOS it seems at least.

kristijanhusak commented 2 years ago

Thanks for testing it out. When you open up file that is symlinked, what does this return for you?

:lua print(vim.api.nvim_buf_get_name(0))

Is it returning full path to symlinked file or full path to the original file (in the iCloud folder)?

Also, if you do this, does it return list of paths to symlinked files or to original files?

:lua print(vim.inspect(vim.fn.glob('/path/to/symlinked/folder/*', 0, 1)))
kristijanhusak commented 2 years ago

@cheif Ok I managed to reproduce it locally. Current buffer name was returning original name, while everything loaded was from symlink. Try pulling latest master and see if it works.

cheif commented 2 years ago

@kristijanhusak I tried master just now, but the problem seems to persist unfortunately 😢

Thanks for testing it out. When you open up file that is symlinked, what does this return for you? :lua print(vim.api.nvim_buf_get_name(0))

/Users/cheif/Library/Mobile Documents/com~apple~CloudDocs/org/my.org So this returns the full path.

Also, if you do this, does it return list of paths to symlinked files or to original files? :lua print(vim.inspect(vim.fn.glob('/path/to/symlinked/folder/*', 0, 1)))

{ /Users/cheif/org/my.org } (and some more org-files others) So this returns paths to the symlink.

Also tried :lua print(vim.fn.bufname()) which returned: org/my.org

kristijanhusak commented 2 years ago

I completely forgot to get full path of the bufname. Can you pull latest master and see if it's fixed now? If not, please let me know what this returns:

:lua print(vim.fn.fnamemodify(vim.fn.bufname(), ':p'))
cheif commented 2 years ago

Unfortunately still seems to be an issue on latest master.

:lua print(vim.fn.fnamemodify(vim.fn.bufname(), ':p'))

/Users/cheif/Library/Mobile Documents/com~apple~CloudDocs/org/my.org

kristijanhusak commented 2 years ago

Damn, it's so inconsistent.

glob() for you returns paths to the symlinked folder, while other things (bufname, nvim_buf_get_name) return real paths. According to docs this should give you list of files with real paths, but I'm not sure if that's really the case. Can you please check?

:lua print(vim.inspect(vim.fn.glob('/path/to/symlinked/folder/*', 0, 1, true)))
cheif commented 2 years ago

:lua print(vim.inspect(vim.fn.glob('/path/to/symlinked/folder/*', 0, 1, true)))

{ "/Users/cheif/org/my.org" } (and other org-files) so this just gives me the symlinks.

kristijanhusak commented 2 years ago

Ok I just pushed another fix. Hopefully this one should work. Now even glob will return the full paths instead of symlinked ones. Could you do a pull and test?

cheif commented 2 years ago

Tested master now, and it seems to be working for me!

Great work @kristijanhusak! 🍾

kristijanhusak commented 2 years ago

Awesome, thanks for your help! I wouldn't be able to figure it out on my own.

Maltimore commented 2 years ago

@cheif I think the issue can be closed then? edit: my bad, the issue was opened by @schultzter

schultzter commented 2 years ago

Good morning

No, other things don't work either after I refresh the Agenda!

cit gave me this error: Failed to parse current file... [image: image.png] ot, ois, and oid all gave me the same error! If I reload the file, with :e! then all those commands work again until I go to my Agenda window and hit 'r' to rebuild it. Here's a copy of that org: #+TITLE: Personal * Agenda ***@***.***: Things to discuss * Call ***@***.***: Calls to make ** DONE Call about Easter Brunch CLOSED: [2022-04-06 Wed 17:17] SCHEDULED: <2022-04-06 Wed> Bring the berry/fruit salad They will bring their own bread ** DONE Call aunt about Easter Brunch CLOSED: [2022-04-06 Wed 14:23] SCHEDULED: <2022-04-06 Wed> Make sure she has a ride ** INPROGRESS Call clinic to make follow appointment SCHEDULED: <2022-04-07 Thu> Follow-up with doctor for excessive nostril hair * Computer ***@***.***: Things to do on the computer/internet ** TODO Shop for headphone 6' cable with r-angle plug To connect from back of docking station to headphones * Errand ***@***.***: Things to go and do somewhere, including printing stuff out ** DONE Print calendars CLOSED: [2022-04-06 Wed 15:28] SCHEDULED: <2022-04-06 Wed> Start with April -- Headed for the second star to the right and straight on 'til morning... Eric Schultz On Thu, Apr 7, 2022 at 1:04 AM Kristijan Husak ***@***.***> wrote: > Ok, i think you misunderstood the order of commands. Do it in this order: > > - git fetch --depth 999 > - git reset --hard e1f3054987ce054525258d9a3cc5837bf6e75212 > - Open Neovim, run :TSUpdate org, restart Neovim > - Try to reproduce an issue > > — > Reply to this email directly, view it on GitHub > , > or unsubscribe > > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
kristijanhusak commented 2 years ago

@schultzter are you sure this file is problematic? Do you have any other files?

iacs commented 1 year ago

For what its worth, I'm also having the same error "Failed to parse current file." etc My agenda opens in a vsplit, and I'm also loading a symlinked file. :lua print(vim.api.nvim_buf_get_name(0)) returns the path to the symlink, not the true file, which is in my Dropbox

kristijanhusak commented 8 months ago

Closing as outdated. If the problem persists, please open up a separate issue. Thanks.