alker0 / chezmoi.vim

Highlight dotfiles you manage with chezmoi.
Other
119 stars 3 forks source link

vim.opt.filetype is empty on non-chezmoi files #74

Closed Nitestack closed 4 months ago

Nitestack commented 5 months ago

Like the title says, the filetype (when I checked the filetype with set filetype) is empty when I edit non-chezmoi files in the chezmoi source dir.

For example, I want to edit a regular Lua file without templating, which is located in the chezmoi source dir. Some treesitter functionalities are not working because filetype is empty

When I removed the plugin from the spec, filetype was lua (when I checked the filetype with set filetype) as usual. I can't tell which commit it was that caused this.

My config looks like this

-- chezmoi.lua.tmpl
{
  "alker0/chezmoi.vim",
  lazy = false,
  init = function()
    vim.g["chezmoi#source_dir_path"] = "{{ .chezmoi.sourceDir }}"
    vim.g["chezmoi#use_tmp_buffer"] = true
  end,
}
alker0 commented 5 months ago

Thank you for reporting this. However I'm still unable to reproduce this.

I need more information to be able to reproduce this:

  1. Your Neovim is Windows version?
  2. What does :echo v:version (when editing a file) show?
  3. Do both chezmoi edit ~/path/to/dest/file and nvim ~/path/to/src/file show same behavior?
  4. What does chezmoi execute-template '{{ println .chezmoi.config.edit.hardlink }}' show?
  5. Does it change anything if you disable each your plugin except chezmoi.vim and nvim-treesitter?

Please try running these command in your non-chezmoi file and tell outputs if you don't care about privacy of your dotfiles directory structure:

Nitestack commented 5 months ago
  1. Yes
  2. 801
  3. Yes
  4. true
  5. No

Output for first command:

4:23:41 PM msg_show   scriptnames   1: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\ftplugin.vim
  2: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\indent.vim
  3: ~\AppData\Local\nvim\init.lua
  4: ~\AppData\Local\bob\nightly\nvim-win64\share/nvim/runtime/filetype.lua
  5: ~\AppData\Local\nvim-data\lazy\catppuccin\colors\catppuccin.vim
  6: ~\AppData\Local\bob\nightly\nvim-win64\share/nvim/runtime/plugin/editorconfig.lua
  7: ~\AppData\Local\bob\nightly\nvim-win64\share/nvim/runtime/plugin/man.lua
  8: ~\AppData\Local\bob\nightly\nvim-win64\share/nvim/runtime/plugin/nvim.lua
  9: ~\AppData\Local\bob\nightly\nvim-win64\share/nvim/runtime/plugin/osc52.lua
 10: ~\AppData\Local\bob\nightly\nvim-win64\share/nvim/runtime/plugin/shada.vim
 11: ~\AppData\Local\bob\nightly\nvim-win64\share/nvim/runtime/plugin/spellfile.vim
 12: ~\AppData\Local\nvim-data\lazy\chezmoi.vim\filetype.vim
 13: ~\AppData\Local\bob\nightly\nvim-win64\share/nvim/runtime/syntax/syntax.vim
 14: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\syntax\synload.vim
 15: ~/AppData/Local/nvim-data/lazy/dashboard-nvim/plugin/dashboard.lua
 16: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\autoload\provider\clipboard.vim
 17: ~/AppData/Local/nvim-data/lazy/smart-splits.nvim/plugin/init.lua
 18: ~/AppData/Local/nvim-data/lazy/smart-splits.nvim/plugin/smart-splits.lua
 19: ~\AppData\Local\nvim-data\lazy\smart-splits.nvim\autoload\smart_splits.vim
 20: ~/AppData/Local/nvim-data/lazy/nvim-treesitter-textobjects/plugin/nvim-treesitter-textobjects.vim
 21: ~/AppData/Local/nvim-data/lazy/vim-matchup/plugin/matchup.vim
 22: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\plugin\matchparen.vim
 23: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup.vim
 24: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup\perf.vim
 25: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup\loader.vim
 26: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup\matchparen.vim
 27: ~/AppData/Local/nvim-data/lazy/nvim-ts-autotag/plugin/nvim-ts-autotag.vim
 28: ~/AppData/Local/nvim-data/lazy/nvim-treesitter/plugin/nvim-treesitter.lua
 29: ~\AppData\Local\nvim-data\sessions\C%%Users%<user>%.dotfiles.vim
 30: ~/AppData/Local/nvim-data/lazy/bigfile.nvim/after/plugin/bigfile.lua
 31: ~/AppData/Local/nvim-data/lazy/indent-blankline.nvim/after/plugin/commands.lua
 32: ~/AppData/Local/nvim-data/lazy/mason-tool-installer.nvim/plugin/mason-tool-installer.lua
 33: ~/AppData/Local/nvim-data/lazy/cmp-nvim-lsp/after/plugin/cmp_nvim_lsp.lua
 34: ~/AppData/Local/nvim-data/lazy/nvim-vtsls/plugin/init.lua
 35: ~/AppData/Local/nvim-data/lazy/nvim-lspconfig/plugin/lspconfig.lua
 36: ~/AppData/Local/nvim-data/lazy/nvim-treesitter-context/plugin/treesitter-context.lua
 37: ~/AppData/Local/nvim-data/lazy/vim-illuminate/plugin/illuminate.vim
 38: ~/AppData/Local/nvim-data/lazy/todo-comments.nvim/plugin/todo.vim
 39: ~/AppData/Local/nvim-data/lazy/which-key.nvim/plugin/which-key.vim
 40: ~/AppData/Local/nvim-data/lazy/vim-sleuth/plugin/sleuth.vim
 41: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\syntax\template.vim
 42: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\syntax\html.vim
 43: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\syntax\xml.vim
 44: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\syntax/dtd.vim
 45: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\syntax\javascript.vim
 46: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\syntax\vb.vim
 47: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\syntax\css.vim
 48: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup\ts_engine.vim
 49: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup\re.vim
 50: ~\AppData\Local\nvim-data\lazy\chezmoi.vim\autoload\chezmoi\filetype.vim
 51: ~\AppData\Local\nvim-data\lazy\chezmoi.vim\syntax\chezmoitmpl.vim
 52: ~\AppData\Local\nvim-data\lazy\chezmoi.vim\syntax/gotmpl.vim
 53: ~\AppData\Local\nvim-data\lazy\chezmoi.vim/vendor/vim-go/syntax/gotmpl.vim
 54: ~/AppData/Local/nvim-data/lazy/nvim-web-devicons/plugin/nvim-web-devicons.vim
 55: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup\pos.vim
 56: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup\delim.vim
 57: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup\util.vim
 58: ~/AppData/Local/nvim-data/lazy/LuaSnip/plugin/luasnip.lua
 59: ~/AppData/Local/nvim-data/lazy/LuaSnip/plugin/luasnip.vim
 60: ~/AppData/Local/nvim-data/lazy/cmp_luasnip/after/plugin/cmp_luasnip.lua
 61: ~/AppData/Local/nvim-data/lazy/cmp-path/after/plugin/cmp_path.lua
 62: ~/AppData/Local/nvim-data/lazy/cmp-buffer/after/plugin/cmp_buffer.lua
 63: ~/AppData/Local/nvim-data/lazy/nvim-cmp/plugin/cmp.lua
 64: ~/AppData/Local/nvim-data/lazy/cmp-cmdline/after/plugin/cmp_cmdline.lua
 65: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\ftplugin\lua.vim
 66: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\ftplugin\lua.lua
 67: ~\AppData\Local\nvim-data\lazy\vim-matchup\after\ftplugin\lua_matchup.vim
 68: ~\AppData\Local\bob\nightly\nvim-win64\share\nvim\runtime\indent\lua.vim
 69: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup\ts_syntax.vim
 70: ~\AppData\Local\nvim-data\lazy\vim-matchup\autoload\matchup\quirks.vim

Output for second command:

chezmoi#use_tmp_buffer  v:true
chezmoi#source_dir_path  C:/Users/<user>/.dotfiles/home
chezmoi#_loaded       #1
b:chezmoi_source_path  C:/Users/<user>/.dotfiles/home/.config/nvim/lua/plugins/codeium.lua
b:chezmoi_default_detect_target  C:/Users/<user>/.dotfiles/home/.config/nvim/lua/plugins/codeium.lua
alker0 commented 5 months ago

The details you've given are very helpful for me, thank you. I will look into the cause of the problem.

xfzv commented 4 months ago

I'm experiencing the same behavior on Neovim nightly:

% nvim -v
NVIM v0.10.0-dev-3024+g158e32972-dirty

It doesn't occur on 0.9.5 with the same setup:

return {
  "alker0/chezmoi.vim",
  init = function()
    vim.g["chezmoi#source_dir_path"] = "{{ .chezmoi.sourceDir }}"
    vim.g["chezmoi#use_tmp_buffer"] = true
  end,
}

Likewise, running set ft in any *.tmpl file returns filetype=chezmoitmpl, which results in no syntax highlighting at all in *.tmpl files.

Again, this only occurs on Neovim nightly for me, it works as expected on 0.9.5.

alker0 commented 4 months ago

Hi @xfzv, thank you for your reporting it. However, the original issue was reported before v0.10 is released, so a v0.10-only problem could come from other causes. Please open another issue ticket with a description of the behavior that you are experiencing.

alker0 commented 4 months ago

@xfzv, Sorry for my confusing you with a wrong direction. I made a mistake and thought the Neovim v0.10 has just released. The original reporter, Nitestack could use v0.10 as well in according to the dotfiles repo. The information you have given, that the problem occurs in only v0.10, should help me a lot to reproduce the behavior and find a cause of this issue. Thank you.

xfzv commented 4 months ago

No worries. I assume OP is also using Nightly considering the multiple ~\AppData\Local\bob\nightly lines.

I'm using tree-sitter 0.22.5 (on Linux).

Feel free to let me know if you need additional details that could help.

alker0 commented 4 months ago

Updating this plugin should make it work for you with setting correct file type even in Neovim v0.10.

xfzv commented 4 months ago

Can confirm #77 fixes the issue on my end with 0.10.

Thank you!