Skip to content

Unlike as documented g:ale_root may only be a Dictionary, not a String #5002

@rymdbar

Description

@rymdbar

Information

VIM version

VIM - Vi IMproved 9.1 (2024 Jan 02, compiled May 28 2025 06:19:53)
Included patches: 1-1415

Operating System: Alpine Linux 3.22.0

What went wrong

According to :help ale_root the valid Types for the variable are either Dictionary or String. While this is true for b:ale_root, g:ale_root may only be a Dictionary.

The failure goes boom! For example vim example.vim gives:

Error detected while processing BufWinEnter Autocommands for "*"..function ale#events#LintOnEnter[5]..ale#Queue[33]..<SNR>32_Lint[37]..ale#eng
ine#RunLinters[4]..<SNR>38_GetLintFileValues[27]..<lambda>5[1]..<SNR>38_RunLinters[18]..<SNR>38_RunLinter[2]..ale#lsp_linter#CheckWithLSP[1]..
ale#lsp_linter#StartLSP[3]..ale#lsp_linter#FindProjectRoot:
line   19:
E1206: Dictionary required for argument 1

Reproducing the bug

:ALEInfo

Expand No need for boilerplate spam when only one variable is set in `.vimrc`.

Consider for example these two files, saved as /tmp/example/root.lua and /tmp/example/subdir/child.lua.

require "subdir/child"

function Conflicting()
    print "I am implemented in the root directory"
end

Conflicting()
function Conflicting()
    print "I am implemented in the sub directory"
end

Conflicting()

One could run these, but that's not where we're going. Instead we add a .vimrc with these contents:

augroup lua
    " autocmd FileType lua let b:ale_root = { 'lua_language_server': '/tmp/example' }
    " autocmd FileType lua let b:ale_root = { 'lua_language_server': '/tmp/example/subdir' }
    " autocmd FileType lua let b:ale_root = '/tmp/example'
    " autocmd FileType lua let b:ale_root = '/tmp/example/subdir'
augroup END

" let g:ale_root = { 'lua_language_server': '/tmp/example/subdir' }
" let g:ale_root = { 'lua_language_server': '/tmp/example' }

" let g:ale_root = '/this-value-does-not-matter-as-the-type-explodes'

Try opening up child.lua and call :ALEFindReferences on Conflicting() in order to make it obvious whether setting the ale_root worked or not. Oh, yeah! All of the lines of .vimrc were commented out. So the fun stuff starts when changing which ale_root to set, and thus which type it becomes. Play around with uncommenting as desired and compare with the initially collapsed message here immediately below once satisfied:

Spoiler All but the very last one works!

The error explosion happens in autoload/ale/events.vim. As illustrated with using both vim and lua among the examples, the issue is unrelated to languages or tools.

Maybe fixing this will or could be done with #4993?

While on the topic of ale_root. Isn't it strange that the dictionary works with only a linter, shouldn't it require a language + linter combination? That would of course be a breaking change, so first with v5.0 in that case. Let me know if that ought to be tracked, and I'll create a separate issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions