terrastruct / d2-vim

The Vim plugin for D2 files
https://d2-lang.com
BSD 3-Clause "New" or "Revised" License
67 stars 6 forks source link

Undefined variable: g:d2_block_string_syntaxes #3

Closed bmizerany closed 1 year ago

bmizerany commented 1 year ago

Using

~ % vim --version
NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by bmizerany@blaptopvm

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

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

I installed d2-vim using vim's built-in plugins like:

; git clone https://github.com/terrastruct/d2-vim/ /home/bmizerany/.config/nvim/pack/github/start/d2-vim

Current HEAD is d1cb1e7e22bc0fb4d4034a1b93c2a13cc471acc6

When I opened vim x.d2, I got:

Error detected while processing /home/bmizerany/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/bmizerany/.config/nvim/init.lua:5: Vim(if):E121: Undefined variable: g:d2_block_string_syntaxes
stack traceback:
        [C]: in function 'cmd'
        /home/bmizerany/.config/nvim/init.lua:5: in main chunk
Press ENTER or type command to continue

I tried pre-defining in my ~/.vimrc like:

" d2
let g:d2_block_string_syntaxes = {
        \ 'd2': ['d2'],
        \ 'markdown': ['md', 'markdown'],
        \ 'javascript': ['javascript', 'js'],
        \ 'html': ['html'],
        \ 'json': ['json'],
        \ 'c': ['c'],
        \ 'go': ['go'],
        \ 'sh': ['sh', 'ksh', 'bash'],
        \ 'css': ['css'],
        \ 'vim': ['vim'],
        \ }

but that didn't help.

I'm a little stumped because my vim-script fu is weak. Any pointers would be appreciated.

pyrho commented 1 year ago

I have this issue too, on NVIM v0.8.0-dev-1025-gfb39bba5a-dirty.

I was not able to understand where the error comes from neither, all functions referencing d2_block_string_syntaxes appears to check for its existence before hand. And this variable is defined fairly early too.

One interesting thing I found is that if you open n*vim first, then open a d2 file you won't have an issue. The issue only shows when you open the file directly (ie. vim test.d2).

pleshevskiy commented 1 year ago

One interesting thing I found is that if you open n*vim first, then open a d2 file you won't have an issue.

Thank you for your explanation! Now I've reproduced it, too.

nhooyr commented 1 year ago

I'm not sure why but I'm not able to reproduce this issue. I'm on NVIM v0.9.0-dev-280+gfae754073 and don't have that variable predefined in my init.vim.

nhooyr commented 1 year ago

Do you guys have a syntax on or filetype plugin on somewhere in your init.vim?

pleshevskiy commented 1 year ago

yes

nhooyr commented 1 year ago

You don't need either in neovim, try removing and see if it works without error.

pleshevskiy commented 1 year ago

I checked on minimal configuration. It's true. syntax on broke this plugin.

I think it's very strange...

=============================================================================

  1. Quick start :syn-qstart

          *:syn-enable* *:syntax-enable* *:syn-on* *:syntax-on*

    Syntax highlighting is enabled by default. If you need to enable it again after it was disabled (see below), use: >

    :syntax enable

Alternatively: >

:syntax on

And I have to enable syntax on to enable syntax folding

nhooyr commented 1 year ago

If you add a filetype plugin on before syntax on things should work I think.

nhooyr commented 1 year ago

Though you shouldn't need syntax on for folding.

nhooyr commented 1 year ago

Just a friendly ping to see if you guys were able to fix by putting filetype plugin on before syntax on.

wyardley commented 1 year ago

FWIW, adding filetype plugin on before syntax on did resolve this issue for me.

wyardley commented 1 year ago

If this isn't "fixable", might be good to add a docs note about this in the README. I've never needed to set that up for other syntax plugins.

(side note: I'm using pathogen, if it matters)

alixander commented 1 year ago

hmm yeah, i'll leave this open after all then

pleshevskiy commented 1 year ago

I've already fixed this in MR. Why you don't want to merge it?

alixander commented 1 year ago

yeah i think if people are running into this with non-outlier vim configs, we should merge that. @nhooyr your call though

nhooyr commented 1 year ago

Ok I'll concede, there's supposed to be an order but perhaps in practice it's not strictly followed. I approved #5

wyardley commented 1 year ago

Confirmed #5 resolves this for me (with vanilla vim 9), even if i remove filetype plugin on again.