refine automatic compiler selection
also overwrite the makeprg with just if justfile is found, otherwise use make
This commit is contained in:
@@ -76,7 +76,6 @@ vim.cmd [=[
|
|||||||
set cursorline
|
set cursorline
|
||||||
set noswapfile
|
set noswapfile
|
||||||
set list
|
set list
|
||||||
set makeprg=just
|
|
||||||
set tags+=~/tags
|
set tags+=~/tags
|
||||||
|
|
||||||
nnoremap ,co :copen<CR>
|
nnoremap ,co :copen<CR>
|
||||||
@@ -344,6 +343,8 @@ end
|
|||||||
|
|
||||||
-- auto select compiler {{{1
|
-- auto select compiler {{{1
|
||||||
do
|
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 = {
|
local compiler_mapping = {
|
||||||
dotnet={'*.csproj', '*.sln'},
|
dotnet={'*.csproj', '*.sln'},
|
||||||
pyright={'requirements.txt', 'pyproject.toml'},
|
pyright={'requirements.txt', 'pyproject.toml'},
|
||||||
@@ -353,6 +354,9 @@ do
|
|||||||
cargo={'Cargo.toml'},
|
cargo={'Cargo.toml'},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@param pattern string
|
||||||
|
---@return boolean
|
||||||
|
local function look_for_file(pattern)
|
||||||
---@type string[]
|
---@type string[]
|
||||||
local folders = {vim.fn.getcwd()}
|
local folders = {vim.fn.getcwd()}
|
||||||
for dir in vim.fs.parents(vim.fn.getcwd()) do
|
for dir in vim.fs.parents(vim.fn.getcwd()) do
|
||||||
@@ -360,17 +364,26 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
for _, dir in ipairs(folders) do
|
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)
|
local result = vim.fn.globpath(dir, pattern, false, false, false)
|
||||||
if result ~= '' then
|
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)
|
vim.cmd('compiler! '..compiler)
|
||||||
goto exit
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if look_for_file('justfile') then
|
||||||
|
vim.go.makeprg = 'just'
|
||||||
|
else
|
||||||
|
vim.go.makeprg = 'make'
|
||||||
end
|
end
|
||||||
::exit::
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user