repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

nvim: start work on lsp

7192ad0a27f2a009f5b79815f472bb1d8116d9ad

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

unsigned

Browse filesCompare with HEAD

Changed files (10)

neovim/.editorconfig

Added
new file mode 100644
1 +# see https://github.com/CppCXY/EmmyLuaCodeStyle
2 +[*.lua]
4 +# optional space/tab
5 +indent_style = space
6 +# if indent_style is space, this is valid
7 +indent_size = 2
8 +# if indent_style is tab, this is valid
9 +tab_width = 2
10 +# none/single/double
11 +quote_style = single
13 +continuation_indent = 2
15 +# this mean utf8 length , if this is 'unset' then the line width is no longer checked
16 +# this option decides when to chopdown the code
17 +max_line_length = 120
19 +# optional crlf/lf/cr/auto, if it is 'auto', in windows it is crlf other platforms are lf
20 +# in neovim the value 'auto' is not a valid option, please use 'unset'
21 +end_of_line = lf
23 +# none/ comma / semicolon / only_kv_colon
24 +table_separator_style = comma
26 +#optional keep/never/always/smart
27 +trailing_table_separator = keep
29 +# keep/remove/remove_table_only/remove_string_only
30 +call_arg_parentheses = remove
32 +detect_end_of_line = false
34 +# this will check text end with new line
35 +insert_final_newline = true
37 +# [space]
38 +space_around_table_field_list = true
40 +space_before_attribute = true
42 +space_before_function_open_parenthesis = false
44 +space_before_function_call_open_parenthesis = false
46 +space_before_closure_open_parenthesis = true
48 +# optional always/only_string/only_table/none
49 +# or true/false
50 +space_before_function_call_single_arg = always
52 +space_before_open_square_bracket = false
54 +space_inside_function_call_parentheses = true
56 +space_inside_function_param_list_parentheses = true
58 +space_inside_square_brackets = false
60 +# like t[#t+1] = 1
61 +space_around_table_append_operator = false
63 +ignore_spaces_inside_function_call = false
65 +space_before_inline_comment = 1
67 +# [operator space]
68 +space_around_math_operator = true
70 +space_after_comma = true
72 +space_after_comma_in_for_statement = true
74 +space_around_concat_operator = true
76 +# [align]
78 +align_call_args = true
80 +align_function_params = true
82 +align_continuous_assign_statement = true
84 +align_continuous_rect_table_field = true
86 +align_continuous_line_space = 2
88 +align_if_branch = true
90 +# option none / always / contain_curly/
91 +align_array_table = true
93 +align_continuous_similar_call_args = true
95 +align_continuous_inline_comment = true
96 +# option none / always / only_call_stmt
97 +align_chain_expr = none
99 +# [indent]
101 +never_indent_before_if_condition = false
103 +never_indent_comment_on_if_branch = false
105 +# [line space]
107 +# The following configuration supports four expressions
108 +# keep
109 +# fixed(n)
110 +# min(n)
111 +# max(n)
112 +# for eg. min(2)
114 +line_space_after_if_statement = keep
116 +line_space_after_do_statement = keep
118 +line_space_after_while_statement = keep
120 +line_space_after_repeat_statement = keep
122 +line_space_after_for_statement = keep
124 +line_space_after_local_or_assign_statement = keep
126 +line_space_after_function_statement = fixed(2)
128 +line_space_after_expression_statement = keep
130 +line_space_after_comment = keep
132 +# [line break]
133 +break_all_list_when_line_exceed = false
135 +auto_collapse_lines = false
137 +break_before_braces = false
138 +# [preference]
139 +ignore_space_after_colon = false
141 +remove_call_expression_list_finish_comma = false

neovim/init.lua

Modified
15 15 require'bugabinga.diagnostic'
16 16 -- FIXME(buga): should this be moved somewhere else?
17 17 require'bugabinga.trim'
18 --- lsp
19 --- require 'bugabinga.lsp'
18 +require 'bugabinga.lsp'
21 20 -- TODO:
22 21 -- [ ] add nu-check to null-ls

neovim/lazy-lock.json

Modified
8 8 "heirline.nvim": { "branch": "master", "commit": "76136ccd93ed608e8109762f032cf1118981ebbd" },
9 9 "hlargs.nvim": { "branch": "main", "commit": "cfc9beab4e176a13311efe03e38e6b6fed5df4f6" },
10 10 "indent-blankline.nvim": { "branch": "master", "commit": "b7aa0aed55887edfaece23f7b46ab22232fc8741" },
11 - "indent-o-matic": { "branch": "master", "commit": "4d11e98f523d3c4500b1dc33f0d1a248a4f69719" },
12 11 "lazy.nvim": { "branch": "main", "commit": "14d76aac4bd3ff07c1fca074c210f28f766a931e" },
13 12 "lush.nvim": { "branch": "main", "commit": "b10ef2bfff0647e701b691019ade3edd5e44eb50" },
14 13 "neodev.nvim": { "branch": "main", "commit": "da1562e1e3df0e994ddc52cb4ba22376a5d7f2fc" },
26 25 "nvim-notify": { "branch": "master", "commit": "ea9c8ce7a37f2238f934e087c255758659948e0f" },
27 26 "nvim-surround": { "branch": "main", "commit": "211eaad7c6d01ef4ac02cba9052b3082ec232101" },
28 27 "nvim-treesitter": { "branch": "master", "commit": "9fa6806b88905d52b5ca36094909630919b432cc" },
29 - "nvim-treesitter-textobjects": { "branch": "master", "commit": "52f1f3280d9092bfaee5c45be5962fabee3d9654" },
30 28 "nvim-ts-autotag": { "branch": "main", "commit": "6be1192965df35f94b8ea6d323354f7dc7a557e4" },
31 29 "nvim-ts-context-commentstring": { "branch": "main", "commit": "7f625207f225eea97ef7a6abe7611e556c396d2f" },
32 30 "nvim-web-devicons": { "branch": "master", "commit": "efbfed0567ef4bfac3ce630524a0f6c8451c5534" },
41 39 "toggleterm.nvim": { "branch": "main", "commit": "b90a1381e9b5b8596f49070ee86c71db267ac868" },
42 40 "treesj": { "branch": "main", "commit": "3203aa553217921fd4dcb79245f9df07278910b2" },
43 41 "virt-column.nvim": { "branch": "master", "commit": "93b40ea038f676f5a72d7d1f2336fe7b051fc0ce" }
44 -}

neovim/lua/bugabinga/lsp/init.lua

Added
new file mode 100644
1 +-- TODO setup neodev + jsonls for neovim plugins ans config
2 +-- TODO setup lua_ls for generic lua stuff
3 +-- TODO setup nvimjdtls + lemminx for java/maven
4 +-- TODO setup marksman + ltex for markdown
5 +-- TODO setup mason for "less important" lsps
7 +local map = require'std.keymap'
8 +local auto = require'std.auto'
10 +local _ = {}
12 +local token_update = function(lsp_client)
13 + local token = lsp_client.data.token
14 + local buffer = lsp_client.buffer
15 + local client_id = lsp_client.data.client_id
16 + local mutable_variable_highlight = 'MutableVariable'
17 + --TODO(buga): add this highlight to nugu
19 + if token.type == 'variable' and not token.modifiers.readonly then
20 + vim.lsp.semantic_tokens.highlight_token(token, buffer, client_id, mutable_variable_highlight)
21 + end
23 + --TODO(buga): find more use cases for semantic tokens
24 +end
26 +local lua_config =
28 + name = 'LuaLS',
29 + filetypes = 'lua',
30 + cmd = 'lua-language-server',
31 + root_dir = project.determine_lua_project_root,
32 + single_file = true,
33 + workspaces = true,
36 +local lsp_start = function(...) vim.print("START LSP", ...) end
37 +local lsp_attach = function(...) vim.print("ATTACH LSP", ...) end
38 +local lsp_detach = function(...) vim.print("DETACH LSP", ...) end
40 +auto 'lsp' {
41 + {
42 + description = 'Start or reuse LSP client',
43 + events = 'FileType',
44 + command = lsp_start,
45 + },
46 + {
47 + description = 'Hook: LSP client attached to buffer',
48 + events = 'LspAttach',
49 + command = lsp_attach,
50 + },
51 + {
52 + description = 'Hook: LSP client detached from buffer',
53 + events = 'LspDetach',
54 + command = lsp_detach,
55 + },
56 + {
57 + description = 'Semantic Tokens from the LSP',
58 + events = 'LspTokenUpdate',
59 + command = token_update,
60 + }
64 +return setmetatable(_ ,{
66 +})

neovim/lua/bugabinga/nugu/init.lua

Modified
107 107 Float { String }, -- a floating point constant: 2.3e10
109 109 Identifier { Normal }, -- (preferred) any variable name
110 + MutableVariable { Debug },
110 111 Function { Normal }, -- function name (also: methods for classes)
112 113 Statement { fg = content_minor }, -- (preferred) any statement

neovim/lua/std/project.lua

Modified
1 ---- Determines the path to a root directory, starting from the given directory.
1 +local dirname = vim.fs.dirname
2 +local exists = vim.loop.fs_stat
4 +--- number of max loop iterations when searching for markers
5 +local MAX_TRAVERSAL_COUNT = 100
7 +--- Determines the path to a root directory, starting from the given path.
2 8 -- Markers have a name and weight.
3 9 -- Each name is checked for existence in all directories up to the root.
4 10 -- The sum of all markers and their weight determines a directories score.
19 25 -- { name = "README", weight = 2 },
20 26 -- { naem = "Makefile", weight = 3 },
22 --- local root = project.determine_root(current_buffer, markers, "~")
28 +-- local root = project.find_root(current_buffer, markers, vim.uv.os_homedir())
23 29 -- print(root) -- /home/user/workspace/some_project
24 30 -- ```
25 ----@param directory string The starting directory, from where to begin the search.
31 +---@param path string? The starting path, from where to begin the search. If `nil`, the path of the current buffer is
32 +---used.
26 33 ---@param markers table<string,number> List of markers, that define the root, that is searched for.
27 ----@param root string The last directory on the path to root, when to stop searching. Usually '/' or '~'.
28 ----@return string? #A directory, that contains the `markers` and lies on the path from `directory` to `root`.
29 -local function determine_root(directory, markers, root)
30 - local dirname = function(path)
31 - return vim.fn.fnamemodify(path, ':h')
32 - end
33 - local exists = function(path)
34 - return vim.loop.fs_stat(path)
34 +---@param stop string? The last directory on the path to root, when to stop searching. if `nil`, the users home
35 +---directory is used.
36 +---@return string? # Directory, that contains the `markers` and lies on the path from `path` to `stop`.
37 +local function find_root(path, markers, stop)
38 + if not path then
39 + local buffer_name = vim.api.nvim_buf_get_name(0)
40 + local path = dirname(buffer_name)
43 + stop = stop or vim.uv.os_homedir()
45 + if not exists(stop) then error( 'the stop directory %s does not exist!':format(stop)) end
36 47 local directory_scores = {}
37 48 local current_distance_to_buffer = 0
38 - --traverse the path to root and check every directory on the way for files
49 + local loop_count = 0
50 + --traverse the path to stop and check every directory on the way for files
39 51 --that are named like the given markers. if markers exist, add those to the
40 52 --score of the directory. scores of all directories with markers will be
41 53 --processes later.
42 - --the root itself never gets checked for markers!
43 - -- stop if we reached the user defined root instead of the file system root
44 - while directory ~= root do
54 + --the stop itself never gets checked for markers!
55 + -- stop if we reached the user defined stop instead of the file system root
56 + while path ~= stop do
57 + if loop_count > MAX_TRAVERSAL_COUNT then error('searching for markers reached the max traversal count!') end
45 59 local score = {
46 - path = directory,
60 + path = path,
47 61 marker_count = 0,
48 62 distance_to_buffer_file = current_distance_to_buffer,
49 63 markers = {},
52 66 for _, marker in ipairs(markers) do
53 - local marker_path = directory .. '/' .. marker.name
67 + local marker_path = path .. '/' .. marker.name
54 68 if exists(marker_path) then
55 69 score.marker_count = score.marker_count + marker.weight
56 70 table.insert(score.markers, marker_path)
61 75 table.insert(directory_scores, score)
64 - directory = dirname(directory)
78 + path = dirname(path)
65 80 current_distance_to_buffer = current_distance_to_buffer + 1
81 + loop_count = loop_count + 1
68 84 local project_root = nil
86 102 --- Determines the project root directory of the current buffer file. A "project" is not clearly defined for all programming languages, so this function uses a heuristic approach.
87 ----@param custom_markers table<string, number> list of markers. a marker is a table with `name` and `weight` key. `name` can be a file or directory name, that indicates, that if a file/folder with that name exists in a directory, that directory is likely to be a project root. `weight` is a means to express confidence in that likelihood. Values should be between 1 and 3. Internally, there are some project-agnostic markers defined (e.g. README, LICENSE, .git, ...) that will be merged with `custom_markers`.
88 ----@param custom_root string Given a `custom_root` the path traversal can be aborted before the filesystem root is reached. A useful value might be `~` for example, if your source code is always in your home directory. the root directory itself does __not__ get searched for markers!
89 ----@return string|nil project_root The project root of the current buffer, or `nil`, if none could be determined.
90 -local function determine_project_root(custom_markers, custom_root)
91 - -- glob expands user defined root and checks, that it exists
92 - ---@diagnostic disable-next-line: missing-parameter
93 - local root = vim.fn.glob(custom_root)
94 - if root == '' then
95 - vim.notify('the custom root ' .. custom_root .. ' does not exist!', 'error')
96 - return nil
97 - end
103 +---@param markers table<string, number>? list of markers. a marker is a table with `name` and `weight` key. `name` can be a file or directory name, that indicates, that if a file/folder with that name exists in a directory, that directory is likely to be a project root. `weight` is a means to express confidence in that likelihood. Values should be between 1 and 3. Internally, there are some project-agnostic markers defined (e.g. README, LICENSE, .git, ...) that will be merged with `custom_markers`.
104 +---
105 +---@param stop string? Given a custom `stop` the path traversal can be aborted before the filesystem root is reached. the stop directory itself does __not__ get searched for markers!
106 +---
107 +---@return string? # The project root of the current buffer, or `nil`, if none could be determined.
108 +---
109 +local function find_project_root(markers)
98 110 -- define some language-independent markers
99 - local markers = {
111 + local default_markers = {
100 112 { name = '.git', weight = 1 },
101 113 { name = '.gitignore', weight = 1 },
102 114 { name = '.svn', weight = 1 },
104 116 { name = 'Jenkinsfile', weight = 1 },
105 117 { name = '.editorconfig', weight = 1 },
106 118 { name = 'LICENSE', weight = 1 },
119 + { name = 'LICENSE.md', weight = 1 },
107 120 { name = 'LICENSE.txt', weight = 1 },
108 121 { name = 'COPYING', weight = 1 },
109 122 { name = 'README', weight = 1 },
110 123 { name = 'README.md', weight = 1 },
124 + { name = 'Makefile', weight = 1 },
125 + { name = 'flake.nix', weight = 1 },
126 + { name = 'flake.nix', weight = 1 },
112 - markers = vim.tbl_deep_extend('force', markers, custom_markers)
128 + markers = vim.tbl_deep_extend('force', default_markers, markers)
114 - local buffer_name = vim.api.nvim_buf_get_name(0)
115 - local directory_name = vim.fn.fnamemodify(buffer_name, ':p:h')
116 - return determine_root(directory_name, markers, root)
130 + return find_root(nil, markers)
119 -local java_markers = {
120 - { name = '.idea', weight = 2 },
121 - { name = '.classpath', weight = 2 },
122 - { name = '.settings', weight = 2 },
123 - { name = '.project', weight = 2 },
124 - { name = 'target', weight = 2 },
125 - { name = 'pom.xml', weight = 2 },
126 - { name = 'mvnw', weight = 3 },
127 - { name = '.mvn', weight = 3 },
128 - { name = 'mvnw.cmd', weight = 3 },
129 - { name = 'build.gradle', weight = 2 },
130 - { name = 'gradle.properties', weight = 3 },
131 - { name = 'settings.gradle', weight = 3 },
132 - { name = 'gradlew', weight = 3 },
133 - { name = 'gradlew.bat', weight = 3 },
133 +local function find_java_project_root()
134 + local java_markers = {
135 + { name = '.idea', weight = 2 },
136 + { name = '.classpath', weight = 2 },
137 + { name = '.settings', weight = 2 },
138 + { name = '.project', weight = 2 },
139 + { name = 'target', weight = 2 },
140 + { name = 'pom.xml', weight = 2 },
141 + { name = 'mvnw', weight = 3 },
142 + { name = '.mvn', weight = 3 },
143 + { name = 'mvnw.cmd', weight = 3 },
144 + { name = 'build.gradle', weight = 2 },
145 + { name = 'gradle.properties', weight = 3 },
146 + { name = 'settings.gradle', weight = 3 },
147 + { name = 'gradlew', weight = 3 },
148 + { name = 'gradlew.bat', weight = 3 },
151 + return find_root(nil, java_markers)
152 +end
154 +local lua_markers = {
155 + {name = '.luacheckrc', weight = 1},
156 + {name = '.stylua.toml', weight = 1},
157 + {name = 'selene.toml', weight = 1},
135 -local function determine_java_project_root(user_root)
136 - return determine_project_root(java_markers, user_root)
159 +local nvim_lua_markers = {
160 + {name = 'neovim.yml', weight = 1},
161 + {name = 'init.lua', weight = 1},
162 + {name = 'lua', weight = 2},
165 +local find_lua_project_root = function()
166 + return find_root(nil, lua_markers)
139 -local function is_java_project_root(directory, user_root)
140 - -- avoid determine_project_root to __not__ check non-java markers
141 - return determine_root(directory, java_markers, user_root) ~= nil
169 +local find_nvim_lua_project_root = function()
170 + local markers = vim.tbl_deep_extend('error', lua_markers, nvim_lua_markers)
171 + return find_root(nil, markers)
144 174 return {
145 - is_java_project_root = is_java_project_root,
146 - determine_root = determine_root,
147 - determine_project_root = determine_project_root,
148 - determine_java_project_root = determine_java_project_root,
175 + find_root = find_root,
176 + find_project_root = find_project_root,
177 + find_java_project_root = find_java_project_root,
178 + find_lua_project_root = find_lua_project_root,
179 + find_nvim_lua_project_root = find_nvim_lua_project_root,

neovim/neovim.yml

Deleted
deleted file mode 100644
1 ----
2 -base: lua51
3 -name: neovim
4 -globals:
5 - after_each:
6 - args:
7 - - type: function
8 - assert:
9 - args:
10 - - type: bool
11 - - required: false
12 - type: string
13 - before_each:
14 - args:
15 - - type: function
16 - describe:
17 - args:
18 - - type: string
19 - - type: function
20 - it:
21 - args:
22 - - type: string
23 - - type: function
24 - vim:
25 - any: true

neovim/selene.toml

Deleted
deleted file mode 100644
1 -std = "neovim"
3 -[rules]
4 -global_usage = "allow"
5 -multiple_statements = "allow"

neovim/stylua.toml

Deleted
deleted file mode 100644
1 -column_width = 120
2 -line_endings = "Unix"
3 -indent_type = "Spaces"
4 -indent_width = 2
5 -quote_style = "AutoPreferSingle"
6 -call_parentheses = "None"

wezterm/wezterm.lua

Modified
48 48 font_size = 16
49 49 elseif hostname == 'PC-00625' then
50 50 font = wez.font'BlexMono Nerd Font'
51 - font_size = 12
51 + font_size = 14
54 54 return {