@@ -42,13 +42,19 @@ M.n["gd"] = {
4242 cond = " textDocument/definition" ,
4343}
4444
45- -- TODO: Add proper conditions
46- M . n [ " <leader>lf " ] = { function () vim .lsp .buf .format (M .format_opts ) end , desc = " Format buffer" }
45+ M . n [ " <leader>lf " ] =
46+ { function () vim .lsp .buf .format (M .format_opts ) end , desc = " Format buffer" , cond = " textDocument/formatting " }
4747M .v [" <leader>lf" ] = M .n [" <leader>lf" ]
48- M .n [" <leader>uf" ] =
49- { function () require (" astronvim.utils.ui" ).toggle_buffer_autoformat () end , desc = " Toggle autoformatting (buffer)" }
50- M .n [" <leader>uF" ] =
51- { function () require (" astronvim.utils.ui" ).toggle_autoformat () end , desc = " Toggle autoformatting (global)" }
48+ M .n [" <leader>uf" ] = {
49+ function () require (" astrolsp.utils" ).toggle_buffer_autoformat () end ,
50+ desc = " Toggle autoformatting (buffer)" ,
51+ cond = " textDocument/formatting" ,
52+ }
53+ M .n [" <leader>uF" ] = {
54+ function () require (" astrolsp.utils" ).toggle_autoformat () end ,
55+ desc = " Toggle autoformatting (global)" ,
56+ cond = " textDocument/formatting" ,
57+ }
5258
5359M .n [" K" ] = { function () vim .lsp .buf .hover () end , desc = " Hover symbol details" , cond = " textDocument/hover" }
5460
@@ -58,7 +64,6 @@ M.n["gI"] = {
5864 cond = " textDocument/implementation" ,
5965}
6066
61- -- TODO: add proper conditions
6267M .n [" <leader>uH" ] = {
6368 function ()
6469 vim .b .inlay_hints_enabled = not vim .b .inlay_hints_enabled
@@ -69,6 +74,7 @@ M.n["<leader>uH"] = {
6974 end
7075 end ,
7176 desc = " Toggle LSP inlay hints (buffer)" ,
77+ cond = vim .lsp .inlay_hint and " textDocument/inlayHint" or false ,
7278}
7379
7480M .n [" gr" ] =
@@ -94,7 +100,7 @@ M.n["<leader>lG"] =
94100M .n [" <leader>uY" ] = {
95101 function ()
96102 vim .b .semantic_tokens_enabled = not vim .b .semantic_tokens_enabled
97- for _ , client in ipairs (vim .lsp .get_active_clients ()) do
103+ for _ , client in ipairs (( vim .lsp .get_clients or vim . lsp . get_active_clients ) ()) do
98104 if client .server_capabilities .semanticTokensProvider then
99105 vim .lsp .semantic_tokens [vim .b .semantic_tokens_enabled and " start" or " stop" ](0 , client .id )
100106 vim .notify ((" Buffer lsp semantic highlighting %s" ):format (vim .b .semantic_tokens_enabled and " on" or " off" ))
@@ -105,40 +111,27 @@ M.n["<leader>uY"] = {
105111 cond = " textDocument/semanticTokens/full" ,
106112}
107113
108- if not vim .tbl_isempty (M .v ) then M .v [" <leader>l" ] = { desc = " LSP" } end
114+ -- TODO: FIX this
115+ -- if not vim.tbl_isempty(M.v) then M.v["<leader>l"] = { desc = " LSP" } end
109116
110- -- if is_available "telescope.nvim" then
111- -- lsp_mappings.n["<leader>lD"] =
112- -- { function() require("telescope.builtin").diagnostics() end, desc = "Search diagnostics" }
113- -- end
114- --
115- -- if is_available "mason-lspconfig.nvim" then
116- -- lsp_mappings.n["<leader>li"] = { "<cmd>LspInfo<cr>", desc = "LSP information" }
117- -- end
117+ if vim .fn .exists " :LspInfo" > 0 then M .n [" <leader>li" ] = { " <cmd>LspInfo<cr>" , desc = " LSP information" } end
118118--
119- -- if is_available "null-ls.nvim" then
120- -- lsp_mappings.n["<leader>lI"] = { "<cmd>NullLsInfo<cr>", desc = "Null-ls information" }
121- -- end
122-
123- -- if is_available "telescope.nvim" then -- setup telescope mappings if available
124- -- if lsp_mappings.n.gd then lsp_mappings.n.gd[1] = function() require("telescope.builtin").lsp_definitions() end end
125- -- if lsp_mappings.n.gI then
126- -- lsp_mappings.n.gI[1] = function() require("telescope.builtin").lsp_implementations() end
127- -- end
128- -- if lsp_mappings.n.gr then lsp_mappings.n.gr[1] = function() require("telescope.builtin").lsp_references() end end
129- -- if lsp_mappings.n["<leader>lR"] then
130- -- lsp_mappings.n["<leader>lR"][1] = function() require("telescope.builtin").lsp_references() end
131- -- end
132- -- if lsp_mappings.n.gT then
133- -- lsp_mappings.n.gT[1] = function() require("telescope.builtin").lsp_type_definitions() end
134- -- end
135- -- if lsp_mappings.n["<leader>lG"] then
136- -- lsp_mappings.n["<leader>lG"][1] = function()
137- -- vim.ui.input({ prompt = "Symbol Query: " }, function(query)
138- -- if query then require("telescope.builtin").lsp_workspace_symbols { query = query } end
139- -- end)
140- -- end
141- -- end
142- -- end
119+ if vim .fn .exists " :NullLsInfo" > 0 then M .n [" <leader>lI" ] = { " <cmd>NullLsInfo<cr>" , desc = " Null-ls information" } end
120+
121+ if vim .fn .exists " :Telescope" > 0 or pcall (require , " telescope" ) then -- setup telescope mappings if available
122+ M .n [" <leader>lD" ] = { function () require (" telescope.builtin" ).diagnostics () end , desc = " Search diagnostics" }
123+ if M .n .gd then M .n .gd [1 ] = function () require (" telescope.builtin" ).lsp_definitions () end end
124+ if M .n .gI then M .n .gI [1 ] = function () require (" telescope.builtin" ).lsp_implementations () end end
125+ if M .n .gr then M .n .gr [1 ] = function () require (" telescope.builtin" ).lsp_references () end end
126+ if M .n [" <leader>lR" ] then M .n [" <leader>lR" ][1 ] = function () require (" telescope.builtin" ).lsp_references () end end
127+ if M .n .gT then M .n .gT [1 ] = function () require (" telescope.builtin" ).lsp_type_definitions () end end
128+ if M .n [" <leader>lG" ] then
129+ M .n [" <leader>lG" ][1 ] = function ()
130+ vim .ui .input ({ prompt = " Symbol Query: " }, function (query )
131+ if query then require (" telescope.builtin" ).lsp_workspace_symbols { query = query } end
132+ end )
133+ end
134+ end
135+ end
143136
144137return M
0 commit comments