Skip to content

Commit

Permalink
wip(ref lsp)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjeusel committed Mar 18, 2023
1 parent 7bb2144 commit de0b822
Show file tree
Hide file tree
Showing 26 changed files with 164 additions and 118 deletions.
55 changes: 48 additions & 7 deletions dotfiles/.config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,57 @@
-- - ThePrimeagen: https://github.com/awesome-streamers/awesome-streamerrc/tree/master/ThePrimeagen ( the funny )
-- - ChristianChiarulli: https://github.com/ChristianChiarulli/LunarVim ( the ambitious )

require("wax.userconfig") -- comes first, define user configs (waxopts)
require("wax.utils") -- utils with globals
require("wax.settings") -- vim.o

require("wax.plugins")
require("wax.userconfig") -- define user configs (waxopts)
require("wax.utils") -- utils with globals

require("wax.filetypes")
require("wax.keymaps")

require("wax.themes")

require("wax.autocmds")
require("wax.folds")

-- Install package manager - https://github.com/folke/lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({ import = "wax.plugins" }, {
custom_keys = false,
checker = { enabled = false }, -- background plugin update checker
change_detection = { enabled = true, notify = false },
performance = {
rtp = {
disabled_plugins = {
"tohtml",
"tutor",
"gzip",
"zip",
"zipPlugin",
"tar",
"tarPlugin",
"getscript",
"getscriptPlugin",
"vimball",
"vimballPlugin",
"2html_plugin",
"logipat",
"rrhelper",
"spellfile_plugin",
"fzf",
"matchit",
"matchparen",
},
},
},
})

safe_require("wax.folds")
76 changes: 0 additions & 76 deletions dotfiles/.config/nvim/lua/wax/lsp/dmypyls-ls.lua

This file was deleted.

99 changes: 84 additions & 15 deletions dotfiles/.config/nvim/lua/wax/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ lsp_status.config({
})

-- Mappings
local function lsp_keymaps()
local function set_lsp_keymaps()
local opts = { noremap = true, silent = true }

-- See `:help vim.lsp.*` for documentation on any of the below functions
Expand Down Expand Up @@ -82,27 +82,18 @@ local function lsp_keymaps()
end, opts)
end

set_lsp_keymaps()

--Enable completion triggered by <c-x><c-o>
vim.api.nvim_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")

-- Generate capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_extend("force", capabilities, lsp_status.capabilities)
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)

-- require("wax.lsp.setup").setup_servers({
-- on_attach = function(client, bufnr)
-- lsp_keymaps()

-- -- -- disable semanticTokens for now
-- -- vim.lsp.semantic_tokens.stop(bufnr, client.id)
-- -- -- client.server_capabilities.semanticTokensProvider = nil

-- lsp_status.on_attach(client, bufnr)
-- end,
-- capabilities = capabilities,
-- })
capabilities.textDocument.completion =
require("cmp_nvim_lsp").default_capabilities({}).textDocument.completion

-- Customization of the publishDiagnostics (remove all pyright diags)
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(function(_, result, ctx, config)
result.diagnostics = vim.tbl_filter(function(diagnostic)
-- Filter out all diagnostics from pyright
Expand All @@ -112,6 +103,10 @@ vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(function(_, r
vim.lsp.diagnostic.on_publish_diagnostics(_, result, ctx, config)
end, {})

-- Disable semanticTokens on lsp attach
--
-- should be done in on_attach setting it to nil, but buggy right now:
-- https://github.com/neovim/neovim/issues/21588
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
-- disable semanticTokens for now
Expand All @@ -121,3 +116,77 @@ vim.api.nvim_create_autocmd("LspAttach", {
client.server_capabilities.semanticTokensProvider = nil
end,
})

local function generate_handlers()
local default_on_attach = lsp_status.on_attach

local default_handler = function(server_name)
require("lspconfig")[server_name].setup({
capabilities = capabilities,
on_attach = default_on_attach,
})
end

local handlers = { default_handler }

local scan = require("plenary.scandir")

local server_with_custom_config = vim.tbl_map(function(server_file)
return vim.fn.fnamemodify(server_file, ":t:r")
end, scan.scan_dir(lua_waxdir .. "/lsp/servers", { depth = 1 }))

for _, server_name in ipairs(server_with_custom_config) do
handlers[server_name] = function()
local server_opts = require(("wax.lsp.servers.%s"):format(server_name))
local on_attach = default_on_attach
if server_opts.on_attach then
on_attach = function(client, bufnr)
default_on_attach(client)
server_opts.on_attach(client, bufnr)
end
end
require("lspconfig")[server_name].setup(
vim.tbl_deep_extend(
"keep",
{ capabilities = capabilities, on_attach = on_attach },
server_opts
)
)
end
end

return handlers
end

local handlers = generate_handlers()

-- -- make sure to configure lspconfig before actual setup_handlers of mason-lspconfig
-- -- so we define our custom servers, and make the on_new_config works
-- vim.tbl_map(function(handler)
-- if type(handler) == "function" then
-- handler()
-- end
-- end,
-- handlers
-- )

-- Register homemade LSP servers (mypygls):
local lspconfig = require("lspconfig")
local configs = require("lspconfig.configs")

configs.mypygls = {
default_config = {
cmd = { "mypygls" },
filetypes = { "python" },
root_dir = function(fname)
return lspconfig.util.find_git_ancestor(fname)
end,
settings = {},
},
}

-- map it in mason-lspconfig
local server_mapping = require("mason-lspconfig.mappings.server")
server_mapping.lspconfig_to_package["mypygls"] = "mypygls"

require("mason-lspconfig").setup_handlers(handlers)
7 changes: 0 additions & 7 deletions dotfiles/.config/nvim/lua/wax/lsp/mypygls-ls.lua

This file was deleted.

2 changes: 1 addition & 1 deletion dotfiles/.config/nvim/lua/wax/lsp/python-utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ local function find_python_cmd(workspace, cmd)
end

M.get_python_path = function(workspace, cmd)
workspace = workspace or ""
workspace = workspace or find_workspace_name(vim.api.nvim_buf_get_name(0))
cmd = cmd or "python"
local python_path = nil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ return {
client.server_capabilities.colorProvider = false
client.server_capabilities.documentHighlightProvider = false

client.server_capabilities.documentFormatting = false
client.server_capabilities.documentFormattingProvider = false
end,
settings = {
Lua = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ return {
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
end,
-- cmd = to_pylsp_cmd(python_utils.get_python_path(nil, "python")),
settings = {
pylsp = {
-- https://github.com/python-lsp/python-lsp-server/blob/develop/CONFIGURATION.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ return {
settings = {
python = {
-- https://github.com/microsoft/pyright/blob/main/docs/settings.md
-- pythonPath = python_utils.get_python_path(),
disableOrganizeImports = true,
analysis = {
-- diagnosticMode = "workspace",
Expand Down
1 change: 1 addition & 0 deletions dotfiles/.config/nvim/lua/wax/lsp/servers/svelte.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return {}
7 changes: 0 additions & 7 deletions dotfiles/.config/nvim/lua/wax/lsp/typescript-ls.lua

This file was deleted.

2 changes: 1 addition & 1 deletion dotfiles/.config/nvim/lua/wax/plugcfg/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ kmap("n", "<leader>fw", function()
".zshrc",
"src/waxcraft/dotfiles",
"src/nvim-treesitter",
".local/share/nvim/site/pack/packer",
".local/share/nvim/lazy",
}
local home = vim.env.HOME
local abs_paths = vim.tbl_map(function(path)
Expand Down
2 changes: 1 addition & 1 deletion dotfiles/.config/nvim/lua/wax/plugcfg/luasnip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ls.config.set_config({
enable_autosnippets = false,
})

local snippets_path = vim.env.waxCraft_PATH .. "/dotfiles/.config/nvim/lua/wax/snippets"
local snippets_path = lua_waxdir .. "/snippets"

load_from_lua({ paths = snippets_path })

Expand Down
16 changes: 15 additions & 1 deletion dotfiles/.config/nvim/lua/wax/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ return {
require("wax.plugcfg.treesitter")
end,
},
{ -- hlslens
"kevinhwang91/nvim-hlslens",
event = "VeryLazy",
config = function()
require("wax.plugcfg.hlslens")
end,
},

--------- Deemed Necessary ---------
{ "nvim-lua/plenary.nvim", lazy = true },
Expand Down Expand Up @@ -274,6 +281,7 @@ return {
},
{ -- mason
"williamboman/mason.nvim",
config = true,
init = function()
vim.keymap.set({ "n" }, "<leader>fm", function()
require("mason.ui").open()
Expand All @@ -293,7 +301,13 @@ return {
},
},
},
{ "williamboman/mason-lspconfig.nvim", config = true },
{ -- mason-lspconfig.nvim
"williamboman/mason-lspconfig.nvim",
opts = {
ensure_installed = {},
automatic_installation = false,
},
},
{ "nvim-lua/lsp-status.nvim" },
{ "b0o/schemastore.nvim", ft = "json" }, -- json schemas for jsonls
},
Expand Down
2 changes: 1 addition & 1 deletion dotfiles/.config/nvim/lua/wax/scratch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function M.float_win(opts)
end)
end
local aucmd_autoclose =
vim.api.nvim_create_autocmd("WinLeave", { callback = close, buffer = bufnr })
vim.api.nvim_create_autocmd("WinLeave", { callback = close, buffer = bufnr })

local open_vertical_split = function()
vim.api.nvim_del_autocmd(aucmd_autoclose)
Expand Down
Loading

0 comments on commit de0b822

Please sign in to comment.