feat: convert to blink, major lsp changes, lualine

This commit is contained in:
Jason Miller 2025-06-12 12:27:51 +09:00
parent 82102e5e29
commit 51ab444c0d
44 changed files with 1387 additions and 700 deletions

12
lua/lsp/ast_grep.lua Normal file
View file

@ -0,0 +1,12 @@
return {
cmd = { 'ast-grep', 'lsp' },
filetypes = { 'java', 'javascript', 'html' },
root_dir = function(fname)
return require('lspconfig.util').find_git_ancestor(fname) or vim.fn.getcwd()
end,
settings = {
['ast-grep'] = {
enable = true,
},
},
}

6
lua/lsp/bashls.lua Normal file
View file

@ -0,0 +1,6 @@
return {
name = 'bashls',
cmd = { 'bash-language-server', 'start' },
root_dir = vim.fs.dirname(vim.fs.find({ '.git' }, { upward = true })[1]),
filetypes = { 'sh', 'bash' },
}

37
lua/lsp/clangd.lua Normal file
View file

@ -0,0 +1,37 @@
local tools = require 'utils.tools'
-- Get LSP capabilities with cmp support
local capabilities = tools.get_lsp_capabilities()
-- Setup clangd LSP using autocmd
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'c', 'cpp', 'h', 'hpp' },
callback = function()
local clangd_path = tools.find_executable 'clangd'
if clangd_path then
vim.lsp.start {
name = 'clangd',
cmd = {
clangd_path,
'--background-index',
'--clang-tidy',
'--header-insertion=iwyu',
'--completion-style=detailed',
'--function-arg-placeholders',
'--fallback-style=llvm',
},
root_dir = vim.fs.dirname(vim.fs.find({ 'compile_commands.json', 'compile_flags.txt', '.clangd', '.git' }, { upward = true })[1]),
capabilities = capabilities,
init_options = {
usePlaceholders = true,
completeUnimported = true,
clangdFileStatus = true,
},
}
end
end,
})
-- Return empty config since we handle clangd LSP manually via autocmd above
return {}

6
lua/lsp/dockerls.lua Normal file
View file

@ -0,0 +1,6 @@
return {
name = 'dockerls',
cmd = { 'docker-langserver', '--stdio' },
root_dir = vim.fs.dirname(vim.fs.find({ 'Dockerfile', 'dockerfile', '.dockerignore' }, { upward = true })[1]),
filetypes = { 'dockerfile', 'Dockerfile' },
}

45
lua/lsp/gopls.lua Normal file
View file

@ -0,0 +1,45 @@
local tools = require 'utils.tools'
-- Get LSP capabilities with cmp support
local capabilities = tools.get_lsp_capabilities()
-- Setup gopls LSP using autocmd
vim.api.nvim_create_autocmd('FileType', {
pattern = 'go',
callback = function()
local gopls_path = tools.find_executable 'gopls'
if gopls_path then
vim.lsp.start {
name = 'gopls',
cmd = { gopls_path },
root_dir = vim.fs.dirname(vim.fs.find({ 'go.mod', 'go.work', '.git' }, { upward = true })[1]),
capabilities = capabilities,
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
gofumpt = true,
completeUnimported = true,
usePlaceholders = true,
experimentalPostfixCompletions = true,
hints = {
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
constantValues = true,
functionTypeParameters = true,
parameterNames = true,
rangeVariableTypes = true,
},
},
},
}
end
end,
})
-- Return empty config since we handle gopls LSP manually via autocmd above
return {}

68
lua/lsp/keybindings.lua Normal file
View file

@ -0,0 +1,68 @@
-- LSP keybindings and autocmds
-- Extracted from legacy lsp.lua plugin configuration
-- LSP attach autocmd with keybindings
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
callback = function(event)
local map = function(keys, func, desc)
vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
end
-- Navigation keybindings
map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
-- LSP gr
map('grn', vim.lsp.buf.rename, '[R]e[n]ame') -- rename
map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' })
map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') -- func def
map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') -- header def
map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition')
map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols') -- open symbols
map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols') -- open ws
-- Document highlighting
local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then
local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.clear_references,
})
vim.api.nvim_create_autocmd('LspDetach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }),
callback = function(event2)
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf }
end,
})
end
-- Inlay hints toggle
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
map('<leader>th', function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
end, '[T]oggle Inlay [H]ints')
end
end,
})
vim.keymap.set('n', '<leader>td', function()
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
end, { silent = true, noremap = true, desc = '[d]iagnostics' })

32
lua/lsp/lua_ls.lua Normal file
View file

@ -0,0 +1,32 @@
-- Get LSP capabilities with cmp support
local capabilities = vim.lsp.protocol.make_client_capabilities()
local ok, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp')
if ok then
capabilities = vim.tbl_deep_extend('force', capabilities, cmp_nvim_lsp.default_capabilities())
end
-- Lua LSP configuration for vim.lsp.enable()
return {
name = 'lua_ls',
cmd = { 'lua-language-server' },
filetypes = { 'lua' },
root_dir = vim.fs.dirname(vim.fs.find({ '.luarc.json', '.luarc.jsonc', '.stylua.toml', 'stylua.toml', 'selene.toml' }, { upward = true })[1]),
capabilities = capabilities,
settings = {
Lua = {
completion = {
callSnippet = 'Replace',
},
diagnostics = {
globals = { 'vim' },
},
workspace = {
library = vim.api.nvim_get_runtime_file('', true),
checkThirdParty = false,
},
telemetry = {
enable = false,
},
},
},
}

6
lua/lsp/marksman.lua Normal file
View file

@ -0,0 +1,6 @@
return {
name = 'marksman',
cmd = { 'marksman', 'server' },
root_dir = vim.fs.dirname(vim.fs.find({ '.git', '.marksman.toml' }, { upward = true })[1]),
filetypes = { 'markdown', 'md' },
}

6
lua/lsp/nil_ls.lua Normal file
View file

@ -0,0 +1,6 @@
return {
name = 'nixd',
cmd = { 'nixd' },
root_dir = vim.fs.dirname(vim.fs.find({ 'flake.nix', 'default.nix', 'shell.nix' }, { upward = true })[1]),
filetypes = { 'nix' },
}

119
lua/lsp/python.lua Normal file
View file

@ -0,0 +1,119 @@
local tools = require 'utils.tools'
-- Get LSP capabilities with cmp support
local capabilities = tools.get_lsp_capabilities()
-- Setup multiple Python LSP servers using autocmd (not via vim.lsp.enable)
vim.api.nvim_create_autocmd('FileType', {
pattern = 'python',
callback = function()
-- Stop any unwanted Python LSPs that may have been auto-started
local unwanted_lsps = { 'pylsp', 'pyright', 'mypy' }
local clients = vim.lsp.get_clients { bufnr = 0 }
for _, client in ipairs(clients) do
for _, unwanted in ipairs(unwanted_lsps) do
if client.name == unwanted then
vim.lsp.stop_client(client.id, true)
vim.notify('Stopped unwanted LSP: ' .. client.name, vim.log.levels.INFO)
end
end
end
-- Common root directory lookup for all Python LSPs
local current_file = vim.api.nvim_buf_get_name(0)
local file_dir = vim.fs.dirname(current_file)
local root_dir = vim.fs.dirname(
vim.fs.find(
{ 'pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'Pipfile', 'pyrightconfig.json', 'ruff.toml', '.ruff.toml' },
{ path = file_dir, upward = true }
)[1]
)
local pyright_path = tools.find_tool 'basedpyright-langserver'
local ruff_path = tools.find_tool 'ruff'
local jedi_path = tools.find_tool 'jedi-language-server'
local python3_path = tools.find_tool 'python3'
-- Setup pyright (hover and type checking)
-- https://docs.basedpyright.com/dev/
if pyright_path then
local pyright_capabilities = vim.tbl_deep_extend('force', capabilities, {})
vim.lsp.start {
name = 'basedpyright',
cmd = { pyright_path, '--stdio' },
root_dir = root_dir,
capabilities = pyright_capabilities,
settings = {
basedpyright = {
analysis = {
autoImportCompletion = true,
autoSearchPaths = true,
diagnosticMode = 'openFilesOnly',
typeCheckingMode = 'off', -- 'basic',
useLibraryCodeForTypes = true,
inlayHints = {
callArgumentNames = true,
},
},
pythonPath = python3_path,
extraPaths = vim.list_extend(
vim.fn.isdirectory(root_dir .. '/python') == 1 and { root_dir .. '/python' } or {},
vim.split(vim.env.PYTHONPATH or '', ':')
),
},
},
handlers = {
['textDocument/publishDiagnostics'] = function() end,
},
}
end
-- Setup ruff (linting and formatting)
if ruff_path then
local ruff_capabilities = vim.tbl_deep_extend('force', capabilities, {})
ruff_capabilities.textDocument.completion = nil
ruff_capabilities.hoverProvider = false
vim.lsp.start {
name = 'ruff',
cmd = { ruff_path, 'server' },
root_dir = root_dir,
capabilities = ruff_capabilities,
handlers = {
['textDocument/hover'] = function() end,
['textDocument/completion'] = function() end,
},
}
end
-- Setup jedi language server (completions)
if jedi_path then
local jedi_capabilities = vim.tbl_deep_extend('force', capabilities, {})
jedi_capabilities.hoverProvider = false
vim.lsp.start {
name = 'jedi_language_server',
cmd = { jedi_path },
root_dir = root_dir,
capabilities = jedi_capabilities,
init_options = {
diagnostics = {
enable = false,
didOpen = false,
didChange = false,
didSave = false,
},
},
handlers = {
['textDocument/publishDiagnostics'] = function() end,
['textDocument/hover'] = function() end,
},
}
end
end,
})
-- Return empty config since we handle Python LSP manually via autocmd above
return {}

6
lua/lsp/taplo.lua Normal file
View file

@ -0,0 +1,6 @@
return {
name = 'taplo',
cmd = { 'taplo', 'lsp', 'stdio' },
root_dir = vim.fs.dirname(vim.fs.find({ '.git', '*.toml' }, { upward = true })[1]),
filetypes = { 'toml' },
}

38
lua/lsp/ts_ls.lua Normal file
View file

@ -0,0 +1,38 @@
-- Get LSP capabilities with cmp support
local capabilities = vim.lsp.protocol.make_client_capabilities()
local ok, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp')
if ok then
capabilities = vim.tbl_deep_extend('force', capabilities, cmp_nvim_lsp.default_capabilities())
end
return {
name = 'ts_ls',
cmd = { 'typescript-language-server', '--stdio' },
root_dir = vim.fs.dirname(vim.fs.find({ 'package.json', 'tsconfig.json', 'jsconfig.json', '.git' }, { upward = true })[1]),
filetypes = { 'ts' },
capabilities = capabilities,
settings = {
typescript = {
inlayHints = {
includeInlayParameterNameHints = 'all',
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
},
},
javascript = {
inlayHints = {
includeInlayParameterNameHints = 'all',
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
},
},
},
}

27
lua/lsp/yamlls.lua Normal file
View file

@ -0,0 +1,27 @@
-- Get LSP capabilities with cmp support
local capabilities = vim.lsp.protocol.make_client_capabilities()
local ok, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp')
if ok then
capabilities = vim.tbl_deep_extend('force', capabilities, cmp_nvim_lsp.default_capabilities())
end
return {
name = 'yamlls',
cmd = { 'yaml-language-server', '--stdio' },
filetypes = { 'yaml', 'yml' },
root_dir = vim.fs.dirname(vim.fs.find({ '.git', 'docker-compose.yml', 'docker-compose.yaml' }, { upward = true })[1]),
capabilities = capabilities,
settings = {
telemetry = {
enabled = false,
},
yaml = {
schemas = {
['https://json.schemastore.org/github-workflow.json'] = '/.github/workflows/*',
['https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json'] = '/docker-compose*.{yml,yaml}',
['https://json.schemastore.org/kustomization.json'] = 'kustomization.{yml,yaml}',
['https://json.schemastore.org/chart.json'] = '/Chart.{yml,yaml}',
},
},
},
}