alker0 / chezmoi.vim

Highlight dotfiles you manage with chezmoi.
Other
128 stars 4 forks source link

Can't figure how to get it to work #45

Closed xfzv closed 1 year ago

xfzv commented 2 years ago
❯  nvim --version
NVIM v0.8.0
Build type: Release
LuaJIT 2.1.0-beta3

I'm using wbthomason/packer.nvim to manage my plug-ins, including this one (loaded early, as suggested in the README:

https://github.com/alker0/chezmoi.vim/blob/7fd839d7fa275e7ffc4b11e2f1d99527c9024681/README.md?plain=1#L56

Relevant part of my plugins.lua:

vim.api.nvim_command('packadd packer.nvim')
function get_setup(name)
  return string.format('require("setup/%s")', name)
end

return require('packer').startup({
  function(use)
    use { 'wbthomason/packer.nvim' }
    use { 'lewis6991/impatient.nvim', config = get_setup('impatient') }
    use { 'alker0/chezmoi.vim', config = get_setup('chezmoi') }
-- ...

I'm using a custom source dir path for chezmoi, so I use:

-- ~/.config/nvim/lua/setup/chezmoi.lua
vim.cmd ([[ let g:chezmoi#source_dir_path = "~/dotfiles" ]])

This seems to work as expected:

image

However, I'm not getting any syntax highlighting at all. Here are various screenshots:

Screenshots - regular `~/.zshenv` (top) and `dot_zshenv` (bottom) ![image](https://user-images.githubusercontent.com/78810647/197205249-f8990d7a-7226-4e78-8773-70576c1ca13a.png) - `.chezmoiignore` in source dir: ![image](https://user-images.githubusercontent.com/78810647/197206223-eadc65a9-b357-4082-9849-3ae7aaf7a2b5.png) - After running `:set ft=chezmoitmpl` manually: ![image](https://user-images.githubusercontent.com/78810647/197206406-60b11a13-f456-4a32-adef-eca713d41787.png)

Not sure what I'm doing wrong, any advice is appreciated. Thanks!


Edit:

let chezmoi#_loaded

image

Is this normal? Not sure if it means 0 because # is treated as a comment or if it's actually 1 aka plug-in disabled.

xfzv commented 2 years ago

I partially solved my issue by using:

vim.cmd ([[ let g:chezmoi#source_dir_path = "~/dotfiles" ]])

in my plugins.lua file before loading the plug-in. Partially because while it works for dot_zshenv or dot_zshrc, many of my chezmoi files that have some go templates in it such as:

are still not having proper syntax highlighting. It works fine for two .ini.tmpl and .js.tmpl files I have for some reasons. Seems quite erratic.


I re-read Packer documentation and thought I could use setup = instead of config = to run this command before the plugin is load with my current method, but it doesn't seem to work.

xfzv commented 2 years ago
More screenshots where the syntax highlighting isn't correct: - `user-overrides.js.tmpl` (go-template syntax isn't applied): ![image](https://user-images.githubusercontent.com/78810647/197868777-c6fb43be-2691-492a-804a-38eb8e8438fc.png) - `.chezmoi.yml.tmpl` (no syntax highlighting at all): ![image](https://user-images.githubusercontent.com/78810647/197869752-1b46573b-1ad5-4b65-9b54-5d2cd0ab8f29.png) - `.chezmoiexternal.yml` (yaml syntax highlighting is correct only until a go-template section, then it's broken until the end of the file): ![image](https://user-images.githubusercontent.com/78810647/197870215-13b4fb28-de6b-4928-8092-0cbefdef53a4.png) - `musiclib-grpc-server.service.tmpl` (go template syntax is correct in the first part, broken in the second): ![image](https://user-images.githubusercontent.com/78810647/197871164-70ac3978-28b6-49c6-82a6-d5169b97c183.png)
alker0 commented 2 years ago

Hi. Thank you for your catching.

Missing highlighting in .chezmoi*.yml should be fixed by #47 (it has processed yaml but not yml before).

For highlighting *.service.tmpl correctly, it seems to need special adjustment for merging syntax systemd and go-template. I'll split it out as a new issue.

For user-override.js.tmpl, more details needed. Please tell the file path from your chezmoi's source directory if you don't mind.

For the core problem this issue that integration with neovim, lua and packer, I don't know how do combination and configuration of these affect ordering around file type detection yet. I don't use neovim and need to make time for making similar environment and reproduction. Please give me a few months to start once being free.

alker0 commented 2 years ago

Is this normal? Not sure if it means 0 because # is treated as a comment or if it's actually 1 aka plug-in disabled.

A prefix # means the value is number type (not string). So calling :let foo = 0, :let bar = '0' and :let should show:

foo   #0
bar    0
xfzv commented 2 years ago

Missing highlighting in .chezmoi*.yml should be fixed by https://github.com/alker0/chezmoi.vim/pull/47 (it has processed yaml but not yml before).

Doesn't seem to work after updating:

image

After manually running :set ft=yml.chezmoitmpl:

image

For highlighting *.service.tmpl correctly, it seems to need special adjustment for merging syntax systemd and go-template. I'll split it out as a new issue.

Thanks, will try when it's merged.

For user-override.js.tmpl, more details needed. Please tell the file path from your chezmoi's source directory if you don't mind.

~/dotfiles/dot_mozilla/firefox/default-release/user-overrides.js.tmpl

alker0 commented 1 year ago

Please update it and check if it enables highlighting automatically for below files.

For passing options to this plugin in managed by packer, you need to define manually because both setup = and config = don't run before file type detection. In packer settings, the config = option runs a script after loaded the plugin, and setup = does before but after file type detection, does it start to watch the plugin be going to load. setup = seems to focus to help you run scripts lazily rather than early for good at combining the plugin and a plugin-specific script and make it wait custom trigger together.

Please ask anything if you still get (excepting about .service.tmpl you can track in #48) , or close it.

xfzv commented 1 year ago

Please update it and check if it enables highlighting automatically for below files.

* `.chezmoiignore`

* `.chezmoiexternal.yml`

* `.chezmoi.yml.tmpl`

* `user-overrides.js.tmpl`

Nothing changed after updating to recent commits unfortunately.

Only .chezmoiignore has proper syntax highlighting but it worked fine prior to updating.

.chezmoiexternal.yml, .chezmoi.yml.tmpl and user-overrides.js.tmpl still have incorrect syntax highlighting (see screenshots from previous posts)

For passing options to this plugin in managed by packer, you need to define manually because both setup = and config = don't run before file type detection. In packer settings, the config = option runs a script after loaded the plugin, and setup = does before but after file type detection, does it start to watch the plugin be going to load. setup = seems to focus to help you run scripts lazily rather than early for good at combining the plugin and a plugin-specific script and make it wait custom trigger together.

I'm just using:

vim.cmd([[ let g:chezmoi#source_dir_path = "/home/{{ .chezmoi.username }}/dotfiles" ]])

in my plugins.lua.tmpl file before the use function where my plugins are loaded. I load alker0/chezmoi.vim without any additional packer option.

I don't think I need anything else?

let chezmoi#_loaded
chezmoi#_loaded              #1

let chezmoi#source_dir_path
chezmoi#source_dir_path      /home/xfzv/dotfiles
alker0 commented 1 year ago

hmm... What does running this show? This shows updated time and where packer installed it into, if using packer, it needs to be in start/ , or opt/ doesn't work.

# With bracket keeps your current directory
(cd ~/.local/share/nvim/site/pack/packer && stat -c "%n,%y" ./*/chezmoi.vim{,/*} | column -t -s,)

If it's in opt/, you need to reinstall this plugin manually via:

  1. Comment out use { 'alker0/chezmoi.vim' }
  2. Restart neovim and run PackerSync
  3. Uncomment use { 'alker0/chezmoi.vim' }
  4. Restart neovim and run PackerSync

By the way, for getting ordering of startup phases verbosely, you can run this.

echo > /tmp/foo.txt && nvim --startuptime /tmp/foo.txt ~/dotfiles/.chezmoi.yml.tmpl '+quit' && nvim /tmp/foo.txt

And it should show like (if succeeded):

/tmp/foo.txt
times in msec
 clock   self+sourced   self:  sourced script
 clock   elapsed:              other lines

000.005  000.005: --- NVIM STARTING ---
000.077  000.072: event init
000.169  000.092: ...MANY...
000.169  000.092: ...LINES...
003.479  000.059  000.059: sourcing /usr/share/nvim/runtime/ftplugin.vim
003.545  000.032  000.032: sourcing /usr/share/nvim/runtime/indent.vim
005.048  000.148  000.148: require('packer.XXX')
005.048  000.148  000.148: ...MANY...
005.048  000.148  000.148: ...LINES...
006.362  002.781  000.147: sourcing /home/alker/.config/nvim/init.lua
006.367  000.589: sourcing vimrc file(s)
=================================== Ordering of some lines below is the most important. =========================
006.627  000.230  000.230: sourcing /home/alker/.local/share/nvim/site/pack/packer/start/chezmoi.vim/filetype.vim
006.857  000.187  000.187: sourcing /usr/share/nvim/runtime/filetype.lua
007.048  000.097  000.097: sourcing /usr/share/nvim/runtime/syntax/synload.vim
007.207  000.305  000.208: sourcing /usr/share/nvim/runtime/syntax/syntax.vim
007.867  000.282  000.282: ...MANY...
007.867  000.282  000.282: ...LINES...
009.954  000.238  000.238: require('setup/impatient')
009.956  000.423  000.185: sourcing /home/alker/.config/nvim/plugin/packer_compiled.lua
010.097  000.040  000.040: sourcing /usr/share/nvim/runtime/plugin/man.lua
010.105  000.779: ...SOME...
010.105  000.779: ...LINES...
011.044  000.807: reading ShaDa
011.406  000.119  000.119: sourcing /home/alker/.local/share/nvim/site/pack/packer/start/chezmoi.vim/autoload/chezmoi/filetype.vim
012.259  000.709  000.709: require('vim.filetype')
012.797  000.040  000.040: sourcing /usr/share/nvim/runtime/ftplugin/yaml.vim
013.283  000.114  000.114: sourcing /usr/share/nvim/runtime/indent/yaml.vim
014.052  000.669  000.669: sourcing /usr/share/nvim/runtime/syntax/yaml.vim
014.305  000.033  000.033: sourcing /usr/share/nvim/runtime/ftplugin/yaml.vim
015.026  000.017  000.017: sourcing /usr/share/nvim/runtime/indent/yaml.vim
015.749  000.581  000.581: sourcing /usr/share/nvim/runtime/syntax/yaml.vim
016.053  000.148  000.148: sourcing /home/alker/.local/share/nvim/site/pack/packer/start/chezmoi.vim/vendor/vim-go/syntax/gotmpl.vim
016.055  000.162  000.014: sourcing /home/alker/.local/share/nvim/site/pack/packer/start/chezmoi.vim/syntax/gotmpl.vim
016.099  000.239  000.077: sourcing /home/alker/.local/share/nvim/site/pack/packer/start/chezmoi.vim/syntax/chezmoitmpl.vim
016.511  002.947: opening buffers
016.525  000.015: BufEnter autocommands
016.527  000.002: editing files in windows
xfzv commented 1 year ago

hmm... What does running this show? This shows updated time and where packer installed it into, if using packer, it needs to be in start/ , or opt/ doesn't work.

# With bracket keeps your current directory
(cd ~/.local/share/nvim/site/pack/packer && stat -c "%n,%y" ./*/chezmoi.vim{,/*} | column -t -s,)
./start/chezmoi.vim               2022-11-10 11:17:37.527066452 +0100
./start/chezmoi.vim/after         2022-10-29 15:34:56.633189244 +0200
./start/chezmoi.vim/autoload      2022-10-29 15:34:56.633189244 +0200
./start/chezmoi.vim/filetype.vim  2022-11-10 11:17:37.527066452 +0100
./start/chezmoi.vim/.git          2022-11-12 10:53:34.550462466 +0100
./start/chezmoi.vim/LICENSE       2022-10-29 15:34:56.633189244 +0200
./start/chezmoi.vim/README.md     2022-10-29 15:34:56.633189244 +0200
./start/chezmoi.vim/syntax        2022-10-29 15:34:56.633189244 +0200
./start/chezmoi.vim/vendor        2022-10-29 15:34:56.633189244 +0200

By the way, for getting ordering of startup phases verbosely, you can run this.

echo > /tmp/foo.txt && nvim --startuptime /tmp/foo.txt ~/dotfiles/.chezmoi.yml.tmpl '+quit' && nvim /tmp/foo.txt

And it should show like (if succeeded): /tmp/foo.txt

/tmp/foo.txt ``` times in msec clock self+sourced self: sourced script clock elapsed: other lines 000.010 000.010: --- NVIM STARTING --- 004.629 000.053 000.053: sourcing /usr/share/nvim/runtime/ftplugin.vim 004.953 000.030 000.030: sourcing /usr/share/nvim/runtime/indent.vim 008.475 000.268 000.268: require('packer.util') 015.653 010.572 000.027: sourcing /home/xfzv/.config/nvim/init.lua 015.667 001.713: sourcing vimrc file(s) 015.863 000.115 000.115: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/chezmoi.vim/filetype.vim 016.778 000.009 000.009: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/chezmoi.vim/filetype.vim 016.925 000.009 000.009: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/filetype.vim 016.978 000.011 000.011: sourcing /usr/share/nvim/runtime/filetype.vim 017.113 000.013 000.013: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/LuaSnip/ftdetect/snippets.vim 017.284 000.011 000.011: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/neorg/ftdetect/norg.vim 017.466 000.010 000.010: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-fugitive/ftdetect/fugitive.vim 017.538 000.024 000.024: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-kitty/ftdetect/kitty.vim 017.599 000.012 000.012: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/ftdetect/polyglot.vim 017.662 000.011 000.011: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/yuck.vim/ftdetect/yuck.vim 017.779 000.011 000.011: sourcing /usr/share/vim/vimfiles/ftdetect/PKGBUILD.vim 017.802 000.008 000.008: sourcing /usr/share/vim/vimfiles/ftdetect/SRCINFO.vim 030.932 014.433 014.302: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/autoload/polyglot/init.vim 030.958 014.714 000.281: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/filetype.vim 031.062 000.056 000.056: sourcing /usr/share/nvim/runtime/filetype.lua 031.094 000.013 000.013: sourcing /usr/share/nvim/runtime/filetype.vim 032.416 000.075 000.075: sourcing /usr/share/nvim/runtime/syntax/synload.vim 032.543 001.367 001.292: sourcing /usr/share/nvim/runtime/syntax/syntax.vim 160.725 009.068 000.033: require('plugins/impatient') 240.328 202.563 002.079: sourcing /home/xfzv/.config/nvim/plugin/packer_compiled.lua 240.660 000.115 000.115: sourcing /usr/share/nvim/runtime/plugin/man.lua 282.412 001.595: reading ShaDa 284.157 000.214 000.214: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/chezmoi.vim/autoload/chezmoi/filetype.vim 285.822 000.188 000.188: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/ftplugin/yaml.vim 286.243 000.113 000.113: sourcing /usr/share/nvim/runtime/ftplugin/yaml.vim 288.214 000.236 000.236: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/indent/yaml.vim 288.401 000.129 000.129: sourcing /usr/share/nvim/runtime/indent/yaml.vim 290.081 000.996 000.996: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/syntax/yaml.vim 290.337 000.148 000.148: sourcing /usr/share/nvim/runtime/syntax/yaml.vim 316.947 000.033 000.033: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-matchup/autoload/matchup/re.vim 318.386 000.074 000.074: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/ftplugin/yaml.vim 318.723 000.013 000.013: sourcing /usr/share/nvim/runtime/ftplugin/yaml.vim 323.711 000.064 000.064: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/indent/yaml.vim 323.801 000.013 000.013: sourcing /usr/share/nvim/runtime/indent/yaml.vim 325.687 000.624 000.624: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/syntax/yaml.vim 325.793 000.011 000.011: sourcing /usr/share/nvim/runtime/syntax/yaml.vim 327.055 000.265 000.265: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/chezmoi.vim/vendor/vim-go/syntax/gotmpl.vim 327.060 000.394 000.129: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/chezmoi.vim/syntax/gotmpl.vim 327.100 000.587 000.193: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/chezmoi.vim/syntax/chezmoitmpl.vim 330.892 000.950 000.950: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/vim-polyglot/syntax/yaml.vim 331.005 000.011 000.011: sourcing /usr/share/nvim/runtime/syntax/yaml.vim 331.919 000.135 000.135: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/chezmoi.vim/vendor/vim-go/syntax/gotmpl.vim 331.925 000.162 000.027: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/chezmoi.vim/syntax/gotmpl.vim 331.962 000.243 000.082: sourcing /home/xfzv/.local/share/nvim/site/pack/packer/start/chezmoi.vim/syntax/chezmoitmpl.vim 337.539 048.979: opening buffers 340.168 002.573: BufEnter autocommands 340.174 000.006: editing files in windows ```
alker0 commented 1 year ago

Please try the latest and re-check if it works. But it might not do for .chezmoiignore, and if so, please run these and tell the output.

xfzv commented 1 year ago

Please try the latest and re-check if it works. But it might not do for .chezmoiignore, and if so, please run these and tell the output.

* `:set filetype`

* `:echo substitute(execute('let'), '\n\%(b:chezmoi_\|b:current_syntax\)\@![^\n]*', '', 'g')`

After updating, .chezmoiignore still has proper syntax highlighting, the other problematic files still don't.

Some files have correct syntax highligthing and some other don't as far as I'm concerned.

Does this work fine on your end for example? it doesn't here.

The correct filetype is set automatically (yaml.chezmoitmpl) but there is no syntax highlighting at all:

image

For this file, running :echo substitute(execute('let'), '\n\%(b:chezmoi_\|b:current_syntax\)\@![^\n]*', '', 'g') gives me:

b:chezmoi_default_detect_target    /home/xfzv/dotfiles/test.yaml
b:chezmoi_source_path    /home/xfzv/dotfiles/test.yaml
b:chezmoi_original_filetype    yaml
alker0 commented 1 year ago

My neovim environment still doesn't reproduce the issue so I don't sure this comes from.

nvim --version shows:

NVIM v0.8.0-1210-gd367ed9b2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by runner@fv-az505-656

Features: +acl +iconv +tui

In ~/.config/nvim/lua/plugins.lua: plugin-lua

In ~/dotfiles/test-sh.toml and ~/dotfiles/test-yaml.toml: test-sh test-yaml

This may come from integration with others. Please try toggling On/Off each plugins (e.g. with disabled of packer option) and tell whether any works correctly.

xfzv commented 1 year ago

Please try toggling On/Off each plugins (e.g. with disabled of packer option) and tell whether any works correctly.

Will do and report back. Thanks for your time. :bow:

xfzv commented 1 year ago

I finally found the culprit :tada: - it's nvim-treesitter. Everything is fine without it:

image

image

and the highlighting issues come back as soon as I enable it again.

Closing because it's definitely not an issue with chezmoi.vim. I don't know how to keep tree-sitter enabled while using chezmoi.vim though. The disabled option is only for actual parsers, not file types.


Edit: Maybe with a function as documented here?


Feel free to let me know if you have any idea about this.

Thank you again for your time and your help!

xfzv commented 1 year ago

Using additional_vim_regex_highlighting = true seems to works just fine.

Edit: My bad, it doesn't make any difference. I forgot to run :PackerCompile after re-enabling tree-sitter. :man_facepalming:

alker0 commented 1 year ago

Yes! :tada: I'm glad I could help you and also fix and improve it. Thank you for a lot of time and response for my many questions.