nvim: lsp: Do not attach LSP if file is opened via git

We might use Gedit to view older git revision of the file to which we do
not want to attach LSP.
This commit is contained in:
Sanchayan Maity 2024-07-29 19:39:28 +05:30
parent ccd2f77454
commit 1eec783a20
Signed by: sanchayanmaity
GPG key ID: 6F6A0609C12038F3

View file

@ -252,9 +252,14 @@ end
vim.api.nvim_create_autocmd("LspAttach", { vim.api.nvim_create_autocmd("LspAttach", {
group = lsp_augroup_id, group = lsp_augroup_id,
callback = function(args) callback = function(args)
local bufnr = args.buf local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id) local client = vim.lsp.get_client_by_id(args.data.client_id)
local opts = { noremap=true, silent=true } local file_name = vim.api.nvim_buf_get_name(bufnr)
local opts = { noremap=true, silent=true }
if string.find(file_name, ".git/") then
return
end
for _, mappings in pairs(lsp_key_mappings) do for _, mappings in pairs(lsp_key_mappings) do
local capability, mode, lhs, rhs = unpack(mappings) local capability, mode, lhs, rhs = unpack(mappings)
@ -270,8 +275,13 @@ vim.api.nvim_create_autocmd("LspAttach", {
vim.api.nvim_create_autocmd("LspDetach", { vim.api.nvim_create_autocmd("LspDetach", {
group = lsp_augroup_id, group = lsp_augroup_id,
callback = function(args) callback = function(args)
local bufnr = args.buf local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id) local client = vim.lsp.get_client_by_id(args.data.client_id)
local file_name = vim.api.nvim_buf_get_name(bufnr)
if string.find(file_name, ".git/") then
return
end
for _, mappings in pairs(lsp_key_mappings) do for _, mappings in pairs(lsp_key_mappings) do
local capability, mode, lhs, _ = unpack(mappings) local capability, mode, lhs, _ = unpack(mappings)