refine automatic compiler selection

also overwrite the makeprg with just if justfile is found, otherwise use
make
This commit is contained in:
Ivar Fatland
2026-06-12 13:48:16 +02:00
parent da47abeb91
commit be3defb53f
+18 -5
View File
@@ -76,7 +76,6 @@ vim.cmd [=[
set cursorline
set noswapfile
set list
set makeprg=just
set tags+=~/tags
nnoremap ,co :copen<CR>
@@ -344,6 +343,8 @@ end
-- auto select compiler {{{1
do
-- TODO: vendor the compiler plugins so I can use e.g. basedpyright instead of pyright and add matching for failing tests in c using criterion.
-- did a similar thing for the vim config.
local compiler_mapping = {
dotnet={'*.csproj', '*.sln'},
pyright={'requirements.txt', 'pyproject.toml'},
@@ -353,6 +354,9 @@ do
cargo={'Cargo.toml'},
}
---@param pattern string
---@return boolean
local function look_for_file(pattern)
---@type string[]
local folders = {vim.fn.getcwd()}
for dir in vim.fs.parents(vim.fn.getcwd()) do
@@ -360,17 +364,26 @@ do
end
for _, dir in ipairs(folders) do
for compiler, patterns in pairs(compiler_mapping) do
for _, pattern in ipairs(patterns) do
local result = vim.fn.globpath(dir, pattern, false, false, false)
if result ~= '' then
return true
end
end
return false
end
for compiler, patterns in pairs(compiler_mapping) do
for _, pattern in ipairs(patterns) do
if look_for_file(pattern) then
vim.cmd('compiler! '..compiler)
goto exit
end
end
end
if look_for_file('justfile') then
vim.go.makeprg = 'just'
else
vim.go.makeprg = 'make'
end
::exit::
end