Skip to content

Commit 6d8b2a4

Browse files
committed
fixed: lsp setup
1 parent ac6fa29 commit 6d8b2a4

File tree

14 files changed

+122
-105
lines changed

14 files changed

+122
-105
lines changed

lsp/README.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ The LSP configuration uses the new Neovim 0.10+ core LSP approach:
1515
```
1616
lsp/
1717
├── README.md # This documentation
18-
├── _utils.lua # Shared utilities to reduce redundancy
1918
├── lua_ls.lua # Lua language server config
2019
├── gopls.lua # Go language server config
2120
├── tsserver.lua # TypeScript/JavaScript server config
@@ -31,12 +30,13 @@ Each server configuration file should return a table with server-specific settin
3130

3231
```lua
3332
-- Example: lsp/example_server.lua
34-
local utils = require('lsp._utils')
35-
3633
return {
3734
cmd = { 'example-language-server', '--stdio' },
3835
filetypes = { 'example' },
39-
root_dir = utils.root_dir(utils.root_patterns.git), -- Use shared patterns
36+
root_dir = function(fname)
37+
local lspconfig = require('lspconfig')
38+
return lspconfig.util.root_pattern('.git')(fname) or lspconfig.util.path.dirname(fname)
39+
end,
4040
settings = {
4141
example = {
4242
-- Server-specific settings
@@ -45,31 +45,46 @@ return {
4545
}
4646
```
4747

48-
## Utilities
48+
## Common Patterns
4949

50-
The `_utils.lua` file provides shared utilities to reduce redundancy:
50+
### Root Directory Functions
5151

52-
### Root Directory Patterns
52+
Most servers need a root_dir function. Common patterns:
5353

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
54+
```lua
55+
-- Git-based projects
56+
root_dir = function(fname)
57+
local lspconfig = require('lspconfig')
58+
return lspconfig.util.root_pattern('.git')(fname) or lspconfig.util.path.dirname(fname)
59+
end
60+
61+
-- JavaScript/TypeScript projects
62+
root_dir = function(fname)
63+
local lspconfig = require('lspconfig')
64+
return lspconfig.util.root_pattern('package.json', 'tsconfig.json', 'jsconfig.json', '.git')(fname)
65+
or lspconfig.util.path.dirname(fname)
66+
end
67+
```
5968

6069
### Schema Integration
6170

6271
For JSON/YAML servers with schemastore integration:
6372
```lua
64-
schemas = utils.get_schemas('json'), -- or 'yaml'
73+
schemas = function()
74+
local status, schemastore = pcall(require, 'schemastore')
75+
if status then
76+
return schemastore.json.schemas() -- or schemastore.yaml.schemas()
77+
end
78+
return {}
79+
end
6580
```
6681

6782
## Adding New Servers
6883

6984
1. Create a new file `lsp/server_name.lua`
7085
2. Return a configuration table with server-specific settings
7186
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
87+
4. Use common patterns for root_dir and schema functions when applicable
7388

7489
## Migration from Old System
7590

@@ -98,5 +113,5 @@ vim.lsp.enable(servers)
98113

99114
- **Performance**: Global configuration reduces redundancy and improves startup time
100115
- **Maintainability**: Server-specific configs are isolated and easier to manage
101-
- **Consistency**: Shared utilities ensure consistent patterns across servers
116+
- **Consistency**: Common patterns ensure consistent configuration across servers
102117
- **Simplicity**: Adding new servers requires minimal configuration

lsp/_utils.lua

Lines changed: 0 additions & 64 deletions
This file was deleted.

lsp/emmet_ls.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local utils = require('lsp._utils')
2-
31
return {
42
filetypes = {
53
'astro',
@@ -18,7 +16,10 @@ return {
1816
'templ',
1917
},
2018
cmd = { 'emmet-ls', '--stdio' },
21-
root_dir = utils.root_dir(utils.root_patterns.git),
19+
root_dir = function(fname)
20+
local lspconfig = require('lspconfig')
21+
return lspconfig.util.root_pattern('.git')(fname) or lspconfig.util.path.dirname(fname)
22+
end,
2223
single_file_support = true,
2324
init_options = {
2425
html = {

lsp/gopls.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
local utils = require('lsp._utils')
2-
31
return {
42
cmd = { 'gopls' },
53
filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' },
6-
root_dir = utils.root_dir(utils.root_patterns.go),
4+
root_dir = function(fname)
5+
local lspconfig = require('lspconfig')
6+
return lspconfig.util.root_pattern('.golangci.yml', '.golangci.yaml', '.golangci.toml', '.golangci.json', 'go.work', 'go.mod', '.git')(fname)
7+
or lspconfig.util.path.dirname(fname)
8+
end,
79
single_file_support = true,
810
}

lsp/jsonls.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
local utils = require('lsp._utils')
2-
31
return {
42
settings = {
53
json = {
6-
schemas = utils.get_schemas('json'),
4+
schemas = function()
5+
local status, schemastore = pcall(require, 'schemastore')
6+
if status then
7+
return schemastore.json.schemas()
8+
end
9+
return {}
10+
end,
711
validate = { enable = true },
812
},
913
},

lsp/pyright.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
local utils = require('lsp._utils')
2-
31
return {
42
cmd = { 'pyright-langserver', '--stdio' },
53
filetypes = { 'python' },
6-
root_dir = utils.root_dir(utils.root_patterns.python),
4+
root_dir = function(fname)
5+
local lspconfig = require('lspconfig')
6+
return lspconfig.util.root_pattern('pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', '.git')(fname)
7+
or lspconfig.util.path.dirname(fname)
8+
end,
79
settings = {
810
python = {
911
analysis = {

lsp/tailwindcss.lua

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local utils = require('lsp._utils')
2-
31
return {
42
cmd = { 'tailwindcss-language-server', '--stdio' },
53
filetypes = {
@@ -54,7 +52,24 @@ return {
5452
'svelte',
5553
'templ',
5654
},
57-
root_dir = utils.root_dir(utils.root_patterns.tailwind),
55+
root_dir = function(fname)
56+
local lspconfig = require('lspconfig')
57+
return lspconfig.util.root_pattern(
58+
'tailwind.config.js',
59+
'tailwind.config.ts',
60+
'tailwind.config.cjs',
61+
'tailwind.config.mjs',
62+
'tailwind.config.json',
63+
'postcss.config.js',
64+
'postcss.config.ts',
65+
'postcss.config.cjs',
66+
'postcss.config.mjs',
67+
'postcss.config.json',
68+
'package.json',
69+
'node_modules',
70+
'.git'
71+
)(fname) or lspconfig.util.path.dirname(fname)
72+
end,
5873
init_options = {
5974
userLanguages = {
6075
eelixir = 'html-eex',

lsp/tsserver.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
local utils = require('lsp._utils')
2-
31
return {
42
cmd = { 'typescript-language-server', '--stdio' },
53
filetypes = { 'javascript', 'javascriptreact', 'javascript.jsx', 'typescript', 'typescriptreact', 'typescript.tsx' },
6-
stInfo = 'neovim',
7-
root_dir = utils.root_dir(utils.root_patterns.js_ts),
4+
hostInfo = 'neovim',
5+
root_dir = function(fname)
6+
local lspconfig = require('lspconfig')
7+
return lspconfig.util.root_pattern('package.json', 'tsconfig.json', 'jsconfig.json', '.git')(fname) or lspconfig.util.path.dirname(fname)
8+
end,
89
init_options = {
910
hostInfo = 'neovim',
1011
preferences = {

lsp/yamlls.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
local utils = require('lsp._utils')
2-
31
return {
42
settings = {
53
yaml = {
64
schemaStore = {
75
enable = false,
86
url = '',
97
},
10-
schemas = utils.get_schemas('yaml'),
8+
schemas = function()
9+
local status, schemastore = pcall(require, 'schemastore')
10+
if status then
11+
return schemastore.yaml.schemas()
12+
end
13+
return {}
14+
end,
1115
customTags = {
1216
-- AWS CloudFormation
1317
'!And scalar',

lua/LoneExile/core/settings/plugins/all.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ return {
114114

115115
{ 'folke/todo-comments.nvim', true },
116116
{ 'folke/snacks.nvim', true },
117+
{ 'echasnovski/mini.icon', false },
117118
}

0 commit comments

Comments
 (0)