Adds configuration and packages for lsp

This commit is contained in:
Dennis Schoepf 2025-04-10 00:13:52 +02:00
parent e80172efaf
commit 89eab258b0
9 changed files with 224 additions and 4 deletions

View file

@ -21,6 +21,7 @@
"plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" },
"render-markdown.nvim": { "branch": "main", "commit": "05e6a6d119f90b99829ecb7eb85428a226c0c05f" },
"rose-pine": { "branch": "main", "commit": "96ff3993a67356ee85d1cdab9be652cdc1c5d1ac" },
"schemastore.nvim": { "branch": "main", "commit": "9961c820c0fb66288056093e8fb8056570a1eb9a" },
"snacks.nvim": { "branch": "main", "commit": "bc0630e43be5699bb94dadc302c0d21615421d93" },
"todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" },
"todo.txt-vim": { "branch": "master", "commit": "3bb5f9cf0d6c7ee91b476a97054c336104d2b6f5" },

View file

@ -0,0 +1,160 @@
local lsp = vim.lsp
local function validate_bufnr(bufnr)
if nvim_eleven then
validate('bufnr', bufnr, 'number')
end
return bufnr == 0 and api.nvim_get_current_buf() or bufnr
end
local function fix_all(opts)
opts = opts or {}
local eslint_lsp_client = vim.lsp.get_clients({ bufnr = opts.bufnr, name = 'eslint' })[1]
if eslint_lsp_client == nil then
return
end
local request
if opts.sync then
request = function(bufnr, method, params)
eslint_lsp_client.request_sync(method, params, nil, bufnr)
end
else
request = function(bufnr, method, params)
eslint_lsp_client.request(method, params, nil, bufnr)
end
end
local bufnr = util.validate_bufnr(opts.bufnr or 0)
request(0, 'workspace/executeCommand', {
command = 'eslint.applyAllFixes',
arguments = {
{
uri = vim.uri_from_bufnr(bufnr),
version = lsp.util.buf_versions[bufnr],
},
},
})
end
return {
cmd = { 'vscode-eslint-language-server', '--stdio' },
filetypes = {
'javascript',
'javascriptreact',
'javascript.jsx',
'typescript',
'typescriptreact',
'typescript.tsx',
'vue',
'svelte',
'astro',
},
root_markers = {
'.eslintrc',
'.eslintrc.js',
'.eslintrc.cjs',
'.eslintrc.yaml',
'.eslintrc.yml',
'.eslintrc.json',
'eslint.config.js',
'eslint.config.mjs',
'eslint.config.cjs',
'eslint.config.ts',
'eslint.config.mts',
'eslint.config.cts',
},
commands = {
EslintFixAll = {
function()
fix_all { sync = true, bufnr = 0 }
end,
description = 'Fix all eslint problems for this buffer',
},
},
settings = {
validate = 'on',
packageManager = nil,
useESLintClass = false,
experimental = {
useFlatConfig = false,
},
codeActionOnSave = {
enable = true,
mode = 'all',
},
format = true,
quiet = false,
onIgnoredFiles = 'off',
rulesCustomizations = {},
run = 'onType',
problems = {
shortenToSingleLine = false,
},
-- nodePath configures the directory in which the eslint server should start its node_modules resolution.
-- This path is relative to the workspace folder (root dir) of the server instance.
nodePath = '',
-- use the workspace folder location or the file location (if no workspace folder is open) as the working directory
workingDirectory = { mode = 'location' },
codeAction = {
disableRuleComment = {
enable = true,
location = 'separateLine',
},
showDocumentation = {
enable = true,
},
},
},
on_new_config = function(config, new_root_dir)
-- The "workspaceFolder" is a VSCode concept. It limits how far the
-- server will traverse the file system when locating the ESLint config
-- file (e.g., .eslintrc).
config.settings.workspaceFolder = {
uri = new_root_dir,
name = vim.fn.fnamemodify(new_root_dir, ':t'),
}
-- Support flat config
if
vim.fn.filereadable(new_root_dir .. '/eslint.config.js') == 1
or vim.fn.filereadable(new_root_dir .. '/eslint.config.mjs') == 1
or vim.fn.filereadable(new_root_dir .. '/eslint.config.cjs') == 1
or vim.fn.filereadable(new_root_dir .. '/eslint.config.ts') == 1
or vim.fn.filereadable(new_root_dir .. '/eslint.config.mts') == 1
or vim.fn.filereadable(new_root_dir .. '/eslint.config.cts') == 1
then
config.settings.experimental.useFlatConfig = true
end
-- Support Yarn2 (PnP) projects
local pnp_cjs = new_root_dir .. '/.pnp.cjs'
local pnp_js = new_root_dir .. '/.pnp.js'
if vim.loop.fs_stat(pnp_cjs) or vim.loop.fs_stat(pnp_js) then
config.cmd = vim.list_extend({ 'yarn', 'exec' }, config.cmd)
end
end,
handlers = {
['eslint/openDoc'] = function(_, result)
if result then
vim.ui.open(result.url)
end
return {}
end,
['eslint/confirmESLintExecution'] = function(_, result)
if not result then
return
end
return 4 -- approved
end,
['eslint/probeFailed'] = function()
vim.notify('[lspconfig] ESLint probe failed.', vim.log.levels.WARN)
return {}
end,
['eslint/noLibrary'] = function()
vim.notify('[lspconfig] Unable to find ESLint library.', vim.log.levels.WARN)
return {}
end,
},
}

View file

@ -0,0 +1,17 @@
return {
cmd = { 'vscode-json-language-server', '--stdio' },
filetypes = { 'json', 'jsonc' },
init_options = {
provideFormatter = true,
},
root_dir = function(fname)
return vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1])
end,
single_file_support = true,
settings = {
json = {
schemas = require("schemastore").json.schemas(),
validate = { enable = true }
}
}
}

View file

@ -0,0 +1,16 @@
return {
cmd = { 'lua-language-server' },
filetypes = { 'lua' },
root_markers = {
'.luarc.json',
'.luarc.jsonc',
'.luacheckrc',
'.stylua.toml',
'stylua.toml',
'selene.toml',
'selene.yml',
'.git',
},
single_file_support = true,
log_level = vim.lsp.protocol.MessageType.Warning,
}

View file

@ -1 +1,4 @@
vim.lsp.enable("ts_ls")
vim.lsp.enable("lua_ls")
vim.lsp.enable("eslint")
vim.lsp.enable("jsonls")

View file

@ -5,13 +5,24 @@ return {
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
keymap = { preset = "super-tab" }, -- 'default' | 'super-tab' | 'enter'
keymap = { preset = "enter" }, -- 'default' | 'super-tab' | 'enter'
appearance = {
nerd_font_variant = "mono",
},
-- (Default) Only show the documentation popup when manually triggered
-- C-k: Toggle signature help (if signature.enabled = true)
completion = { documentation = { auto_show = false } },
completion = {
documentation = { auto_show = false },
list = {
selection = {
preselect = false,
auto_insert = true,
}
}
},
signature = {
enabled = true
},
sources = {
default = { "lsp", "path", "snippets", "buffer" },
per_filetype = { sql = { "dadbod" } },

View file

@ -0,0 +1,3 @@
return {
'b0o/schemastore.nvim'
}

View file

@ -37,10 +37,13 @@
neovim
just
tldr
aider-chat
fortune
neofetch
jrnl
stylua
typescript-language-server
vscode-langservers-extracted
lua-language-server
prettierd
];
# Homebrew

6
todo.txt Normal file
View file

@ -0,0 +1,6 @@
x Set up luals
x Set up eslint ls
x Set up jsonls
x Set up better (Enter vs. super-tab) keymaps for blink
Set up keymaps for LSP
Set up snacks picker instead of fzf