From ac18ae5d5717f7dad09ed396d2abbf9c30ee4e94 Mon Sep 17 00:00:00 2001 From: ray-x Date: Tue, 28 Feb 2023 17:06:21 +1100 Subject: [PATCH] ftdetect for attach --- lua/navigator/diagnostics.lua | 4 +-- lua/navigator/lspclient/clients.lua | 46 +++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/lua/navigator/diagnostics.lua b/lua/navigator/diagnostics.lua index 80cfa6a..91cd1bc 100644 --- a/lua/navigator/diagnostics.lua +++ b/lua/navigator/diagnostics.lua @@ -59,8 +59,8 @@ local function error_marker(result, ctx, config) -- local rootfolder = vim.fn.expand('%:h:t') -- get the current file root folder local bufnr = ctx.bufnr - if bufnr == nil then - bufnr = vim.uri_to_bufnr(result.uri) + if bufnr == nil and result.uri then + bufnr = vim.uri_to_bufnr(result.uri) or vim.api.nvim_get_current_buf() end local success, fname = pcall(api.nvim_buf_get_name, bufnr) if not success then diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index e69075d..1f9feac 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -499,33 +499,61 @@ local function ft_disabled(ft) end end end +local ft_map = { + js = 'javascript', + ts = 'typescript', + jsx = 'javascriptreact', + tsx = 'typescriptreact', + mod = 'gomod', + cxx = 'cpp', + chh = 'cpp', + hs = 'haskell', + pl = 'perl', + rs = 'rust', + rb = 'ruby', + py = 'python', +} local function setup(user_opts, cnt) user_opts = user_opts or {} local ft = vim.bo.filetype local bufnr = user_opts.bufnr or vim.api.nvim_get_current_buf() + cnt = cnt or 0 if ft == '' or ft == nil then - log('nil filetype, callback') + log('nil filetype, callback',vim.fn.expand('%'), cnt) local ext = vfn.expand('%:e') + if ext ~= '' and cnt >= 2 then + local ft = ft_map[ext] or ft or ext or 'txt' + log('set ft', ft) + vim.cmd('setlocal ft=' .. ft) + vim.cmd('setlocal syntax=on') + -- goto break + goto continue + end + local opt + if cnt > 0 then + opt = user_opts + else + opts = vim.deepcopy(user_opts) + end if ext ~= '' then - cnt = cnt or 0 - local opts = vim.deepcopy(user_opts) if cnt > 3 then log('failed to load filetype, skip') return - else - cnt = cnt + 1 end - vim.defer_fn(function() - log('defer_fn', ext, ft) - setup(opts, cnt) - end, 200) + if cnt < 4 then + vim.defer_fn(function() + log('defer_fn', ext, ft) + setup(opts, cnt + 1) + end, 200) return + end else log('no filetype, no ext return') return end end + ::continue:: local uri = vim.uri_from_bufnr(bufnr) if uri == 'file://' or uri == 'file:///' then