Skip to content

Commit af72687

Browse files
committed
feat: continue migrating more tooling
1 parent ca1a764 commit af72687

File tree

6 files changed

+193
-150
lines changed

6 files changed

+193
-150
lines changed

.luacheckrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Global objects
2-
globals = { "vim" }
2+
globals = { "vim", "astronvim" }
33

44
-- Rerun tests only if their modification time changed
55
cache = true

.neoconf.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
},
1515
"lspconfig": {
1616
"lua_ls": {
17-
"Lua.format.enable": false
17+
"Lua.format.enable": false,
18+
"Lua.diagnostics.globals": [
19+
"astronvim"
20+
]
1821
}
1922
}
2023
}

lua/astrolsp/config/init.lua

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local schemastore_avail, schemastore = pcall(require, "schemastore")
2+
13
return {
24
diagnostics = {
35
virtual_text = true,
@@ -48,15 +50,38 @@ return {
4850

4951
flags = {},
5052

51-
config = {},
53+
config = {
54+
jsonls = {
55+
settings = {
56+
json = {
57+
schemas = schemastore_avail and schemastore.json.schemas() or nil,
58+
validate = { enable = schemastore_avail },
59+
},
60+
},
61+
},
62+
yamlls = { settings = { yaml = { schemas = schemastore_avail and schemastore.json.schemas() or nil } } },
63+
lua_ls = {
64+
before_init = function(param, config)
65+
if vim.b.neodev_enabled and type(astronvim) == "table" and type(astronvim.supported_configs) == "table" then
66+
for _, astronvim_config in ipairs(astronvim.supported_configs) do
67+
if param.rootPath:match(astronvim_config) then
68+
table.insert(config.settings.Lua.workspace.library, astronvim.install.home .. "/lua")
69+
break
70+
end
71+
end
72+
end
73+
end,
74+
settings = { Lua = { workspace = { checkThirdParty = false } } },
75+
},
76+
},
77+
78+
servers = {},
5279

5380
-- on_attach = function(client, bufnr) ... end, -- user can pass in an extension of the on_attach
5481

55-
setup_handlers = {
56-
function(server, opts) require("lspconfig")[server].setup(opts) end,
57-
},
82+
setup_handlers = { function(server, opts) require("lspconfig")[server].setup(opts) end },
5883

59-
formatting = { format_on_save = { enabled = true }, disable = {} },
84+
formatting = { format_on_save = { enabled = true }, disabled = {} },
6085

6186
mappings = require "astrolsp.config.mappings",
6287
}

lua/astrolsp/config/mappings.lua

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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" }
4747
M.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

5359
M.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
6267
M.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

7480
M.n["gr"] =
@@ -94,7 +100,7 @@ M.n["<leader>lG"] =
94100
M.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

144137
return M

0 commit comments

Comments
 (0)