commit b6c895c75fa91083025507ae6146bbc1372b4cd6
parent d8b9208426f52492254db2f0b8c8427e421f990c
Author: Tomas Nemec <nemi@skaut.cz>
Date: Tue, 26 Apr 2022 16:19:17 +0200
update
Diffstat:
13 files changed, 271 insertions(+), 178 deletions(-)
diff --git a/after/plugin/nulls.lua b/after/plugin/nulls.lua
@@ -1,64 +1,75 @@
-if not pcall(require, 'null-ls') then return end
+local servers = require('tms.lsp.servers')
-local null_ls = require('null-ls')
-local h = require('null-ls.helpers')
-local builtins = null_ls.builtins
+local on_attach = function(client, bufnr)
+ local lsp = vim.lsp
-local zsh_diag = {
- name = 'zsh check',
- method = null_ls.methods.DIAGNOSTICS,
- filetypes = { 'zsh' },
- update_on_insert = true,
- generator = null_ls.generator({
- command = 'zsh',
- args = { '-n', '$FILENAME' },
- format = 'line',
- check_exit_code = function(code) return code <= 1 end,
- from_stderr = true,
- to_stdin = true,
- on_output = h.diagnostics.from_patterns({ { pattern = [[%w+:(%d+): (.*)]], groups = { 'row', 'message' } } }),
- }),
-}
+ lsp.handlers['textDocument/hover'] = lsp.with(lsp.handlers.hover, { border = 'single' })
+ lsp.handlers['textDocument/signatureHelp'] = lsp.with(lsp.handlers.signature_help, { border = 'single' })
+ vim.api.nvim_buf_set_option(bufnr, 'tagfunc', 'v:lua.vim.lsp.tagfunc')
+ -- vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr()')
-null_ls.setup({
- on_attach = function(_, bufnr)
- vim.keymap.set('n', 'Q', vim.lsp.buf.formatting,
- { silent = true, buffer = bufnr, noremap = true, desc = 'LSP Format (nulls)' })
- vim.keymap.set('v', 'Q', vim.lsp.buf.range_formatting,
- { silent = true, buffer = bufnr, noremap = true, desc = 'LSP Range Format (nulls)' })
- end,
- sources = {
- -- formatting
- builtins.formatting.prettier.with {
- filetypes = { 'html', 'yaml', 'markdown', 'css', 'scss' },
- args = h.range_formatting_args_factory({
- '--parser',
- vim.api.nvim_buf_get_option(0, 'filetype'),
- '--stdin-filepath',
- '$FILENAME',
- }, '--range-start', '--range-end'),
- },
- builtins.formatting.prettier.with {
- filetypes = { 'typescript' },
- args = h.range_formatting_args_factory({
- '--parser',
- vim.api.nvim_buf_get_option(0, 'filetype'),
- '--trailing-comma',
- 'all',
- '--tab-width',
- '2',
- '--stdin-filepath',
- '$FILENAME',
- }, '--range-start', '--range-end'),
- },
- builtins.formatting.lua_format,
- -- builtins.formatting.clang_format,
- builtins.formatting.shfmt.with {
- filetypes = { 'sh', 'zsh' },
- args = { '-i', vim.opt.shiftwidth:get(), '-filename', '$FILENAME' },
- },
- -- diagnostic
- builtins.diagnostics.shellcheck,
- zsh_diag,
- },
-})
+ local opts = function(desc) return { silent = true, buffer = bufnr, desc = desc } end
+ vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts('LSP Definition'))
+ vim.keymap.set('n', 'gD', '<cmd>vsplit | lua vim.lsp.buf.definition()<cr>', opts('LSP definition in vsplit'))
+ vim.keymap.set('n', 'gT', vim.lsp.buf.type_definition, opts('LSP Type Definition'))
+ vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts('LSP Implementation'))
+ vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts('LSP Hover'))
+ vim.keymap.set('n', '<c-p>', vim.lsp.buf.signature_help, opts('LSP Signature Help'))
+ vim.keymap.set('i', '<c-p>', vim.lsp.buf.signature_help, opts('LSP Signature Help'))
+ vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts('LSP References'))
+ vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, opts('LSP Code Actions'))
+ vim.keymap.set('v', 'ga', vim.lsp.buf.range_code_action, opts('LSP Code Actions'))
+ vim.keymap.set('n', 'gn', vim.lsp.buf.rename, opts('LSP Rename'))
+
+ vim.keymap.set('n', 'Q', vim.lsp.buf.formatting, opts('LSP Format'))
+ vim.keymap.set('v', 'Q', ':<c-u>lua vim.lsp.buf.range_formatting()<cr>', opts('LSP Range Format'))
+
+ local has_lsp_format, lsp_format = pcall(require, 'lsp-format')
+ if has_lsp_format then lsp_format.on_attach(client) end
+ local has_aerial, aerial = pcall(require, 'aerial')
+ if has_aerial then aerial.on_attach(client, bufnr) end
+end
+
+local capabilities = function()
+ local ok, cnl = pcall(require, 'cmp_nvim_lsp')
+ if ok then
+ return cnl.update_capabilities(vim.lsp.protocol.make_client_capabilities())
+ else
+ return vim.lsp.protocol.make_client_capabilities()
+ end
+end
+
+local make_opts = function(name, server)
+ local opts = {}
+ opts.on_attach = on_attach
+ opts.capabilities = capabilities()
+ opts = servers.setup(name, opts, server)
+ return opts
+end
+
+local setup = function()
+ -- LSP Installer
+ local has_lspi, lsp_installer = pcall(require, 'nvim-lsp-installer')
+ if has_lspi then
+ lsp_installer.on_server_ready(function(server)
+ local opts = make_opts(server.name, server)
+ server:setup(opts)
+ end)
+ end
+
+ -- LSP Config
+ local has_lspc, lsp_config = pcall(require, 'lspconfig')
+ if has_lspc then
+ local manual_servers = { 'gdscript', 'dartls' }
+ for _, name in ipairs(manual_servers) do
+ local opts = make_opts(name)
+ lsp_config[name].setup(opts)
+ end
+ end
+
+ -- Manual
+ local has_zk, zk = pcall(require, 'zk')
+ if has_zk then zk.setup({ lsp = { config = make_opts('zk') } }) end
+end
+
+return { on_attach = on_attach, setup = setup }
diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua
@@ -22,33 +22,33 @@ require('packer').init()
_ = telescope.load_extension('packer')
local map = function(mode, lhs, picker, opts)
+ opts = opts or {}
opts.desc = 'Telescope ' .. picker
vim.keymap.set(mode, lhs, require('tms.p.telescope')[picker], opts)
end
-local opts = { noremap = true }
-map('n', '<space>h', 'help_tags', opts)
-map('n', '<space>d', 'find_files', opts)
-map('n', '<space>D', 'find_files', opts)
-map('n', '<space>g', 'git_files', opts)
-map('n', '<space>b', 'buffers', opts)
-map('n', '<space>l', 'lines', opts)
-map('n', '<space>e', 'grep_string', opts)
-map('n', '<space>c', 'git_status', opts)
-map('n', '<space>q', 'quickfix', opts)
-map('n', '<space>k', 'keymaps', opts)
-map('n', '<space>m', 'man_pages', opts)
-map('n', '<space>o', 'oldfiles', opts)
-map('n', '<space>t', 'treesitter', opts)
-
-map('n', '<space>p', 'packer', opts)
-map('n', '<space>P', 'reloader', opts)
-map('n', '<space>M', 'media_files', opts)
-map('n', '<space>r', 'aerial', opts)
-map('n', '<space>wo', 'git_worktrees', opts)
-map('n', '<space>wi', 'create_git_worktree', opts)
-
-map('n', '<space>n', 'edit_neovim', opts)
+map('n', '<space>h', 'help_tags')
+map('n', '<space>d', 'find_files')
+map('n', '<space>D', 'find_files')
+map('n', '<space>g', 'git_files')
+map('n', '<space>b', 'buffers')
+map('n', '<space>l', 'lines')
+map('n', '<space>e', 'grep_string')
+map('n', '<space>c', 'git_status')
+map('n', '<space>q', 'quickfix')
+map('n', '<space>k', 'keymaps')
+map('n', '<space>m', 'man_pages')
+map('n', '<space>o', 'oldfiles')
+map('n', '<space>t', 'treesitter')
+map('n', '<space>p', 'packer')
+map('n', '<space>P', 'reloader')
+map('n', '<space>M', 'media_files')
+map('n', '<space>r', 'aerial')
+map('n', '<space>wo', 'git_worktrees')
+map('n', '<space>wi', 'create_git_worktree')
+map('n', '<space>n', 'edit_neovim')
+map('n', 'gm', 'lsp_document_symbols')
+map('n', 'gM', 'lsp_dynamic_workspace_symbols')
require('tms.colors').update(function(t)
t.Group.new('TelescopeSelection', nil, t.dimm(t.groups.Normal.bg, 0.05))
diff --git a/ftplugin/dart.lua b/ftplugin/dart.lua
@@ -1,30 +1,38 @@
vim.g.dart_style_guide = 2
vim.g.dart_html_in_string = true
+local dlsp = require('tms.ft.dart.lsp')
+local ddebug = require('tms.ft.dart.debug')
+local analyze = require('tms.ft.dart.analyze')
+
local cmd_opts = { buffer = nil }
-- vim.cmd [[command! -buffer DartAnalyzer lua require('tms.ft.dart.analyze').qf2131()]]
-vim.api.nvim_create_user_command('DartDebug', require('tms.ft.dart.debug').func, cmd_opts)
-vim.api.nvim_create_user_command('DartPrint', require('tms.ft.dart.debug').print, cmd_opts)
-vim.api.nvim_create_user_command('DartOrganizeImports', require('tms.ft.dart.lsp').organize_imports, cmd_opts)
-vim.api.nvim_create_user_command('DartFixAll', require('tms.ft.dart.lsp').fix_all, cmd_opts)
-vim.api.nvim_create_user_command('DartExtract', require('tms.ft.dart.lsp').extract_method, cmd_opts)
-vim.api.nvim_create_user_command('DartVariable', require('tms.ft.dart.lsp').extract_local_variable, cmd_opts)
+vim.api.nvim_create_user_command('DartDebug', ddebug.func, cmd_opts)
+vim.api.nvim_create_user_command('DartPrint', ddebug.print, cmd_opts)
+vim.api.nvim_create_user_command('DartOrganizeImports', dlsp.organize_imports, cmd_opts)
+vim.api.nvim_create_user_command('DartFixAll', dlsp.fix_all, cmd_opts)
+vim.api.nvim_create_user_command('DartExtract', dlsp.extract_method, cmd_opts)
+vim.api.nvim_create_user_command('DartVariable', dlsp.extract_local_variable, cmd_opts)
local opts = function(desc) return { buffer = true, noremap = true, desc = desc } end
-vim.keymap.set('n', '<leader>pp', function() require('tms.ft.dart.debug').print() end, opts('Dart Debug Print'))
-vim.keymap.set('n', '<leader>pa', function() require('tms.ft.dart.analyze').qf2131() end, opts('Dart Analyze'))
-vim.keymap.set('n', '<leader>po', function() require('tms.ft.dart.lsp').organize_imports() end,
- opts('Dart Organize Imports'))
-vim.keymap.set('n', '<leader>pf', function() require('tms.ft.dart.lsp').fix_all() end, opts('Dart Fix All'))
-vim.keymap.set({ 'v', 'n' }, '<leader>pi', function() require('tms.ft.dart.lsp').inline_local_variable() end,
- opts('Dart Inline Local Varibale'))
-vim.keymap.set({ 'v', 'n' }, '<leader>pe', function() require('tms.ft.dart.lsp').extract_local_variable() end,
- opts('Dart Extract Local Varibale'))
-vim.keymap.set({ 'v', 'n' }, '<leader>pm', function() require('tms.ft.dart.lsp').extract_method() end,
- opts('Dart Extract Method'))
+vim.keymap.set('n', '<leader>pp', function() ddebug.print() end, opts('Dart Debug Print'))
+vim.keymap.set('n', '<leader>pn', function() analyze.qf2131() end, opts('Dart Analyze'))
+vim.keymap.set('n', '<leader>po', dlsp.organize_imports, opts('Dart Organize Imports'))
+vim.keymap.set('n', '<leader>pf', function() dlsp.fix_all() end, opts('Dart Fix All'))
+vim.keymap.set({ 'v', 'n' }, '<leader>pi', dlsp.inline_local_variable, opts('Dart Inline Local Varibale'))
+vim.keymap.set({ 'v', 'n' }, '<leader>pe', dlsp.extract_local_variable, opts('Dart Extract Local Varibale'))
+vim.keymap.set({ 'v', 'n' }, '<leader>pm', dlsp.extract_method, opts('Dart Extract Method'))
+vim.keymap.set('n', '<leader>pl', dlsp.list_code_action_kinds, opts('Dart List Code Actions'))
+vim.keymap.set('n', '<leader>ps', function() dlsp.execute_code_action('refactor.splitVariableDeclaration') end, opts('Dart Split Variable Declaration'))
+vim.keymap.set('n', '<leader>pj', function() dlsp.execute_code_action('refactor.joinVariableDeclaration') end, opts('Dart Join Variable Declaration'))
+vim.keymap.set('n', '<leader>px', function() dlsp.execute_code_action('refactor.convert.bodyToExpression') end, opts('Dart Convert To Expression'))
+vim.keymap.set('n', '<leader>pa', function() dlsp.execute_code_action('refactor.convert.bodyToAsync') end, opts('Dart Convert To Async'))
+vim.keymap.set('n', '<leader>pb', function() dlsp.execute_code_action('refactor.convert.bodyToBlock') end, opts('Dart Convert To Block'))
if vim.fn.getline(1):match('^#!.*dcli') then
vim.cmd [[comp dcli]]
else
vim.cmd [[comp dart]]
end
+
+require('lsp-format').disabled_filetypes.dart = true
diff --git a/ftplugin/gitcommit.lua b/ftplugin/gitcommit.lua
@@ -1,8 +1,10 @@
require('cmp').setup.buffer {
sources = {
--
- {name = 'glab_dpgw'},
- {name = 'path'},
- {name = 'buffer', keyword_length = 5},
+ { name = 'glab_dpgw' },
+ { name = 'path' },
+ { name = 'buffer', keyword_length = 5 },
},
}
+
+vim.cmd([[startinsert]])
diff --git a/ftplugin/go.lua b/ftplugin/go.lua
@@ -1,2 +1,4 @@
vim.cmd [[comp go]]
vim.cmd [[command! -buffer -nargs=? Godoc lua require('tms.ft.go.doc').godoc(vim.fn.expand('<args>'), vim.fn.expand('<cword>'))]]
+
+vim.api.nvim_create_autocmd('BufWritePre', { callback = function() require('tms.ft.go').org_imports() end, buffer = 0, desc = "GO Organize Imports" })
diff --git a/lua/tms/first_load.lua b/lua/tms/first_load.lua
@@ -1,16 +1,14 @@
local install_path = vim.fn.stdpath('data') .. '/site/pack/packer'
-
-local packer_path = install_path .. '/opt/packer.nvim'
-if vim.fn.empty(vim.fn.glob(packer_path)) > 0 then
- vim.api.nvim_command('!git clone --depth=1 https://github.com/wbthomason/packer.nvim ' .. packer_path)
+local name = function(repo) return string.match(repo, '%w+/(.*)') end
+local clone = function(repo, path)
+ vim.api.nvim_command(string.format('!git clone --depth=1 https://github.com/%s %s', repo, path))
end
+local install = function(repo, path) if vim.fn.isdirectory(path) == 0 then clone(repo, path) end end
+local opt = function(repo) install(repo, string.format('%s/opt/%s', install_path, name(repo))) end
+local start = function(repo) install(repo, string.format('%s/start/%s', install_path, name(repo))) end
-local impatient_path = install_path .. '/start/impatient.nvim'
-if vim.fn.empty(vim.fn.glob(impatient_path)) > 0 then
- vim.api.nvim_command('!git clone --depth=1 https://github.com/lewis6991/impatient.nvim ' .. impatient_path)
-end
-local colorbuddy_path = install_path .. '/start/colorbuddy.nvim'
-if vim.fn.empty(vim.fn.glob(colorbuddy_path)) > 0 then
- vim.api.nvim_command('!git clone --depth=1 https://github.com/tjdevries/colorbuddy.nvim ' .. colorbuddy_path)
-end
+opt('wbthomason/packer.nvim')
+start('lewis6991/impatient.nvim')
+start('tjdevries/colorbuddy.nvim')
+start('tjdevries/lsp-format.nvim')
diff --git a/lua/tms/ft/dart/lsp.lua b/lua/tms/ft/dart/lsp.lua
@@ -1,15 +1,5 @@
local M = {}
-local get_visual_lines = function()
- local vs_start_line = vim.fn.getcurpos()[2]
- local vs_end_line = vim.fn.line('v')
- if vs_start_line > vs_end_line then
- return vs_end_line - 1, vs_start_line - 1
- else
- return vs_start_line - 1, vs_end_line - 1
- end
-end
-
local get_visual = function()
local curpos = vim.fn.getcurpos()
local one = { row = curpos[2] - 1, col = curpos[3] - 1 }
@@ -32,6 +22,43 @@ local get_visual = function()
return { start = one, ['end'] = two }
end
+local make_code_action_params = function()
+ local params = vim.lsp.util.make_range_params()
+ params.context = {
+ diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
+ }
+ return params
+end
+
+local list_code_action_kinds = function()
+ local params = make_code_action_params()
+ local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
+ for _, res in pairs(result or {}) do
+ print('---', 'CODE ACTIONS')
+ for _, r in pairs(res.result or {}) do
+ -- vim.pretty_print(r)
+ print(r.kind)
+ end
+ print('---')
+ end
+end
+
+local execute_code_action = function(kind)
+ if not kind then return end
+ local params = make_code_action_params()
+ params.context.only = { kind }
+ local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
+ for _, res in pairs(result or {}) do
+ for _, r in pairs(res.result or {}) do
+ if r.edit then
+ vim.lsp.util.apply_workspace_edit(r.edit, 'utf-8')
+ else
+ vim.lsp.buf.execute_command(r.command)
+ end
+ end
+ end
+end
+
-- TODO(tms) 22.04.22: possible bug that does not count new lines
local get_offest_length = function(buf, mode)
local vs = get_visual()
@@ -97,5 +124,7 @@ M.fix_all = function() execute_simple_command('edit.fixAll') end
M.extract_method = function() execute_command('EXTRACT_METHOD') end
M.extract_local_variable = function() execute_command('EXTRACT_LOCAL_VARIABLE') end
M.inline_local_variable = function() execute_command_no_input('INLINE_LOCAL_VARIABLE') end
+M.list_code_action_kinds = list_code_action_kinds
+M.execute_code_action = function(kind) execute_code_action(kind) end
return M
diff --git a/lua/tms/ft/go/init.lua b/lua/tms/ft/go/init.lua
@@ -0,0 +1,19 @@
+local M = {}
+
+M.org_imports = function()
+ ---@diagnostic disable-next-line: missing-parameter
+ local params = vim.lsp.util.make_range_params()
+ params.context = { only = { "source.organizeImports" } }
+ local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
+ for _, res in pairs(result or {}) do
+ for _, r in pairs(res.result or {}) do
+ if r.edit then
+ vim.lsp.util.apply_workspace_edit(r.edit, 'utf-8')
+ else
+ vim.lsp.buf.execute_command(r.command)
+ end
+ end
+ end
+end
+
+return M
diff --git a/lua/tms/lsp/init.lua b/lua/tms/lsp/init.lua
@@ -1,52 +1,31 @@
local servers = require('tms.lsp.servers')
+local format = require('lsp-format')
local on_attach = function(client, bufnr)
local lsp = vim.lsp
- local hh = lsp.with(lsp.handlers.hover, { border = 'single' })
- lsp.handlers['textDocument/hover'] = hh
+ lsp.handlers['textDocument/hover'] = lsp.with(lsp.handlers.hover, { border = 'single' })
+ lsp.handlers['textDocument/signatureHelp'] = lsp.with(lsp.handlers.signature_help, { border = 'single' })
+ vim.api.nvim_buf_set_option(bufnr, 'tagfunc', 'v:lua.vim.lsp.tagfunc')
+ vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr()')
- local sh = lsp.with(lsp.handlers.signature_help, { border = 'single' })
- lsp.handlers['textDocument/signatureHelp'] = sh
- if client.resolved_capabilities.goto_definition then
- vim.api.nvim_buf_set_option(bufnr, 'tagfunc', 'v:lua.vim.lsp.tagfunc')
- end
- -- if client.resolved_capabilities.document_formatting then
- -- vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr()')
- -- end
-
- vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { silent = true, buffer = bufnr, desc = 'LSP Definition' })
- vim.keymap.set('n', 'gD', '<cmd>vsplit | lua vim.lsp.buf.definition()<cr>',
- { silent = true, buffer = bufnr, desc = 'LSP definition in vsplit' })
- vim.keymap
- .set('n', 'gT', vim.lsp.buf.type_definition, { silent = true, buffer = bufnr, desc = 'LSP Type Definition' })
- vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { silent = true, buffer = bufnr, desc = 'LSP Implementation' })
- vim.keymap.set('n', 'K', vim.lsp.buf.hover, { silent = true, buffer = bufnr, desc = 'LSP Hover' })
- vim.keymap.set('n', '<c-p>', vim.lsp.buf.signature_help,
- { silent = true, buffer = bufnr, desc = 'LSP Signature Help' })
- vim.keymap.set('i', '<c-p>', vim.lsp.buf.signature_help,
- { silent = true, buffer = bufnr, desc = 'LSP Signature Help' })
- vim.keymap.set('n', 'gr', vim.lsp.buf.references, { silent = true, buffer = bufnr, desc = 'LSP References' })
- vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, { silent = true, buffer = bufnr, desc = 'LSP Code Actions' })
- vim.keymap.set('v', 'ga', vim.lsp.buf.range_code_action, { silent = true, buffer = bufnr, desc = 'LSP Code Actions' })
- vim.keymap.set('n', 'gn', vim.lsp.buf.rename, { silent = true, buffer = bufnr, desc = 'LSP Rename' })
+ local opts = function(desc) return { silent = true, buffer = bufnr, desc = desc } end
+ vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts('LSP Definition'))
+ vim.keymap.set('n', 'gD', '<cmd>vsplit | lua vim.lsp.buf.definition()<cr>', opts('LSP definition in vsplit'))
+ vim.keymap.set('n', 'gT', vim.lsp.buf.type_definition, opts('LSP Type Definition'))
+ vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts('LSP Implementation'))
+ vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts('LSP Hover'))
+ vim.keymap.set('n', '<c-p>', vim.lsp.buf.signature_help, opts('LSP Signature Help'))
+ vim.keymap.set('i', '<c-p>', vim.lsp.buf.signature_help, opts('LSP Signature Help'))
+ vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts('LSP References'))
+ vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, opts('LSP Code Actions'))
+ vim.keymap.set('v', 'ga', vim.lsp.buf.range_code_action, opts('LSP Code Actions'))
+ vim.keymap.set('n', 'gn', vim.lsp.buf.rename, opts('LSP Rename'))
- -- formatting
- -- TODO(tms) 11.04.22
- local excluded = { tsserver = true, sumneko_lua = true }
- if not excluded[client.name] then
- vim.keymap.set('n', 'Q', vim.lsp.buf.formatting, { silent = true, buffer = bufnr, desc = 'LSP Format' })
- vim.keymap.set('v', 'Q', vim.lsp.buf.range_formatting, { silent = true, buffer = bufnr, desc = 'LSP Range Format' })
- else
- client.resolved_capabilities.document_formatting = false
- client.resolved_capabilities.range_formatting = false
- end
+ vim.keymap.set('n', 'Q', vim.lsp.buf.formatting, opts('LSP Format'))
+ vim.keymap.set('v', 'Q', ':<c-u>lua vim.lsp.buf.range_formatting()<cr>', opts('LSP Range Format'))
- -- symbols
- local t = require('tms.p.telescope')
- vim.keymap.set('n', 'gm', t.lsp_document_symbols, { silent = true, buffer = bufnr, desc = 'LSP Document Symbols' })
- vim.keymap.set('n', 'gM', t.lsp_dynamic_workspace_symbols,
- { silent = true, buffer = bufnr, desc = 'LSP Workspace Symbols' })
+ format.on_attach(client)
local has_aerial, aerial = pcall(require, 'aerial')
if has_aerial then aerial.on_attach(client, bufnr) end
@@ -61,7 +40,7 @@ local capabilities = function()
end
end
-local server_opts = function(name, server)
+local make_opts = function(name, server)
local opts = {}
opts.on_attach = on_attach
opts.capabilities = capabilities()
@@ -70,13 +49,15 @@ local server_opts = function(name, server)
end
local setup = function()
+
+ format.setup()
+
-- LSP Installer
local has_lspi, lsp_installer = pcall(require, 'nvim-lsp-installer')
if has_lspi then
lsp_installer.on_server_ready(function(server)
- local opts = server_opts(server.name, server)
+ local opts = make_opts(server.name, server)
server:setup(opts)
- vim.cmd [[ do User LspAttachBuffers ]]
end)
end
@@ -85,14 +66,14 @@ local setup = function()
if has_lspc then
local manual_servers = { 'gdscript', 'dartls' }
for _, name in ipairs(manual_servers) do
- local opts = server_opts(name)
+ local opts = make_opts(name)
lsp_config[name].setup(opts)
end
end
-- Manual
local has_zk, zk = pcall(require, 'zk')
- if has_zk then zk.setup({ lsp = { config = server_opts('zk') } }) end
+ if has_zk then zk.setup({ lsp = { config = make_opts('zk') } }) end
end
-return { setup = setup, server_opts = server_opts }
+return { on_attach = on_attach, setup = setup }
diff --git a/lua/tms/lsp/servers.lua b/lua/tms/lsp/servers.lua
@@ -60,7 +60,7 @@ M.emmet_ls = function(opts)
end
M.gopls = function(opts)
- opts.root_dir = require('lspconfig').util.root_pattern('go.mod', '.git', vim.fn.getcwd())
+ opts.root_dir = require('lspconfig').util.root_pattern('go.work', 'go.mod', '.git', vim.fn.getcwd())
return opts
end
diff --git a/lua/tms/plugins.lua b/lua/tms/plugins.lua
@@ -106,6 +106,7 @@ return packer.startup({
use 'folke/lua-dev.nvim'
use { 'jose-elias-alvarez/null-ls.nvim', requires = { 'nvim-lua/plenary.nvim' } }
use 'stevearc/aerial.nvim'
+ use 'lukas-reineke/lsp-format.nvim'
-- dap
use 'mfussenegger/nvim-dap'
diff --git a/test/dart.dart b/test/dart.dart
@@ -1,6 +1,11 @@
-Class Test {
+class Test {
Test() {
var object = 2 + 2;
print(object);
}
+
+ void b() {}
+ void a() {}
}
+
+var a = Test();
diff --git a/test/dart.lua b/test/dart.lua
@@ -25,8 +25,45 @@ local extract = function()
end)
end
-vim.keymap.set('n', ',e', extract)
-vim.keymap.set('v', ',e', extract)
+local make_code_action_params = function()
+ local params = vim.lsp.util.make_range_params()
+ params.context = {
+ diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
+ }
+ return params
+end
+
+local list_code_action_kinds = function()
+ local params = make_code_action_params()
+ local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
+ for _, res in pairs(result or {}) do
+ print('---', 'CODE ACTIONS')
+ for _, r in pairs(res.result or {}) do
+ -- vim.pretty_print(r)
+ print(r.kind)
+ end
+ print('---')
+ end
+end
+
+local execute_code_action = function(kind)
+ if not kind then return end
+ local params = make_code_action_params()
+ params.context.only = { kind }
+ local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
+ for _, res in pairs(result or {}) do
+ for _, r in pairs(res.result or {}) do
+ if r.edit then
+ vim.lsp.util.apply_workspace_edit(r.edit, 'utf-8')
+ else
+ vim.lsp.buf.execute_command(r.command)
+ end
+ end
+ end
+end
+
+vim.keymap.set('n', ',e', function() execute_code_action('refactor.remove.typeAnnotation') end)
+vim.keymap.set('n', ',l', list_code_action_kinds)
-vim.cmd [[messages clear]]
print('loaded')
+vim.cmd [[messages clear]]