Small improvementes in lsp config; trying to add lsp with biome for tsx files

This commit is contained in:
Jose Carvajal 2026-03-18 09:21:19 -06:00
parent 7f7aeb562b
commit f84ddbaf8e
3 changed files with 44 additions and 56 deletions

View File

@ -38,6 +38,7 @@ return {
typescript = { 'biome' }, typescript = { 'biome' },
javascript = { 'biome' }, javascript = { 'biome' },
typescriptreact = { 'biome' }, typescriptreact = { 'biome' },
javascriptreact = { 'biome' },
}, },
}, },
}, },

View File

@ -7,7 +7,6 @@ return {
local lint = require 'lint' local lint = require 'lint'
lint.linters_by_ft = { lint.linters_by_ft = {
go = { 'golangcilint' }, go = { 'golangcilint' },
markdown = { 'markdownlint' },
typescript = { 'biomejs' }, typescript = { 'biomejs' },
typescriptreact = { 'biomejs' }, typescriptreact = { 'biomejs' },
} }

View File

@ -118,26 +118,11 @@ return {
-- map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition') -- map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition')
map('grt', require('fzf-lua').lsp_typedefs, '[G]oto [T]ype Definition') map('grt', require('fzf-lua').lsp_typedefs, '[G]oto [T]ype Definition')
-- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10)
---@param client vim.lsp.Client
---@param method vim.lsp.protocol.Method
---@param bufnr? integer some lsp support methods only in specific files
---@return boolean
local function client_supports_method(client, method, bufnr)
if vim.fn.has 'nvim-0.11' == 1 then
return client:supports_method(method, bufnr)
else
return client.supports_method(method, { bufnr = bufnr })
end
end
-- The following two autocommands are used to highlight references of the -- The following two autocommands are used to highlight references of the
-- word under your cursor when your cursor rests there for a little while. -- word under your cursor when your cursor rests there for a little while.
-- See `:help CursorHold` for information about when this is executed -- See `:help CursorHold` for information about when this is executed
--
-- When you move your cursor, the highlights will be cleared (the second autocommand).
local client = vim.lsp.get_client_by_id(event.data.client_id) local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then if client and client:supports_method('textDocument/documentHighlight', event.buf) then
local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
buffer = event.buf, buffer = event.buf,
@ -145,6 +130,7 @@ return {
callback = vim.lsp.buf.document_highlight, callback = vim.lsp.buf.document_highlight,
}) })
-- When you move your cursor, the highlights will be cleared
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf, buffer = event.buf,
group = highlight_augroup, group = highlight_augroup,
@ -164,7 +150,7 @@ return {
-- code, if the language server you are using supports them -- code, if the language server you are using supports them
-- --
-- This may be unwanted, since they displace some of your code -- This may be unwanted, since they displace some of your code
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then if client and client:supports_method('textDocument/inlayHint', event.buf) then
map('<leader>th', function() map('<leader>th', function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
end, '[T]oggle Inlay [H]ints') end, '[T]oggle Inlay [H]ints')
@ -205,11 +191,8 @@ return {
-- By default, Neovim doesn't support everything that is in the LSP specification. -- By default, Neovim doesn't support everything that is in the LSP specification.
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers. -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
local capabilities = require('blink.cmp').get_lsp_capabilities() -- local capabilities = require('blink.cmp').get_lsp_capabilities()
-- Enable the following language servers
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
--
-- Add any additional override configuration in the following tables. Available keys are: -- Add any additional override configuration in the following tables. Available keys are:
-- - cmd (table): Override the default command used to start the server -- - cmd (table): Override the default command used to start the server
-- - filetypes (table): Override the default list of associated filetypes for the server -- - filetypes (table): Override the default list of associated filetypes for the server
@ -222,18 +205,35 @@ return {
pyright = {}, pyright = {},
rust_analyzer = {}, rust_analyzer = {},
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
-- stylua = {},
-- Some languages (like typescript) have entire language plugins that can be useful:
-- https://github.com/pmizio/typescript-tools.nvim
--
-- But for many setups, the LSP (`ts_ls`) will work just fine
-- ts_ls = {},
--
lua_ls = { lua_ls = {
-- cmd = { ... }, -- cmd = { ... },
-- filetypes = { ... }, -- filetypes = { ... },
-- capabilities = {}, -- capabilities = {},
on_init = function(client)
if client.workspace_folders then
local path = client.workspace_folders[1].name
if path ~= vim.fn.stdpath 'config' and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc')) then
return
end
end
-- client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
-- runtime = {
-- version = 'LuaJIT',
-- path = { 'lua/?.lua', 'lua/?/init.lua' },
-- },
-- workspace = {
-- checkThirdParty = false,
-- -- NOTE: this is a lot slower and will cause issues when working on your own configuration.
-- -- See https://github.com/neovim/nvim-lspconfig/issues/3189
-- library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), {
-- '${3rd}/luv/library',
-- '${3rd}/busted/library',
-- }),
-- },
-- })
end,
settings = { settings = {
Lua = { Lua = {
completion = { completion = {
@ -241,45 +241,33 @@ return {
}, },
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
-- diagnostics = { disable = { 'missing-fields' } }, -- diagnostics = { disable = { 'missing-fields' } },
diagnostics = {
globals = { 'vim' },
},
}, },
}, },
}, },
biome = {}, ts_ls = {},
-- TODO: make biome work as lsp fot ts, js, tsx, jsx files instead of ts_ls
biome = {
-- cmd = { 'biome', 'lsp-proxy' },
-- root_dir = require('lspconfig').util.root_pattern('package.json', '.git'),
},
} }
-- Ensure the servers and tools above are installed -- Ensure the servers and tools above are installed
--
-- To check the current status of installed tools and/or manually install -- To check the current status of installed tools and/or manually install
-- other tools, you can run -- other tools, you can run
-- :Mason -- :Mason
--
-- You can press `g?` for help in this menu.
--
-- `mason` had to be setup earlier: to configure its options see the
-- `dependencies` table for `nvim-lspconfig` above.
--
-- You can add other tools here that you want Mason to install
-- for you, so that they are available from within Neovim.
local ensure_installed = vim.tbl_keys(servers or {}) local ensure_installed = vim.tbl_keys(servers or {})
vim.list_extend(ensure_installed, { vim.list_extend(ensure_installed, {
'stylua', -- Used to format Lua code -- add any other tools we want from mason
}) })
require('mason-tool-installer').setup { ensure_installed = ensure_installed } require('mason-tool-installer').setup { ensure_installed = ensure_installed }
for name, server in pairs(servers) do
require('mason-lspconfig').setup { vim.lsp.config(name, server)
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) vim.lsp.enable(name)
automatic_installation = false, end
handlers = {
function(server_name)
local server = servers[server_name] or {}
-- This handles overriding only values explicitly passed
-- by the server configuration above. Useful when disabling
-- certain features of an LSP (for example, turning off formatting for ts_ls)
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
require('lspconfig')[server_name].setup(server)
end,
},
}
-- In case you want to install an lsp directly on your system, you;ll need to configure it and enable it manually -- In case you want to install an lsp directly on your system, you;ll need to configure it and enable it manually
-- local system_installed_servers = { -- local system_installed_servers = {