Skip to content

Commit baebb69

Browse files
Bekaboobekaboojmbuhr
authored
refactor: use vim.fs.root() not lspconfig to find project root directory (#149)
--------- Co-authored-by: bekaboo <[email protected]> Co-authored-by: Jannik Buhr <[email protected]>
1 parent 45db179 commit baebb69

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

.neoconf.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@
44
"enabled": true,
55
"plugins": [
66
"otter.nvim",
7-
"nvim-lspconfig",
8-
"lsp",
7+
"lsp"
98
]
109
}
1110
},
1211
"neoconf": {
1312
"plugins": {
1413
"sumneko_lua": {
1514
"enabled": true
16-
},
15+
}
1716
}
18-
},
19-
"lspconfig": {
20-
"sumneko_lua": {}
2117
}
2218
}

README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ handler --> defaultHandler
111111

112112
```lua
113113
{
114-
'neovim/nvim-lspconfig',
115114
'nvim-treesitter/nvim-treesitter'
116115
}
117116
```
@@ -122,10 +121,7 @@ handler --> defaultHandler
122121
{
123122
'jmbuhr/otter.nvim',
124123
dependencies = {
125-
{
126-
'neovim/nvim-lspconfig',
127-
'nvim-treesitter/nvim-treesitter',
128-
},
124+
'nvim-treesitter/nvim-treesitter',
129125
},
130126
opts = {},
131127
},
@@ -144,7 +140,13 @@ otter.setup{
144140
-- but more instant diagnostic updates
145141
diagnostic_update_events = { "BufWritePost" },
146142
-- function to find the root dir where the otter-ls is started
147-
root_dir = require("lspconfig").util.root_pattern({ ".git", "_quarto.yml", "package.json" }),
143+
root_dir = function(_, bufnr)
144+
return vim.fs.root(bufnr or 0, {
145+
".git",
146+
"_quarto.yml",
147+
"package.json",
148+
}) or vim.fn.getcwd(0)
149+
end,
148150
},
149151
buffers = {
150152
-- if set to true, the filetype of the otterbuffers will be set.

doc/otter.nvim.txt

-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ DEPENDENCIES ~
218218
>lua
219219
{
220220
'hrsh7th/nvim-cmp', -- optional, for completion
221-
'neovim/nvim-lspconfig',
222221
'nvim-treesitter/nvim-treesitter'
223222
}
224223
<

lua/otter/config.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ local M = {}
33
local default_config = {
44
lsp = {
55
diagnostic_update_events = { "BufWritePost" },
6-
root_dir = require("lspconfig").util.root_pattern({ ".git", "_quarto.yml", "package.json" }),
6+
root_dir = function(_, bufnr)
7+
return vim.fs.root(bufnr or 0, {
8+
".git",
9+
"_quarto.yml",
10+
"package.json",
11+
}) or vim.fn.getcwd(0)
12+
end,
713
},
814
buffers = {
915
-- if set to true, the filetype of the otterbuffers will be set.

lua/otter/lsp/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ otterls.start = function(main_nr, completion)
124124
end,
125125
init_options = {},
126126
before_init = function(params, config) end,
127-
on_init = function(client, initialzie_result) end,
127+
on_init = function(client, initialize_result) end,
128128
root_dir = require("otter.config").cfg.lsp.root_dir(),
129129
on_exit = function(code, signal, client_id) end,
130130
})

tests/init.lua

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ function M.setup()
2828
vim.opt.packpath = { M.root(".tests/site") }
2929
M.load("nvim-lua/plenary.nvim")
3030
M.load("nvim-treesitter/nvim-treesitter")
31-
M.load("neovim/nvim-lspconfig")
3231
vim.env.XDG_CONFIG_HOME = M.root(".tests/config")
3332
vim.env.XDG_DATA_HOME = M.root(".tests/data")
3433
vim.env.XDG_STATE_HOME = M.root(".tests/state")

0 commit comments

Comments
 (0)