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

@ -254,8 +254,13 @@ vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
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
local capability, mode, lhs, rhs = unpack(mappings)
if client.supports_method(capability) then
@ -272,6 +277,11 @@ vim.api.nvim_create_autocmd("LspDetach", {
callback = function(args)
local bufnr = args.buf
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
local capability, mode, lhs, _ = unpack(mappings)