~wintershadows/dotfiles

ref: 356fb9cd385deb3c9239cb130cddf5964bbcc225 dotfiles/.config/nvim/lua/plugin-config.lua -rw-r--r-- 11.4 KiB
356fb9cd — Mysterious Grass Fix Guifont issue 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
-- Tree sitter {{{
vim.g.treesitter_filetypes = {
  'bash',
  'c',
  'cpp',
  'css',
  'fennel',
  'graphql',
  'haskell',
  'html',
  'javascript',
  'json',
  'lua',
  'python',
  'regex',
  'rst',
  'ruby',
  'teal',
  'toml',
  'typescript',
}

require('nvim-treesitter.configs').setup({
  ensure_installed = vim.g.treesitter_filetypes,

  highlight = {
    -- TODO: work out a color scheme or syntax settings that makes this output
    --       less like rainbow vomit
    enable = true,
  },

  indent = {
    -- Disable for now, it's giving weird/bad results
    enable = false,
    disable = { "python" },
  },

  -- Extension from nvim-treesitter-textobjects
  -- Note that the 'a' mappings for function parameters/arguments override the
  -- 'a' mappings from Targets.vim for function parameters/arguments.
  textobjects = {
    select = {
      enable = true,
      keymaps = {
        ["ia"] = "@parameter.inner",

        ["ac"] = "@class.outer",
        ["ic"] = "@class.inner",

        ["af"] = "@function.outer",
        ["if"] = "@function.inner",
      },
    },
    swap = {
      swap_next = {
        enable = true,
        ["<localleader>xa"] = "@parameter.inner",

        ["<localleader>xf"] = "@function.outer",
      },
      swap_previous = {
        enable = true,
        ["<localleader>Xa"] = "@parameter.inner",
        ["<localleader>XA"] = "@parameter.inner",

        ["<localleader>Xf"] = "@function.outer",
        ["<localleader>XF"] = "@function.outer",
      },
    },
    move = {
      goto_next_start = {
        enable = true,
        ["]m"] = "@function.outer",
        ["]]"] = "@class.outer",
      },
      goto_next_end = {
        enable = true,
        ["]M"] = "@function.outer",
        ["]["] = "@class.outer",
      },
      goto_previous_start = {
        enable = true,
        ["[m"] = "@function.outer",
        ["[["] = "@class.outer",
      },
      goto_previous_end = {
        enable = true,
        ["[M"] = "@function.outer",
        ["[]"] = "@class.outer",
      },
    },
    lsp_interop = {
      peek_definition_code = {
        enable = true,
        ["<localleader>pf"] = "@function.outer",
        ["<localleader>pc"] = "@class.outer",
      },
    },
  },
})
-- }}}

-- Colorizer.nvim {{{
if vim.api.nvim_get_option('termguicolors') then
 require('colorizer').setup(
 {
   css = {
     css = true,
     css_fn = true,
   }
 },
 {
   mode = 'background',
   names = false,
   RGB = true,
   RRRGGBB = true,
   RRGGBBAA = true,
 })
end
--}}}

-- DAP {{{
dap = require('dap')

--[[
* Keys in the dap.adapters table can be anything.

* The Debug Adapter can be installed in a standalone environment, because it
can run in a standalone server mode.

* An adapter definition can be a `function(adapter_callback, configuration)`.
This lets you dynamically generate the adapter at runtime, if needed.
--]]
dap.adapters.debugpy_adapter = {
  type = 'executable',
  command = vim.fn['local#joinpaths'](vim.fn['local#xdg_home']('data'), 'pipx/bin/debugpy-adapter'),
  args = { },
}

dap.adapters.generic_remote = function(callback, config)
  local dap_host = '127.0.0.1'
  local dap_port = 9865

  callback({
    type = 'server',
    host = dap_host,
    port = dap_port
  })
end

-- TODO: figure out how to correctly connect to a debug server or adapter that
--       is running inside a container!
--function dap_attach_local(port)
--  dap.attach('127.0.0.1', port, dap.configurations.generic_remote)
--end

-- TODO: check out Vimpeccable which lets you bind a key directly to a Lua
--       function, instead of my DIY version
-- local map = require('local-utils.mapping').map

vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>do]], [[v:lua.dap.repl.open()]], { noremap = true, expr = true })
vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>dc]], [[v:lua.dap.continue()]], { noremap = true, expr = true })
vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>dx]], [[v:lua.dap.stop()]], { noremap = true, expr = true })
vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>dr]], [[v:lua.dap.repl.run_last()]], { noremap = true, expr = true })

vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>dbb]], [[v:lua.dap.toggle_breakpoint()]], { noremap = true, expr = true })
vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>dbB]], [[v:lua.dap.set_breakpoint()]], { noremap = true, expr = true })
vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>dbe]], [[v:lua.dap.set_exception_breakpoints('uncaught')]], { noremap = true, expr = true })

vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>dlb]], [[v:lua.dap.list_breakpoints()]], { noremap = true, expr = true })

vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>dsi]], [[v:lua.dap.step_into()]], { noremap = true, expr = true })
vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>dso]], [[v:lua.dap.step_out()]], { noremap = true, expr = true })
vim.fn.nvim_buf_set_keymap(0, 'n', [[<localleader>dss]], [[v:lua.dap.step_over()]], { noremap = true, expr = true })

--[[
* Keys in the dap.configurations table should be Vim filetypes.

* Debugpy can be told what Python to actually run the code or module with.

Table attributes can functions with 0 parameters; this lets you dynamically
generate the configuration at runtime, if needed.
--]]
dap.configurations.python = {
  {
    type = 'generic_remote',
    request = 'attach',
    name = 'Generic remote',
  },
  {
    type = 'debugpy_adapter',
    request = 'launch',
    name = 'Launch file - auto-detect python',
    program = "${file}",
    pythonPath = function()
      local py_home = vim.b.python_home or os.getenv('PYENV_VIRTUAL_ENV') or os.getenv('VIRTUAL_ENV') or '/usr/local'
      local py_bin = vim.fn['local#os#joinpaths'](py_home, 'bin/python')
      print(string.format('Using Python: %s', py_bin))
      return py_bin
    end
  },
  {
    type = 'debugpy_adapter',
    request = 'launch',
    name = 'Launch file - Nvim host python',
    program = '${file}',
    pythonPath = function()
      return vim.g.python3_host_prog
    end
  },
}
--}}}

-- LSP completion {{{
-- TODO: "chain completion", see *g:completion_chain_complete_list*
completion = require('completion')
vim.g.completion_enable_auto_popup = 0
vim.g.completion_sorting = 'length'
-- }}}

-- LSP Config {{{
lspconfig = require('lspconfig')

function lspconfig_on_attach(lsp_client, buf_num)
  if require('completion') then
    completion.on_attach(lsp_client)
  end

  vim.api.nvim_buf_set_option(buf_num, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

  if lsp_client.resolved_capabilities.document_range_formatting then
    vim.api.nvim_buf_set_option(buf_num, 'formatexpr', 'v:lua.vim.lsp.buf.range_formatting()')
  else
    vim.cmd [[echomsg 'Range formatting not supported.']]
  end

  -- Based on example in *lsp-config* in lsp.txt
  -- TODO: use Fennel-generated shortcut functions, once they support
  -- TODO: use more of these https://github.com/neovim/nvim-lspconfig#keybindings-and-completion
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[<localleader>K]]  , [[v:lua.vim.lsp.buf.signature_help()]]  , { noremap = true, expr = true })
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[K]]               , [[v:lua.vim.lsp.buf.hover()]]           , { noremap = true, expr = true })
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[gD]]              , [[v:lua.vim.lsp.buf.definition()]]      , { noremap = true, expr = true })
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[<localleader>gdd]], [[v:lua.vim.lsp.buf.definition()]]      , { noremap = true, expr = true })
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[<localleader>gdt]], [[v:lua.vim.lsp.buf.type_definition()]] , { noremap = true, expr = true })
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[<localleader>lci]], [[v:lua.vim.lsp.buf.incoming_calls()]]  , { noremap = true, expr = true })
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[<localleader>lco]], [[v:lua.vim.lsp.buf.outgoing_calls()]]  , { noremap = true, expr = true })
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[<localleader>li]] , [[v:lua.vim.lsp.buf.implementation()]]  , { noremap = true, expr = true })
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[<localleader>ls]] , [[v:lua.vim.lsp.buf.document_symbol()]] , { noremap = true, expr = true })
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[<localleader>lr]] , [[v:lua.vim.lsp.buf.references()]]      , { noremap = true, expr = true })
  vim.api.nvim_buf_set_keymap(buf_num, 'n', [[<localleader>r]]  , [[v:lua.vim.lsp.buf.rename()]]          , { noremap = true, expr = true })
end

-- TODO: snippets

--[[
Installation (I think... I did it interactively in the REPL):
    julia                                                        \
      --project=$XDG_DATA_HOME/jlenv/environments/languageserver \
      -e 'using Pkg; Pkg.add("LanguageServer"); Pkg.add("SymbolServer")'
Invocation:
    julia                                                                 \
      --project=$XDG_DATA_HOME/jlenv/environments/lanuageserver           \
      -e "using LanguageServer, LanguageServer.SymbolServer; runserver()" \
      <env_path>
Config instructions: https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#julials
--]]
--lspconfig.julials.setup({})

-- npm install --global bash-language-server
lspconfig.bashls.setup({
  on_attach = lspconfig_on_attach,
})

-- Requires Clang 9+
--lspconfig.clangd.setup({
--  on_attach = lspconfig_on_attach,
--})

-- npm install --global vscode-css-languageserver-bin
lspconfig.cssls.setup({
  on_attach = lspconfig_on_attach,
  settings = {
    -- Disable "unknown" warning in Gtk color themes for @define-color
    css = { lint = { unknownProperties = "ignore" }, },
    scss = { lint = { unknownProperties = "ignore" }, },
    less = { lint = { unknownProperties = "ignore" }, },
  }
})

-- IDK how to install this
--lspconfig.dhall_lsp_server.setup({})

-- IDK how to install this
--lspconfig.diagnosticls.setup({})

-- npm install --global dockerfile-language-server-nodejs
lspconfig.dockerls.setup({
  on_attach = lspconfig_on_attach,
})

-- npm install -g graphql-language-service-cli
lspconfig.graphql.setup({
  on_attach = lspconfig_on_attach,
})

-- npm install --global vscode-html-languageserver-bin
lspconfig.html.setup({
  on_attach = lspconfig_on_attach,
})

-- pipx install jedi-language-server
lspconfig.jedi_language_server.setup({
  cmd = { vim.fn['local#string#joinpath2'](vim.env.PIPX_BIN_DIR, 'jedi-language-server') },
  on_attach = lspconfig_on_attach,
})

-- Only provides range formatting.
-- npm install --global vscode-json-languageserver
lspconfig.jsonls.setup({
  on_attach = lspconfig_on_attach,
})

-- npm install --global sql-language-server
lspconfig.sqlls.setup({
  on_attach = lspconfig_on_attach,
})

-- TODO: Use Vlime mappings + some REPL integration
-- raco pkg install racket-langserver
lspconfig.racket_langserver.setup({
  on_attach = lspconfig_on_attach,
})

-- :LspInstall sumneko_lua
--lspconfig.sumneko_lua.setup({
--  settings = {
--      Lua = {
--          diagnostics = {
--              globals = {
--                  'vim',
--                  'use',
--              }
--          },
--          workspace = {
--              library = {
--                  ['$VIMRUNTIME/lua'] = true,
--              }
--          }
--      }
--  }
--})

-- brew install texlab
--lspconfig.texlab.setup()

-- npm install -g typescript typescript-language-server
lspconfig.tsserver.setup({
  on_attach = lspconfig_on_attach,
})

-- npm install --global vim-language-server
lspconfig.vimls.setup({
  on_attach = lspconfig_on_attach,
})

-- npm install --global yaml-language-server
--lspconfig.yamlls.setup()
-- }}}

-- vim: set foldmethod=marker: