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

Refactored runtime/ftplugin/zig.vim, removed upstream comment, and removed aucmd and auto formatting support. #13803

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Tiseno
Copy link

@Tiseno Tiseno commented Dec 30, 2023

https://github.com/ziglang/zig.vim added auto formatting and linting (and population of the qflist) on save as a aucmd with an opt-out configuration, and was then merged into vim runtime. This seems to me like something that should be left up to that plugin and not be a part of vim.

It should probably be:
opt-in, as it is very unexpected behavior and uncharacteristic of vim to do something like this automatically
or removed entirely, as it should be left up to the user to register that kind of behavior if they want it through a plugin.
This PR does the latter.

I could not find any concrete guidelines of what built in file type plugins should and should not do, I am personally fine with whatever, opt-in, or remove the format/astcheck functionality. But in any case I think it should not register any aucmds by default without opting in to it (i.e. the check for opt in should be for registering the aucmd, not for running the formatter or not). I have noted that the rust filetype support also has a lot of options available as opt-in, and it also always registers an aucmd.
Is this the direction vim is moving in? i.e. upstreaming oppinionated plugins for integrating languages tightly?
My expectation before going down this rabbit hole was that built-in language supports only provided: filetype, filetype detection, syntax, indentation, and a makeprg.

The zig.vim plugin wants to be an ide-like plugin, and this PR removes the upstream dependency for the ftplugin implementation. I also made some consistency changes to the code in how undo_ftplugin is handled and added the zig_recommended_style as consistent with other ftplugins. The only significant thing left is the g:zig_std_dir/path and execution of zig env, which might also be up for discussion if it should be removed.

@habamax
Copy link
Contributor

habamax commented Dec 30, 2023

I believe autocmd that does autoformat should absolutely not happen by default.

@habamax
Copy link
Contributor

habamax commented Dec 30, 2023

I would also avoid all g:zig_std_dir set up:

" Safety check: don't execute zig from current directory
if !exists('g:zig_std_dir') && exists('*json_decode') &&
    \  executable('zig') && dist#vim#IsSafeExecutable('zig', 'zig')
    silent let s:env = system('zig env')
    if v:shell_error == 0
        let g:zig_std_dir = json_decode(s:env)['std_dir']
    endif
    unlet! s:env
endif

On windows gvim system() call looks ugly and you probably don't want to see cmd.exe window popup upon opening zig file.

Should be either opt-in or just a ftplugin help entry on how to set up g:zig_std_dir

@Tiseno Tiseno changed the title Refactored zig ftplugin, removed upstream comment, and removed aucmd and auto formatting support. Refactored runtime/ftplugin/zig.vim, removed upstream comment, and removed aucmd and auto formatting support. Dec 30, 2023
@dkearns
Copy link
Contributor

dkearns commented Dec 30, 2023

Is there a reason not to send your more general changes through the maintainer's repo?

@habamax
Copy link
Contributor

habamax commented Dec 30, 2023

Is there a reason not to send your more general changes through the maintainer's repo?

They might disagree with the proposed changes, but yeah it needs to be addressed there too(first?).

PS,
Do we have vim runtime files guide? What to avoid in ftplugin/syntax files?

@Tiseno
Copy link
Author

Tiseno commented Dec 31, 2023

The general changes can be added to the zig.vim plugin after the fact, if they want them.
This is a proposal to split from that plugin where vim maintains its own ftplugin implementation (as zig.vim wants to do things that should probably not be in the vim runtime).

And please note that I am only referring to runtime/ftplugin/zig.vim not the syntax/indentation/compiler implementations, I see no problem with those, so they can still be upstreamed.

@Tiseno
Copy link
Author

Tiseno commented Dec 31, 2023

Just as an example, the go ft plugin was split into two, one bare bones and one more ide-like.
https://github.com/google/vim-ft-go
https://github.com/fatih/vim-go
The former one was merged into vim and is now obsolete.
zig.vim is more comparable to the latter in what it wants to be.

Edit: And again, the rust ftplugin implementation also has exactly the same problem as noted. We have merged a lot of special and opinionated support for rust fmt and cargo, which I don't believe should be a part of the vim runtime either.
But that implementation at least has sensible opt-in defaults (I haven't checked all the options).
But it still always registers an auto command on save even when not opting in which seems wrong (prior to fc93594d562dbbd9da03c89754538f91efd0c7ca it did not).

let &l:define='\v(<fn>|<const>|<var>|^\s*\#\s*define)'
let b:undo_ftplugin = 'setl isk< fo< sua< mp< def<'

if get(g:, 'zig_recommended_style', 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if get(g:, 'zig_recommended_style', 1)

That variable should be documented. Please place a short section into runtime/doc/syntax.txt (e.g. see how it is done for other synax files, like :h ft-python-syntax . Don't forget to add a tag and update the last change header please.

@chrisbra chrisbra added the needs more work used for a pull request that isn't ready to include (other than needing a test) label Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more work used for a pull request that isn't ready to include (other than needing a test)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants