neovim

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

commit b23689987b0284b4c379833758fc7af60dbe23d1
parent 4cf42804261f14172b65cbdc2d141dd6fe790ea8
Author: Tomas Nemec <nemi@skaut.cz>
Date:   Sat, 17 Sep 2022 12:07:37 +0200

dart ngformat

Diffstat:
Mafter/plugin/format.lua | 11++++++++++-
Mafter/plugin/ng_html.lua | 6++++--
2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/after/plugin/format.lua b/after/plugin/format.lua @@ -12,7 +12,16 @@ vim.api.nvim_create_autocmd('LspAttach', { vim.keymap.set('n', 'Q', function() local params = vim.lsp.util.make_formatting_params({}) - client.request('textDocument/formatting', params, nil, buf) + local rsp = client.request_sync('textDocument/formatting', params, nil, buf) + + if rsp.result then + vim.lsp.util.apply_text_edits(rsp.result, buf, 'utf-8') + end + + if vim.api.nvim_buf_get_option(buf, 'ft') == 'dart' then + vim.api.nvim_command('NgHtmlFormat') + end + end, { buffer = buf, desc = 'LSP Format' }) end diff --git a/after/plugin/ng_html.lua b/after/plugin/ng_html.lua @@ -47,9 +47,11 @@ local format_ng_html = function() local name = template_query.captures[id] if name == 'template' then local range = { node:range() } - local formatted = prettier_html(vim.treesitter.get_node_text(node, bufnr)) + if range[1] ~= range[3] then + local formatted = prettier_html(vim.treesitter.get_node_text(node, bufnr)) - table.insert(changes, 1, { start = range[1] + 1, final = range[3], formatted = formatted }) + table.insert(changes, 1, { start = range[1] + 1, final = range[3], formatted = formatted }) + end end end