Skip to content

Commit ac6fa29

Browse files
committed
refactor(LSP): vim.lsp.config
1 parent e9342be commit ac6fa29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+868
-834
lines changed

lsp/README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# LSP Configuration Directory
2+
3+
This directory contains server-specific configurations for the Neovim 0.10+ core LSP system.
4+
5+
## Architecture
6+
7+
The LSP configuration uses the new Neovim 0.10+ core LSP approach:
8+
9+
- **Global Configuration**: Set via `vim.lsp.config('*', {...})` in the main init.lua
10+
- **Server Activation**: Done via `vim.lsp.enable(servers)` instead of individual setup calls
11+
- **Server-Specific Config**: Individual files in this directory that return configuration tables
12+
13+
## File Structure
14+
15+
```
16+
lsp/
17+
├── README.md # This documentation
18+
├── _utils.lua # Shared utilities to reduce redundancy
19+
├── lua_ls.lua # Lua language server config
20+
├── gopls.lua # Go language server config
21+
├── tsserver.lua # TypeScript/JavaScript server config
22+
├── pyright.lua # Python language server config
23+
├── jsonls.lua # JSON language server config
24+
├── yamlls.lua # YAML language server config
25+
└── [other servers].lua # Additional server configurations
26+
```
27+
28+
## Configuration Format
29+
30+
Each server configuration file should return a table with server-specific settings:
31+
32+
```lua
33+
-- Example: lsp/example_server.lua
34+
local utils = require('lsp._utils')
35+
36+
return {
37+
cmd = { 'example-language-server', '--stdio' },
38+
filetypes = { 'example' },
39+
root_dir = utils.root_dir(utils.root_patterns.git), -- Use shared patterns
40+
settings = {
41+
example = {
42+
-- Server-specific settings
43+
},
44+
},
45+
}
46+
```
47+
48+
## Utilities
49+
50+
The `_utils.lua` file provides shared utilities to reduce redundancy:
51+
52+
### Root Directory Patterns
53+
54+
Common root directory patterns are predefined:
55+
- `utils.root_patterns.js_ts` - JavaScript/TypeScript projects
56+
- `utils.root_patterns.python` - Python projects
57+
- `utils.root_patterns.go` - Go projects
58+
- `utils.root_patterns.git` - Generic git-based projects
59+
60+
### Schema Integration
61+
62+
For JSON/YAML servers with schemastore integration:
63+
```lua
64+
schemas = utils.get_schemas('json'), -- or 'yaml'
65+
```
66+
67+
## Adding New Servers
68+
69+
1. Create a new file `lsp/server_name.lua`
70+
2. Return a configuration table with server-specific settings
71+
3. Add the server name to the `servers` list in `lua/LoneExile/lsp/init.lua`
72+
4. Use shared utilities from `_utils.lua` when possible
73+
74+
## Migration from Old System
75+
76+
This configuration replaces the previous approach:
77+
78+
**Old (deprecated):**
79+
```lua
80+
lspconfig[server].setup({
81+
-- configuration
82+
})
83+
```
84+
85+
**New (current):**
86+
```lua
87+
-- Global config in init.lua
88+
vim.lsp.config('*', { ... })
89+
90+
-- Server-specific config in lsp/server.lua
91+
return { ... }
92+
93+
-- Server activation in init.lua
94+
vim.lsp.enable(servers)
95+
```
96+
97+
## Benefits
98+
99+
- **Performance**: Global configuration reduces redundancy and improves startup time
100+
- **Maintainability**: Server-specific configs are isolated and easier to manage
101+
- **Consistency**: Shared utilities ensure consistent patterns across servers
102+
- **Simplicity**: Adding new servers requires minimal configuration

lsp/_utils.lua

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- LSP Configuration Utilities
2+
-- Shared utilities to reduce redundancy across server configurations
3+
4+
local M = {}
5+
6+
-- Common root directory patterns for different project types
7+
M.root_patterns = {
8+
-- JavaScript/TypeScript projects
9+
js_ts = { 'package.json', 'tsconfig.json', 'jsconfig.json', '.git' },
10+
11+
-- Python projects
12+
python = { 'pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', '.git' },
13+
14+
-- Go projects
15+
go = { '.golangci.yml', '.golangci.yaml', '.golangci.toml', '.golangci.json', 'go.work', 'go.mod', '.git' },
16+
17+
-- Tailwind CSS projects
18+
tailwind = {
19+
'tailwind.config.js',
20+
'tailwind.config.ts',
21+
'tailwind.config.cjs',
22+
'tailwind.config.mjs',
23+
'tailwind.config.json',
24+
'postcss.config.js',
25+
'postcss.config.ts',
26+
'postcss.config.cjs',
27+
'postcss.config.mjs',
28+
'postcss.config.json',
29+
'package.json',
30+
'node_modules',
31+
'.git',
32+
},
33+
34+
-- Generic git-based projects
35+
git = { '.git' },
36+
37+
-- Configuration files
38+
config = { '.git' },
39+
}
40+
41+
-- Create a root_dir function with common patterns
42+
function M.root_dir(patterns)
43+
return function(fname)
44+
local lspconfig = require('lspconfig')
45+
return lspconfig.util.root_pattern(unpack(patterns))(fname) or lspconfig.util.path.dirname(fname)
46+
end
47+
end
48+
49+
-- Get schema configurations if schemastore is available
50+
function M.get_schemas(schema_type)
51+
return function()
52+
local status, schemastore = pcall(require, 'schemastore')
53+
if status then
54+
if schema_type == 'json' then
55+
return schemastore.json.schemas()
56+
elseif schema_type == 'yaml' then
57+
return schemastore.yaml.schemas()
58+
end
59+
end
60+
return {}
61+
end
62+
end
63+
64+
return M

lsp/csharp_ls.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
return {
2+
cmd = { 'csharp-ls' },
3+
filetypes = { 'cs' },
4+
init_options = {
5+
AutomaticWorkspaceInit = true,
6+
},
7+
root_dir = function(fname)
8+
local lspconfig = require('lspconfig')
9+
return lspconfig.util.root_pattern('*.sln', '*.csproj', '.git')(fname) or lspconfig.util.path.dirname(fname)
10+
end,
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
return {
2+
cmd = { 'docker-compose-langserver', '--stdio' },
3+
filetypes = { 'yaml.docker-compose' },
4+
root_dir = function(fname)
5+
local lspconfig = require('lspconfig')
6+
return lspconfig.util.root_pattern('docker-compose.yaml', 'docker-compose.yml', 'compose.yaml', 'compose.yml')(fname)
7+
end,
8+
single_file_support = true,
9+
}

lsp/emmet_ls.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
local utils = require('lsp._utils')
2+
3+
return {
4+
filetypes = {
5+
'astro',
6+
'css',
7+
'eruby',
8+
'html',
9+
'htmldjango',
10+
'javascriptreact',
11+
'less',
12+
'pug',
13+
'sass',
14+
'scss',
15+
'svelte',
16+
'typescriptreact',
17+
'vue',
18+
'templ',
19+
},
20+
cmd = { 'emmet-ls', '--stdio' },
21+
root_dir = utils.root_dir(utils.root_patterns.git),
22+
single_file_support = true,
23+
init_options = {
24+
html = {
25+
options = {
26+
['bem.enabled'] = true,
27+
},
28+
},
29+
},
30+
}

lsp/eslint.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
return {
2+
on_attach = function(_, bufnr)
3+
vim.api.nvim_create_autocmd('BufWritePre', {
4+
buffer = bufnr,
5+
command = 'EslintFixAll',
6+
})
7+
end,
8+
}

lsp/golangci_lint_ls.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
return {
2+
filetypes = { 'go', 'gomod' },
3+
root_dir = function(fname)
4+
local lspconfig = require('lspconfig')
5+
return lspconfig.util.root_pattern('.golangci.yml', '.golangci.yaml', '.golangci.toml', '.golangci.json', 'go.work', 'go.mod', '.git')(fname)
6+
or lspconfig.util.path.dirname(fname)
7+
end,
8+
command = { 'golangci-lint', 'run', '--out-format', 'json' },
9+
}

lsp/gopls.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
local utils = require('lsp._utils')
2+
3+
return {
4+
cmd = { 'gopls' },
5+
filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' },
6+
root_dir = utils.root_dir(utils.root_patterns.go),
7+
single_file_support = true,
8+
}

lsp/helm_ls.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
return {
2+
cmd = { 'helm_ls', 'serve' },
3+
filetypes = { 'helm' },
4+
root_dir = function(fname)
5+
local lspconfig = require('lspconfig')
6+
return lspconfig.util.root_pattern('Chart.yaml')(fname) or lspconfig.util.path.dirname(fname)
7+
end,
8+
settings = {
9+
['helm-ls'] = {
10+
logLevel = 'info',
11+
valuesFiles = {
12+
mainValuesFile = 'values.yaml',
13+
lintOverlayValuesFile = 'values.lint.yaml',
14+
additionalValuesFilesGlobPattern = 'values*.yaml',
15+
},
16+
yamlls = {
17+
enabled = true,
18+
diagnosticsLimit = 50,
19+
showDiagnosticsDirectly = false,
20+
path = 'yaml-language-server',
21+
config = {
22+
schemas = {
23+
kubernetes = 'templates/**',
24+
},
25+
completion = true,
26+
hover = true,
27+
},
28+
},
29+
},
30+
},
31+
single_file_support = true,
32+
}

lsp/html.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
return {
2+
cmd = { 'vscode-html-language-server', '--stdio' },
3+
filetypes = { 'html', 'templ' },
4+
init_options = {
5+
configurationSection = { 'html', 'css', 'javascript' },
6+
embeddedLanguages = {
7+
css = true,
8+
javascript = true,
9+
},
10+
provideFormatter = false,
11+
},
12+
single_file_support = true,
13+
}

0 commit comments

Comments
 (0)