@@ -15,7 +15,6 @@ The LSP configuration uses the new Neovim 0.10+ core LSP approach:
1515```
1616lsp/
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-
3633return {
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
6271For 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
69841 . Create a new file ` lsp/server_name.lua `
70852 . Return a configuration table with server-specific settings
71863 . 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
0 commit comments