repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: playing around with project root logic

c498152a7844a61971f6d53918cbf43c1f54e05d

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (9)

neovim/.luarc.jsonc

Deleted
deleted file mode 100644
1 -{
2 - "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
3 - "diagnostics": {
4 - "globals": [
5 - "vim"
6 - ],
7 - "neededFileStatus": {
8 - "codestyle-check": "Any"
9 - }
10 - },
11 - "workspace": {
12 - "checkThirdParty": false
13 - },
14 - "runtime": {
15 - "version": "LuaJIT",
16 - "pathStrict": true,
17 - "special": {
18 - "want": "require"
19 - }
20 - }
21 -}

neovim/lazy-lock.json

Modified
16 16 "hyper.nvim": { "branch": "main", "commit": "b84fb39e703b1dd487d20c4faf028ee51374c88b" },
17 17 "indent-blankline.nvim": { "branch": "master", "commit": "821a7acd88587d966f7e464b0b3031dfe7f5680c" },
18 18 "lazy.nvim": { "branch": "main", "commit": "83493db50a434a4c5c648faf41e2ead80f96e478" },
19 + "lsp_signature.nvim": { "branch": "master", "commit": "c6aeb2f1d2538bbdfdaab1664d9d4c3c75aa9db8" },
19 20 "mason-tool-installer.nvim": { "branch": "main", "commit": "1212fb6082b7177dde17ea65e429e027835aeb40" },
20 21 "mason.nvim": { "branch": "main", "commit": "c43eeb5614a09dc17c03a7fb49de2e05de203924" },
21 22 "mini.align": { "branch": "main", "commit": "f845218c5fea89e49074e48270dc5e1b9511a0f9" },

neovim/lua/bugabinga/lsp/clients/lua.lua

Modified
11 11 settings = {
12 12 Lua = {
13 13 addonManager = { enable = false, },
14 - completion = { callSnippet = 'Disable', postfix = '.', },
14 + completion = { callSnippet = 'Replace', },
15 15 diagnostics = { globals = { 'vim', }, workspaceRate = 50, },
16 16 hint = { enable = true, setType = true, },
17 17 telemetry = { enable = false, },

neovim/lua/bugabinga/lsp/init.lua

Modified
193 193 local old_tagfunc
195 195 local keybinds = {}
196 -local add = function ( client_id, keybind )
196 +local add = function ( client_id, keybind_remover )
197 + vim.validate {
198 + client_id = { client_id, 'number', },
199 + keybind_remover = { keybind_remover, 'function', },
197 201 if not table.contains( keybinds, client_id ) then
198 202 keybinds[client_id] = {}
200 - table.insert( keybinds[client_id], keybind )
204 + table.insert( keybinds[client_id], keybind_remover )
203 207 local lsp_attach = function ( args )
204 208 local bufnr = args.buf
205 - local client = vim.lsp.get_client_by_id( args.data.client_id )
209 + local client_id = args.data.client_id
210 + local client = vim.lsp.get_client_by_id( client_id )
206 211 if not client then return end
208 213 debug.print( client.server_capabilities )
245 + local lsp_signature_ok, lsp_signature = pcall( require, 'lsp_signature' )
246 + if lsp_signature_ok then
247 + lsp_signature.on_attach( {}, bufnr )
248 + end
240 250 if client.server_capabilities.documentHighlightProvider then
241 251 -- the timer has application lifetime. no need to close
242 252 local delay = 300
262 272 if client.server_capabilities.inlayHintProvider then
263 - add( map.normal {
273 + add( client_id, map.normal {
264 274 description = 'Toggle inlay hints',
265 275 category = 'lsp',
266 276 buffer = bufnr,
267 277 keys = '<leader>ti',
268 278 command = function ()
269 - vim.lsp.inlay_hint( bufnr, nil )
279 + vim.lsp.inlay_hint.enable( bufnr, nil )
274 - add( map.normal {
284 + add( client_id, map.normal {
275 285 description = 'Show hover documentation above cursor.',
276 286 category = 'lsp',
277 287 buffer = bufnr,
279 289 command = vim.lsp.buf.hover,
282 - add( map.normal {
292 + add( client_id, map.normal {
283 293 description = 'Show signature help under cursor.',
284 294 category = 'lsp',
285 295 buffer = bufnr,
287 297 command = vim.lsp.buf.signature_help,
290 - add( map.normal {
300 + add( client_id, map.normal {
291 301 description = 'Show available code actions on current line.',
292 302 category = 'lsp',
293 303 buffer = bufnr,
295 305 command = vim.lsp.buf.code_action,
298 - add( map.normal {
308 + add( client_id, map.normal {
299 309 description = 'Goto to definition of symbol under cursor.',
300 310 category = 'lsp',
301 311 buffer = bufnr,
303 313 command = vim.lsp.buf.definition,
306 - add( map.normal {
316 + add( client_id, map.normal {
307 317 description = 'Show implementations of symbol under cursor.',
308 318 category = 'lsp',
309 319 buffer = bufnr,
311 321 command = vim.lsp.buf.implementation,
314 - add( map.normal {
324 + add( client_id, map.normal {
315 325 description = 'Show incoming calls of symbol under cursor.',
316 326 category = 'lsp',
317 327 buffer = bufnr,
319 329 command = vim.lsp.buf.incoming_calls,
322 - add( map.normal {
332 + add( client_id, map.normal {
323 333 description = 'Show outgoing calls of symbol under cursor.',
324 334 category = 'lsp',
325 335 buffer = bufnr,
327 337 command = vim.lsp.buf.outgoing_calls,
330 - add( map.normal {
340 + add( client_id, map.normal {
331 341 description = 'Show references of symbol under cursor.',
332 342 category = 'lsp',
333 343 buffer = bufnr,
335 345 command = vim.lsp.buf.references,
338 - add( map.normal {
348 + add( client_id, map.normal {
339 349 description = 'Rename symbol under cursor.',
340 350 category = 'lsp',
341 351 buffer = bufnr,

neovim/lua/bugabinga/nugu/init.lua

Modified
204 204 _.Define = _.PreProc
205 205 _.Macro = _.PreProc
206 206 _.PreCondit = _.PreProc
207 +_.Parameter { fg = content_focus, }
208 209 _.Type = _.Statement
209 210 _.StorageClass = _.Statement
276 277 _['@function'] = _.Function
277 278 _['@function.builtin'] = _.Special
278 279 _['@function.macro'] = _.Macro
279 -_['@parameter'] = _.Identifier
280 +_['@parameter'] = _.Parameter
280 281 _['@method'] = _.Function
281 282 _['@field'] = _.Identifier
282 283 _['@property'] = _.Identifier
293 294 _['@type.definition'] = _.Typedef
294 295 _['@storageclass'] = _.StorageClass
295 296 _['@structure'] = _.Structure
296 -_['@namespace'] = _.Identifier
297 +_['@namespace'] = _.PreProc
297 298 _['@include'] = _.Include
298 299 _['@preproc'] = _.PreProc
299 300 _['@debug'] = _.Debug
518 519 _.IblWhitespace = _.Whitespace
519 520 _.IblScope { fg = ui_focus, bg = _.Normal.bg, }
521 -_.Hlargs { fg = content_important_local, }
523 523 _.MiniStarterCurrent { fg = ui_normal, bg = ui_accent, }
524 524 _.MiniStarterFooter = _.Keyword

neovim/lua/bugabinga/plugins/hlargs.lua

Deleted
deleted file mode 100644
1 -return {
2 - 'm-demare/hlargs.nvim',
3 - event = { 'BufRead', 'BufLeave', 'BufEnter', 'SessionLoadPost', },
4 - opts = {
5 - -- highlight = { 'Hlargs', },
6 - paint_arg_declarations = true,
7 - paint_arg_usages = true,
8 - paint_catch_blocks = {
9 - declarations = true,
10 - usages = true,
11 - },
12 - extras = { named_parameter = true, },
13 - excluded_argnames = {
14 - declarations = {},
15 - usages = { lua = {}, },
16 - },
17 - },
18 - dependencies = {
19 - 'nvim-treesitter/nvim-treesitter',
20 - },
21 -}

neovim/lua/bugabinga/plugins/lsp_signature.lua

Added
new file mode 100644
1 +return {
2 + 'ray-x/lsp_signature.nvim',
3 + event = 'VeryLazy',
4 + opts = {
5 + debug = require 'std.debug'.get(),
6 + -- floating_window_off_x = 10,
7 + -- floating_window_off_y = -2,
8 + -- handler_opts = { border = vim.g.border_style, },
9 + },

neovim/lua/bugabinga/plugins/neodev.lua

Modified
1 1 return {
2 2 'folke/neodev.nvim',
3 + lazy = false,
3 4 opts = {
4 5 lspconfig = false,
5 6 override = function ( root_dir, library )

neovim/lua/std/project.lua

Modified
11 11 local markers_to_string = function ( markers )
12 12 return vim.inspect( markers )
14 -local create_hash = function ( path, markers )
14 +local create_hash = function ( path, markers, stop )
15 15 local path_hash = hasher( path )
16 + local stop_hash = hasher( stop )
16 17 local markers_hash = hasher( markers_to_string( markers ) )
17 - local hash = path_hash .. '|' .. markers_hash
18 + local hash = path_hash .. '|' .. markers_hash .. '|' .. stop_hash
18 19 return hash
20 -local cache_get = function ( path, markers )
21 - local hash = create_hash( path, markers )
21 +local cache_get = function ( path, markers, stop )
22 + local hash = create_hash( path, markers, stop )
22 23 local hit = cache[hash]
23 24 return hit
25 -local cache_set = function ( project_root, path, markers )
26 - local hash = create_hash( path, markers )
26 +local cache_set = function ( project_root, path, markers, stop )
27 + local hash = create_hash( path, markers, stop )
27 28 cache[hash] = project_root
35 36 --- the weight of a project marker, when the likelyhood is low
36 37 local MAYBE = 1
37 38 --- the weight of a project marker, when the likelyhood is high
38 -local LIKELY = 2
39 +local LIKELY = 3
39 40 --- the weight of a project marker, when the likelyhood is 100%
40 -local DEFINITLY = 3
41 +local DEFINITLY = 7
42 43 --- Determines the path to a root directory, starting from the given path.
43 44 -- Markers have a name and weight.
56 57 -- local project = require'std.project'
57 58 -- local current_buffer = vim.api.nvim_buf_get_name(0)
58 59 -- local markers = {
59 --- { name = ".git", weight = MAYEB },
60 +-- { name = ".git", weight = MAYBE },
60 61 -- { name = "README", weight = LIKELY },
61 62 -- { naem = "Makefile", weight = DEFINITLY },
86 87 if #path == 0 then return nil end
88 - local cache_hit = cache_get( path, markers )
89 + local cache_hit = cache_get( path, markers, stop )
89 90 if cache_hit then
90 91 debug.print( 'CACHE HIT', cache_hit )
91 92 return cache_hit
135 136 local project_root = nil
136 137 local max_likelyhood = 0
137 138 -- the project root is most likely the directory with the highest marker count
138 - -- and highest distance to current buffer.
139 - -- because if there are markers further away from the buffer than other markers,
140 - -- then it is most likely a nested project structure (multi-module).
139 + -- and closest distance to current buffer.
140 + -- however, if there are markers further away from the buffer than other markers,
141 + -- then it could be a nested project structure (multi-module).
141 142 -- in those cases we are looking for the root project folder, instead the nearest
142 143 -- child project root folder.
143 144 for _, score in ipairs( directory_scores ) do
144 - local likelihood = score.marker_count + score.distance_to_buffer_file
145 - if likelihood > max_likelyhood then
146 - max_likelyhood = likelihood
145 + local likelyhood = score.marker_count * (1 / score.distance_to_buffer_file)
146 + if debug.get() then score.likelyhood = likelyhood end
147 + if likelyhood > max_likelyhood then
148 + max_likelyhood = likelyhood
147 149 project_root = score.path
150 152 if project_root then
151 - cache_set( project_root, path, markers )
153 + cache_set( project_root, path, markers, stop )
155 + debug.print( 'found project root', project_root, directory_scores )
153 156 return project_root
162 165 local function find_project_root( path, markers )
163 166 -- define some language-independent markers
164 167 local default_markers = {
165 - { name = '.git', weight = LIKELY, },
166 - { name = '.gitignore', weight = LIKELY, },
167 - { name = '.svn', weight = LIKELY, },
168 - { name = 'justfile', weight = LIKELY, },
169 - { name = 'Jenkinsfile', weight = MAYBE, },
170 - { name = '.editorconfig', weight = MAYBE, },
171 - { name = 'LICENSE', weight = MAYBE, },
172 - { name = 'LICENSE.md', weight = MAYBE, },
173 - { name = 'LICENSE.txt', weight = MAYBE, },
174 - { name = 'COPYING', weight = MAYBE, },
175 - { name = 'README', weight = MAYBE, },
176 - { name = 'README.md', weight = MAYBE, },
177 - { name = 'Makefile', weight = LIKELY, },
178 - { name = 'flake.nix', weight = MAYBE, },
179 - { name = 'flake.nix', weight = MAYBE, },
180 - { name = '.project_model', weight = DEFINITLY, },
168 + { name = '.git', weight = LIKELY, },
169 + { name = '.gitignore', weight = LIKELY, },
170 + { name = '.svn', weight = LIKELY, },
171 + { name = 'justfile', weight = LIKELY, },
172 + { name = 'Jenkinsfile', weight = MAYBE, },
173 + { name = '.editorconfig', weight = MAYBE, },
174 + { name = 'LICENSE', weight = MAYBE, },
175 + { name = 'LICENSE.md', weight = MAYBE, },
176 + { name = 'LICENSE.txt', weight = MAYBE, },
177 + { name = 'COPYING', weight = MAYBE, },
178 + { name = 'README', weight = MAYBE, },
179 + { name = 'README.md', weight = MAYBE, },
180 + { name = 'Makefile', weight = LIKELY, },
181 + { name = 'flake.nix', weight = MAYBE, },
182 + { name = 'flake.nix', weight = MAYBE, },
183 + { name = '.project_model.lua', weight = DEFINITLY, },
183 186 markers = markers or {}
205 208 { name = 'gradlew', weight = DEFINITLY, },
206 209 { name = 'gradlew.bat', weight = DEFINITLY, },
208 - return find_root( path, java_markers )
211 + return find_project_root( path, java_markers )
211 -local lua_markers = {
212 - { name = '.luarc.json', weight = MAYBE, },
213 - { name = '.luarc.jsonc', weight = MAYBE, },
214 - { name = '.luacheckrc', weight = MAYBE, },
215 - { name = '.stylua.toml', weight = MAYBE, },
216 - { name = 'stylua.toml', weight = MAYBE, },
217 - { name = 'selene.toml', weight = MAYBE, },
218 - { name = 'selene.yml', weight = MAYBE, },
219 - { name = 'neovim.yml', weight = MAYBE, },
220 - { name = 'lua', weight = MAYBE, },
223 214 local find_lua_project_root = function ( path )
224 - return find_root( path, lua_markers )
215 + local lua_markers = {
216 + { name = '.luarc.json', weight = MAYBE, },
217 + { name = '.luarc.jsonc', weight = MAYBE, },
218 + { name = '.luacheckrc', weight = MAYBE, },
219 + { name = '.stylua.toml', weight = MAYBE, },
220 + { name = 'stylua.toml', weight = MAYBE, },
221 + { name = 'selene.toml', weight = MAYBE, },
222 + { name = 'selene.yml', weight = MAYBE, },
223 + { name = 'neovim.yml', weight = MAYBE, },
224 + { name = 'lua', weight = MAYBE, },
227 + return find_project_root( path, lua_markers )
227 -local zig_markers = {
228 - { name = 'build.zig', weight = DEFINITLY, },
229 - { name = 'zls.build.json', weight = DEFINITLY, },
230 - { name = 'zig-cache', weight = MAYBE, },
231 - { name = 'zig-out', weight = MAYBE, },
234 230 local find_zig_project_root = function ( path )
235 - return find_root( path, zig_markers )
231 + local zig_markers = {
232 + { name = 'build.zig', weight = DEFINITLY, },
233 + { name = 'zls.build.json', weight = DEFINITLY, },
234 + { name = 'zig-cache', weight = MAYBE, },
235 + { name = 'zig-out', weight = MAYBE, },
238 + --FIXME: can we ask the zig build system for this info?
239 + return find_project_root( path, zig_markers )
238 242 local find_rust_project_root = function ( path )
239 243 local markers = {
240 244 { name = 'Cargo.toml', weight = DEFINITLY, },
242 - local cargo_crate_dir = find_root( path, markers )
246 + local cargo_crate_dir = find_project_root( path, markers )
243 247 if cargo_crate_dir == nil then return nil end
245 249 local cmd = {