neovim

Personal neovim configuration files
git clone git://gtms.dev/neovim
Log | Files | Refs

commit 95118f3896ae8bf7ccc4f9abe16f98319bb976a5
parent 5725c92688609d148a35e1aa3e0760f2342072c2
Author: Tomas Nemec <owl@gtms.dev>
Date:   Mon, 29 Apr 2024 12:36:34 +0200

update

Diffstat:
Mafter/plugin/format.lua | 75++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Mafter/plugin/lsp.lua | 51+++++++++++++++++++++++++++------------------------
Mafter/plugin/ng_html.lua | 4++--
Mplugin/diagnostic.lua | 68++++++++++++++++++++++++++++++++++----------------------------------
4 files changed, 111 insertions(+), 87 deletions(-)

diff --git a/after/plugin/format.lua b/after/plugin/format.lua @@ -2,37 +2,58 @@ if not pcall(require, 'conform') then return end -local prettier = { { --[[ 'prettierd', ]] 'prettier' } } --- local util = require 'conform.util' +local prettier = { 'prettier' } +local shfmt = { 'shfmt' } require 'conform'.setup { - formatters_by_ft = { sh = { 'shfmt' }, bash = { 'shfmt' }, zsh = { 'shfmt' }, yaml = prettier, html = prettier, css = prettier, graphql = prettier, scss = prettier }, - formatters = { - shfmt = {}, - prettier = { - prepend_args = { - '--plugin=/home/tms/.local/share/npm/lib/node_modules/prettier-plugin-organize-attributes/lib/index.js', - }, - }, - -- prettierd = { - -- args = { - -- '$FILENAME', - -- '--plugin=/home/tms/.local/share/npm/lib/node_modules/prettier-plugin-organize-attributes/lib/index.js', - -- }, - -- range_args = function(_, ctx) - -- local start_offset, end_offset = util.get_offsets_from_range(ctx.buf, ctx.range) - -- return { - -- '$FILENAME', - -- '--range-start=' .. start_offset, - -- '--range-end=' .. end_offset, - -- '--plugin=/home/tms/.local/share/npm/lib/node_modules/prettier-plugin-organize-attributes/lib/index.js', - -- } - -- end, - -- }, + formatters_by_ft = { + dart = { 'injected' }, + sh = shfmt, + bash = shfmt, + zsh = shfmt, + yaml = prettier, + html = prettier, + css = prettier, + graphql = prettier, + scss = prettier, }, } -vim.o.formatexpr = 'v:lua.require"conform".formatexpr()' +vim.o.formatexpr = "v:lua.require'conform'.formatexpr({'lsp_fallback': 'always'})" + +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*", + callback = function(args) + -- Disable with a global or buffer-local variable + if vim.g.disable_autoformat or vim.b[args.buf].disable_autoformat then + return + end + require("conform").format({ bufnr = args.buf, lsp_fallback = "always", timeout_ms = 500 }) + end, +}) vim.keymap.set('n', 'gQ', function() - require 'conform'.format { lsp_fallback = true } + require 'conform'.format { lsp_fallback = "always" } end, { desc = 'Format' }) + +vim.api.nvim_create_user_command("Format", function() + require 'conform'.format { lsp_fallback = "always" } +end, { desc = "Format" }) + +vim.api.nvim_create_user_command("FormatDisable", function(args) + if args.bang then + -- FormatDisable! will disable formatting just for this buffer + vim.b.disable_autoformat = true + else + vim.g.disable_autoformat = true + end +end, { + desc = "Disable autoformat-on-save", + bang = true, +}) + +vim.api.nvim_create_user_command("FormatEnable", function() + vim.b.disable_autoformat = false + vim.g.disable_autoformat = false +end, { + desc = "Re-enable autoformat-on-save", +}) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua @@ -12,28 +12,31 @@ local function keymap(client, buf) -- client.server_capabilities.semanticTokensProvider = nil - if client.supports_method('textDocument/definition') then - vim.keymap.set('n', 'gd', lb.definition, opt 'LSP Definition') - vim.keymap.set('n', 'gD', '<cmd>vsplit | lua vim.lsp.buf.definition()<cr>', opt('LSP definition in vsplit')) - end + -- if client.supports_method('textDocument/definition') then + -- vim.keymap.set('n', 'gd', lb.definition, opt 'LSP Definition') + -- vim.keymap.set('n', 'gD', '<cmd>vsplit | lua vim.lsp.buf.definition()<cr>', opt('LSP definition in vsplit')) + -- end -- collision with previous tab `gT` -- if cap.typeDefinitionProvider then -- vim.keymap.set('n', 'gT', lb.type_definition, opt('LSP Type Definition')) -- end if client.supports_method('textDocument/implementation') then - vim.keymap.set('n', 'gm', lb.implementation, opt('LSP Implementation')) + vim.keymap.set('n', 'cri', lb.implementation, opt('LSP Implementation')) + vim.keymap.set('i', '<c-w><c-m>', function() + vim.cmd.split() + lb.implementation() + end, opt('LSP Implementation')) end if client.supports_method('textDocument/signatureHelp') then - -- TODO(tms) 29.06.23: - -- vim.keymap.set('n', '<c-p>', lb.signature_help, opt('LSP Signature Help')) -- vim.keymap.set('i', '<c-p>', lb.signature_help, opt('LSP Signature Help')) + vim.keymap.set('n', '<c-s>', lb.signature_help, opt('LSP Signature Help')) end - if client.supports_method('textDocument/references') then - vim.keymap.set('n', 'gr', lb.references, opt('LSP References')) - end - if client.supports_method('textDocument/codeAction') then - vim.keymap.set({ 'n', 'v' }, 'ga', lb.code_action, opt('LSP Code Actions')) - end + -- if client.supports_method('textDocument/references') then + -- vim.keymap.set('n', 'gr', lb.references, opt('LSP References')) + -- end + -- if client.supports_method('textDocument/codeAction') then + -- vim.keymap.set({ 'n', 'v' }, 'ga', lb.code_action, opt('LSP Code Actions')) + -- end if client.supports_method('textDocument/documentHighlight') then vim.keymap.set('n', '<leader>k', lb.document_highlight, opt('LSP Highlight')) vim.api.nvim_create_autocmd('CursorMoved', @@ -44,9 +47,9 @@ local function keymap(client, buf) vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled(0)) end, opt('LSP Inlay hints')) end - if client.supports_method('textDocument/rename') then - vim.keymap.set('n', 'cd', lb.rename, opt('LSP Rename (change definition)')) - end + -- if client.supports_method('textDocument/rename') thenga + -- vim.keymap.set('n', 'cd', lb.rename, opt('LSP Rename (change definition)')) + -- end if client.supports_method('textDocument/prepareTypeHierarchy') then vim.keymap.set('n', 'gh', function() require('tms.lsp.request').type_hierarchy('subtypes') @@ -56,15 +59,15 @@ local function keymap(client, buf) end, opt('LSP Supertypes')) end - if client.supports_method('textDocument/formatting') then - -- vim.keymap.set('n', 'gQ', function() - -- vim.lsp.buf.format() + -- if client.supports_method('textDocument/formatting') then + -- vim.keymap.set('n', 'gQ', function() + -- vim.lsp.buf.format() - -- -- if vim.api.nvim_get_option_value('ft', { buf = buf }) == 'dart' then - -- -- vim.cmd.NgHtmlFormat() - -- -- end - -- end, { buffer = buf, desc = 'LSP Format' }) - end + -- -- if vim.api.nvim_get_option_value('ft', { buf = buf }) == 'dart' then + -- -- vim.cmd.NgHtmlFormat() + -- -- end + -- end, { buffer = buf, desc = 'LSP Format' }) + -- end end vim.api.nvim_create_autocmd('LspAttach', { diff --git a/after/plugin/ng_html.lua b/after/plugin/ng_html.lua @@ -65,5 +65,5 @@ end vim.api.nvim_create_user_command('NgHtmlFormat', format_ng_html, {}) -local group = vim.api.nvim_create_augroup('ng-html-format', {}) -vim.api.nvim_create_autocmd('BufWritePre', { group = group, pattern = '*.dart', callback = format_ng_html }) +-- local group = vim.api.nvim_create_augroup('ng-html-format', {}) +-- vim.api.nvim_create_autocmd('BufWritePre', { group = group, pattern = '*.dart', callback = format_ng_html }) diff --git a/plugin/diagnostic.lua b/plugin/diagnostic.lua @@ -1,38 +1,38 @@ vim.diagnostic.config({ virtual_text = false, underline = false, float = { border = 'single' }, severity_sort = true }) -local d = { - next = function() - vim.diagnostic.goto_next({ float = false }) - end, - prev = function() - vim.diagnostic.goto_prev({ float = false }) - end, - open = function() - vim.diagnostic.open_float() - end, - open_cursor = function() - vim.diagnostic.open_float({ scope = 'cursor' }) - end, - ll = function() - vim.diagnostic.setloclist() - end, - ql = function() - vim.diagnostic.setqflist() - end, - ql_error = function() - vim.diagnostic.setqflist({ severity = vim.diagnostic.severity.ERROR }) - end, -} +-- local d = { +-- next = function() +-- vim.diagnostic.goto_next({ float = false }) +-- end, +-- prev = function() +-- vim.diagnostic.goto_prev({ float = false }) +-- end, +-- open = function() +-- vim.diagnostic.open_float() +-- end, +-- open_cursor = function() +-- vim.diagnostic.open_float({ scope = 'cursor' }) +-- end, +-- ll = function() +-- vim.diagnostic.setloclist() +-- end, +-- ql = function() +-- vim.diagnostic.setqflist() +-- end, +-- ql_error = function() +-- vim.diagnostic.setqflist({ severity = vim.diagnostic.severity.ERROR }) +-- end, +-- } -local o = function(desc) - return { desc = desc, silent = true } -end +-- local o = function(desc) +-- return { desc = desc, silent = true } +-- end -vim.keymap.set('n', 'gww', d.open, o('Diagnostic Open for Line')) -vim.keymap.set('n', 'gw.', d.open, o('Diagnostic Open for Line')) -vim.keymap.set('n', 'gwc', d.open_cursor, o('Diagnostic Open for Cursor')) -vim.keymap.set('n', 'gwl', d.ll, o('Diagnostic to Location List')) -vim.keymap.set('n', 'gwq', d.ql_error, o('Diagnostic of Error to Quickfix List')) -vim.keymap.set('n', 'gwQ', d.ql, o('Diagnostic to Quickfix List')) -vim.keymap.set('n', '<c-l><c-d>', d.next, o('Diagnostic Next')) -vim.keymap.set('n', '<c-h><c-d>', d.prev, o('Diagnostic Previous')) +-- vim.keymap.set('n', 'gww', d.open, o('Diagnostic Open for Line')) +-- vim.keymap.set('n', 'gw.', d.open, o('Diagnostic Open for Line')) +-- vim.keymap.set('n', 'gwc', d.open_cursor, o('Diagnostic Open for Cursor')) +-- vim.keymap.set('n', 'gwl', d.ll, o('Diagnostic to Location List')) +-- vim.keymap.set('n', 'gwq', d.ql_error, o('Diagnostic of Error to Quickfix List')) +-- vim.keymap.set('n', 'gwQ', d.ql, o('Diagnostic to Quickfix List')) +-- vim.keymap.set('n', '<c-l><c-d>', d.next, o('Diagnostic Next')) +-- vim.keymap.set('n', '<c-h><c-d>', d.prev, o('Diagnostic Previous'))