repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: normalize paths for win32

c72c7faa01ab61823f290eb0bbace29f0ee1f6ff

Oliver Krylow <o.krylow@isp-insoft.de> ·

unsigned

Browse filesCompare with HEAD

Changed files (8)

neovim/init.lua

Modified
22 22 -- [ ] DAP
23 23 -- [ ] nugu theme
24 24 -- [ ] add nu-check to nvim-lint
26 --- PLUGINS TO TRY
27 --- https://github.com/ThePrimeagen/refactoring.nvim

neovim/lua/bugabinga/diagnostic.lua

Modified
1 1 local want = require 'std.want'
2 2 local map = require 'std.keymap'
3 +local auto = require'std.auto'
4 +local icon = require'std.icon'
4 -local icon = { ' ', ' ', ' ', ' ' }
6 +local icon = { icon.error, icon.warn, icon.info, icon.hint }
5 7 icon.error = icon[1]
6 8 icon.warn = icon[2]
7 9 icon.info = icon[3]
17 19 local diagnostic = vim.diagnostic
18 ---TODO do this on LspAttach?
19 -diagnostic.disable(0)
21 +auto 'disable_diagnostic_initially'{
22 + description = 'Disable Diagnostics initially, when attaching an LSP client to a buffer',
23 + events = 'LspAttach',
24 + command = function() diagnostic.disable(0) end,
21 27 local diagnostic_format = function(context)
22 28 return string.format('%s: %s', display_name[context.severity], context.message)
38 44 float = {
39 45 focusable = false,
40 46 style = 'minimal',
41 - border = 'rounded',
47 + border = 'shadow',
42 48 source = 'if_many',
43 49 header = 'Diagnostic',
44 50 prefix = prefix_format,
51 57 local sign = function(options)
52 58 vim.fn.sign_define(options.name, {
53 - text = options.text,
54 - texthl = options.name,
55 - numhl = nil,
56 - culhl = nil,
57 - linehl = nil,
58 - })
59 + text = options.text,
60 + texthl = options.name,
61 + numhl = nil,
62 + culhl = nil,
63 + linehl = nil,
64 + })
61 67 sign { name = 'DiagnosticSignError', text = icon.error }
68 74 category = 'diagnostic',
69 75 keys = '<F6><F6>',
70 76 command = function()
71 - if diagnostic.is_disabled(0) then
72 - diagnostic.enable(0)
73 - vim.notify 'Enabling Diagnostics'
74 - else
75 - diagnostic.disable(0)
76 - vim.notify 'Disabling Diagnostics'
77 - end
77 + if diagnostic.is_disabled(0) then
78 + diagnostic.enable(0)
79 + vim.notify 'Enabling Diagnostics'
80 + else
81 + diagnostic.disable(0)
82 + vim.notify 'Disabling Diagnostics'
83 + end
81 87 map.normal {
82 - name = 'Show diagnostics under cursor',
83 - category = 'diagnostic',
84 - keys = 'H',
85 - command = diagnostic.open_float,
88 + name = 'Show diagnostics under cursor',
89 + category = 'diagnostic',
90 + keys = 'H',
91 + command = diagnostic.open_float,
88 94 local show_diagnostics_in_buffer = function()
89 -want{ 'telescope.builtin', 'telescope.themes' }(
90 - function(builtin, themes)
91 - builtin.diagnostics(themes.get_dropdown{ bufnr=0 })
92 - end)
95 + want{ 'telescope.builtin', 'telescope.themes' }(
96 + function(builtin, themes)
97 + builtin.diagnostics(themes.get_dropdown{ bufnr=0 })
98 + end)
95 101 map.normal {
96 - name = 'Show all diagnostics in buffer',
97 - category = 'diagnostic',
98 - keys = '<F6>',
99 - command = show_diagnostics_in_buffer,
102 + name = 'Show all diagnostics in buffer',
103 + category = 'diagnostic',
104 + keys = '<F6>',
105 + command = show_diagnostics_in_buffer,
102 108 local show_diagnostics_in_workspace = function()
103 -want{ 'telescope.builtin', 'telescope.themes' }(
104 - function(builtin, themes)
105 - builtin.diagnostics(themes.get_dropdown{})
106 - end)
109 + want{ 'telescope.builtin', 'telescope.themes' }(
110 + function(builtin, themes)
111 + builtin.diagnostics(themes.get_dropdown{})
112 + end)
109 115 map.normal {
110 - name = 'Show all diagnostics in workspace',
111 - category = 'diagnostic',
112 - keys = '<leader><F6>',
113 - command = show_diagnostics_in_workspace,
116 + name = 'Show all diagnostics in workspace',
117 + category = 'diagnostic',
118 + keys = '<leader><F6>',
119 + command = show_diagnostics_in_workspace,
116 122 map.normal {
117 - name = 'Go to previous diagnostic',
118 - category = 'diagnostic',
119 - keys = '<C-.>',
120 - command = diagnostic.goto_prev,
123 + name = 'Go to previous diagnostic',
124 + category = 'diagnostic',
125 + keys = '<C-.>',
126 + command = diagnostic.goto_prev,
123 129 map.normal {
124 - name = 'Go to next diagnostic',
125 - category = 'diagnostic',
126 - keys = '<C-,>',
127 - command = diagnostic.goto_next,
130 + name = 'Go to next diagnostic',
131 + category = 'diagnostic',
132 + keys = '<C-,>',
133 + command = diagnostic.goto_next,
130 136 -- a little debug helper to show all kinds of diagnostics
132 138 local dia = function( severity, line )
133 - local ns = vim.api.nvim_create_namespace('test'.. tostring(severity))
134 - local bufnr = vim.api.nvim_get_current_buf()
135 - local options = {
136 - bufnr = bufnr,
137 - lnum = line,
138 - end_lnum = line,
139 - col = 0,
140 - severity = severity,
141 - message = 'This is a test ' .. tostring(severity) .. ' diagnostic',
142 - }
139 + local ns = vim.api.nvim_create_namespace('test'.. tostring(severity))
140 + local bufnr = vim.api.nvim_get_current_buf()
141 + local options = {
142 + bufnr = bufnr,
143 + lnum = line,
144 + end_lnum = line,
145 + col = 0,
146 + severity = severity,
147 + message = 'This is a test ' .. tostring(severity) .. ' diagnostic',
144 - vim.diagnostic.set(ns, bufnr, {options})
145 - vim.diagnostic.show(ns, bufnr, {options})
150 + vim.diagnostic.set(ns, bufnr, {options})
151 + vim.diagnostic.show(ns, bufnr, {options})
148 154 local send_dia = function()
149 - dia(vim.diagnostic.severity.ERROR, 1)
150 - dia(vim.diagnostic.severity.WARN, 2)
151 - dia(vim.diagnostic.severity.INFO, 3)
152 - dia(vim.diagnostic.severity.HINT, 4)
155 + dia(vim.diagnostic.severity.ERROR, 1)
156 + dia(vim.diagnostic.severity.WARN, 2)
157 + dia(vim.diagnostic.severity.INFO, 3)
158 + dia(vim.diagnostic.severity.HINT, 4)
155 -vim.g.send_dia = send_dia
161 +vim.g.send_dia = send_dia

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

Modified
6 6 name = 'LuaLS',
7 7 filetypes = 'lua',
8 - cmd = 'lua-language-server',
8 + command = 'lua-language-server',
9 9 root_dir = project.find_lua_project_root,
10 10 single_file_support = true,
11 11 workspaces = true,
31 31 name = 'LuaLS(nvim)',
32 32 filetypes = 'lua',
33 - cmd = 'lua-language-server',
33 + command = 'lua-language-server',
34 34 root_dir = project.find_lua_nvim_project_root,
35 35 single_file_support = false,
36 36 workspaces = true,

neovim/lua/bugabinga/lsp/init.lua

Modified
35 35 -- vim.print("LSP START", file_type_event)
37 - local buffer_path = vim.api.nvim_buf_get_name(file_type_event.buf)
37 + local bufnr = file_type_event.buf
38 + local buffer_path = vim.api.nvim_buf_get_name(bufnr)
39 - vim.print( "SEARCHING LSP CLIENT FOR:", match, buffer_path)
40 + -- vim.print( "SEARCHING LSP CLIENT FOR:", match, buffer_path)
41 42 local lsp_client_configs = require'bugabinga.lsp.clients'
43 - local potential_client_configs = vim.iter(vim.deepcopy(lsp_client_configs))
44 + local potential_client_configs = vim.iter(lsp_client_configs)
44 45 :map(function(config)
45 46 vim.validate{
46 47 config = { config, 'table' },
47 48 ['config.name'] = { config.name, 'string'},
48 49 ['config.filetypes']= { config.filetypes, {'string', 'table'}},
49 - ['config.cmd'] = { config.cmd, { 'string', 'table'}},
50 - ['config.root_dir'] = { config.root_dir, 'function'},
50 + ['config.command'] = { config.command, { 'string', 'table'}},
51 + ['config.environment'] = { config.environment, 'table', true },
52 + ['config.root_dir'] = { config.root_dir, 'function', 'string'},
51 53 ['config.single_file_support'] = { config.single_file_support, 'boolean'},
54 + ['config.settings'] = { config.settings, 'table', true },
52 55 ['config.workspaces'] = { config.workspaces, 'boolean'},
56 + ['config.before_init'] = { config.before_init, 'function', true},
54 - config.cmd = type(config.cmd) == 'string' and { config.cmd } or config.cmd
58 + -- normalize scalar values to its vector alternative for easier processing later on
59 + -- NOTE: this mutates the lsp client configs! careful!
60 + config.command = type(config.command) == 'string' and { config.command } or config.command
55 61 config.filetypes = type(config.filetypes) == 'string' and { config.filetypes } or config.filetypes
56 - config.root_dir = config.root_dir(buffer_path)
57 62 return config
59 64 :filter(function(config)
62 67 :totable()
64 - vim.print("POTENTIAL CLIENTS", #potential_client_configs)
69 + -- vim.print("POTENTIAL CLIENTS", #potential_client_configs)
66 71 -- find clients, that returns some root_dir for this buffer
67 72 local config = vim.iter(potential_client_configs):find(
68 - function(_) return _.root_dir ~= nil end
73 + function(_) return _.root_dir(buffer_path) ~= nil end
71 76 -- if no client can open this buffer as part of a project (root_dir), then look
75 80 function(_) return _.single_file_support end
78 - if config then vim.print('FOUND LSP CLIENT', config.name) end
83 + if not config then
84 + vim.print('FOUND NO LSP CLIENT FOR', buffer_path)
85 + return
86 + end
88 + assert(config, 'a matching LSP client config shoud have been found by now!')
90 + local start_config = {
91 + cmd = config.command,
92 + cmd_cwd = config.root_dir(buffer_path),
93 + -- cmd_env = config.environment,
94 + detached = false, -- do i want this?
95 + -- workspace_folders = { config.root_dir(buffer_path) }, -- TODO: i think workspaces can only ever be declared per project. i cannot think of a generic way to calculate those, like with root_dir. maybe a toml/ini file in root_dir sets these?
96 + -- capabilities = vim.lsp.protocol.make_client_capabilities(),
97 + -- handlers = vim.lsp.handlers,
98 + settings = config.settings,
99 + -- commands = nil, -- what is this?
100 + -- init_options = nil,
101 + name = config.name,
102 + -- get_language_id = nil,
103 + -- offset_encoding = nil,
104 + on_error = function(code, ...) vim.print('LSP ERROR', code, ...) end,
105 + before_init = config.before_init,
106 + -- on_init = nil, -- should i send workspace/didChangeConfiguration here?
107 + on_exit = function(code, signal, client_id) vim.print("LSP CLIENT EXIT", code, signal, client_id) end,
108 + on_attach = function(client, bufnr) vim.print("LSP CLIENT ATTACH", client, bufnr) end,
109 + trace = 'off',
110 + flags = { allow_incremental_sync = true, debounce_text_changes = 50, exit_timeout = 200},
111 + root_dir = config.root_dir(buffer_path),
80 114 --TODO: augment other arguments from start_client
81 - local client_id = vim.lsp.start(config)
115 + local client_id = vim.lsp.start(start_config, {
116 + bufnr = bufnr,
117 + -- TODO: reuse if workspaces
118 + -- local supported = vim.tbl_get(client, 'server_capabilities', 'workspace', 'workspaceFolders', 'supported')
119 + -- reuse_client = function(existing_client, config)end,
120 + })
82 122 vim.print("ATTACHING LSP CLIENT", client_id)
85 - --TODO: workspaces
86 - -- local supported = vim.tbl_get(client, 'server_capabilities', 'workspace', 'workspaceFolders', 'supported')
89 125 local lsp_attach = function(...) vim.print("ATTACH LSP", ...) end
90 126 local lsp_detach = function(...) vim.print("DETACH LSP", ...) end

neovim/lua/bugabinga/plugins/heirline.lua

Modified
113 113 local file_name = {
114 114 init = function(self)
115 - self.lfilename = vim.fn.fnamemodify(self.filename, ":.")
116 - if self.lfilename == "" then self.lfilename = "~scratch~" end
115 + self.lfilename = vim.fs.normalize(vim.fn.fnamemodify(self.filename, ":."))
116 + if self.lfilename == "" then self.lfilename = "~new~" end
119 119 flexible = 2,
127 127 provider = function(self)
128 - return vim.fn.pathshorten(self.lfilename)
128 + return vim.fs.normalize(vim.fn.pathshorten(self.lfilename))
150 150 local file_name_block = {
151 151 init = function(self)
152 - self.filename = vim.api.nvim_buf_get_name(0)
152 + self.filename = vim.fs.normalize(vim.api.nvim_buf_get_name(0))
155 155 file_name,
216 216 provider = function()
217 217 local names = {}
218 - for i, server in pairs(vim.lsp.get_active_clients{ bufnr = 0 }) do
219 - table.insert(names, server.name)
218 + for i, client in pairs(vim.lsp.get_active_clients{ bufnr = 0 }) do
219 + table.insert(names, client.name)
221 - return icon.lsp .. " [" .. table.concat(names, " ") .. "]"
221 + return icon.lsp .. " " .. table.concat(names, " ")
235 235 condition = conditions.has_diagnostics,
237 237 static = {
238 - error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text,
239 - warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text,
240 - info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text,
241 - hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text,
238 + error_icon = icon.error,
239 + warn_icon = icon.warn,
240 + info_icon = icon.info,
241 + hint_icon = icon.hint,
244 244 init = function(self)
356 356 local work_dir = {
357 357 init = function(self)
358 - self.icon = (vim.fn.haslocaldir(0) == 1 and "local" or "") .. " " .. icon.folder .. " "
359 - local cwd = vim.fn.getcwd(0)
360 - self.cwd = vim.fn.fnamemodify(cwd, ":~")
358 + self.icon = (vim.fn.haslocaldir(0) == 1 and icon['local'] or "") .. " " .. icon.global .. " "
359 + self.cwd = vim.fs.normalize(vim.uv.cwd()):gsub(vim.fs.normalize(vim.uv.os_homedir()),"~")
363 362 flexible = 1,
366 365 -- evaluates to the full-length path
367 366 provider = function(self)
368 - local trail = self.cwd:sub(-1) == "/" and "" or "/"
369 - return self.icon .. self.cwd .. trail
367 + return self.icon .. self.cwd
373 371 -- evaluates to the shortened path
374 372 provider = function(self)
375 373 local cwd = vim.fn.pathshorten(self.cwd)
376 - local trail = self.cwd:sub(-1) == "/" and "" or "/"
377 - return self.icon .. cwd .. trail
374 + return self.icon .. cwd

neovim/lua/bugabinga/plugins/neodev.lua

Modified
1 1 return {
2 2 'folke/neodev.nvim',
3 + opts = {
4 + lspconfig = false,
5 + },

neovim/lua/std/icon.lua

Modified
1 1 return {
2 + error = '󰇷',
3 + warn = '󰱯',
4 + info = '󰩖',
5 + hint = '󰊪',
2 6 toggle_on = '',
3 7 toggle_off = '',
4 8 diagnostic = '⊙',
22 26 terminal = '',
23 27 macro = '',
24 28 lazy = '󰄻',
29 + global = '󱥔',
30 + ['local'] = '󱥕',

neovim/lua/std/project.lua

Modified
4 4 local join = require'std.table'.join
5 5 local dirname = vim.fs.dirname
6 6 local normalize = vim.fs.normalize
7 7 local exists = vim.loop.fs_stat
8 8 local validate = vim.validate
10 +--TODO: can this be memoized for perf?
11 +-- is the root of a buffer constant over time?
12 +-- maybe not truly constant, but constant in relation to the lifetime of a neovim session?
10 14 --- number of max loop iterations when searching for markers
11 15 local MAX_TRAVERSAL_COUNT = 100