Created
February 26, 2025 14:12
-
-
Save PMassicotte/4db85e7c1ed0e769ab33aabe1b4465a1 to your computer and use it in GitHub Desktop.
configuring air lsp/formatter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- After installing air, configure it like this | |
local configs = require("lspconfig.configs") | |
configs.air = { | |
default_config = { | |
cmd = { vim.fn.expand("$HOME/.local/bin/air"), "language-server" }, | |
filetypes = { "r" }, | |
root_dir = function(fname) | |
local git_dir = vim.fs.find(".git", { path = fname, upward = true })[1] | |
return git_dir and vim.fs.dirname(git_dir) or vim.loop.os_homedir() | |
end, | |
settings = {}, | |
}, | |
} | |
-- Then, to format on save, you can use something like this in /after/lsp.lua | |
vim.api.nvim_create_autocmd("BufWritePre", { | |
pattern = { "*.R", "*.r" }, | |
callback = function() | |
vim.lsp.buf.format({ | |
async = true, | |
filter = function(client) | |
return client.name == "air" | |
end, | |
}) | |
end, | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment