Add prettier formatting to tsserver-attached buffers.
parent
8947e1d2b9
commit
1055847812
|
@ -1,12 +1,21 @@
|
||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
{
|
{
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
|
nodePackages.prettier
|
||||||
nodePackages.typescript-language-server
|
nodePackages.typescript-language-server
|
||||||
];
|
];
|
||||||
|
|
||||||
programs.neovim = {
|
programs.neovim = {
|
||||||
nvim-lspconfig = ''
|
nvim-lspconfig = ''
|
||||||
require('init.lsp').setup(require('lspconfig').tsserver) {}
|
require('init.lsp').setup(require('lspconfig').tsserver) {
|
||||||
|
on_attach = function(client, bufnr)
|
||||||
|
require('init.lsp').on_attach(client, bufnr)
|
||||||
|
-- Override the default formatter in typescript-language-server.
|
||||||
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', "<CMD>PrettierAsync<CR>", {
|
||||||
|
silent = true,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ let
|
||||||
"mfussenegger/nvim-dap";
|
"mfussenegger/nvim-dap";
|
||||||
config = ''
|
config = ''
|
||||||
require('dap').defaults.fallback.terminal_win_cmd = 'below 10split new'
|
require('dap').defaults.fallback.terminal_win_cmd = 'below 10split new'
|
||||||
${config.programs.neovim.nvim-dap};
|
${config.programs.neovim.nvim-dap}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ in
|
||||||
pkgs.vimPlugins.cmp_luasnip
|
pkgs.vimPlugins.cmp_luasnip
|
||||||
pkgs.vimPlugins.luasnip
|
pkgs.vimPlugins.luasnip
|
||||||
pkgs.vimPlugins.nvim-web-devicons
|
pkgs.vimPlugins.nvim-web-devicons
|
||||||
|
pkgs.vimPlugins.vim-prettier
|
||||||
];
|
];
|
||||||
viAlias = true;
|
viAlias = true;
|
||||||
vimAlias = true;
|
vimAlias = true;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function on_attach(client, bufnr)
|
function M.on_attach(client, bufnr)
|
||||||
local function set_nnoremap(key, func)
|
local function set_nnoremap(key, func)
|
||||||
vim.keymap.set('n', key, func, { buffer = bufnr })
|
vim.keymap.set('n', key, func, { buffer = bufnr })
|
||||||
end
|
end
|
||||||
|
@ -12,14 +12,14 @@ local function on_attach(client, bufnr)
|
||||||
set_nnoremap('gr', vim.lsp.buf.rename)
|
set_nnoremap('gr', vim.lsp.buf.rename)
|
||||||
end
|
end
|
||||||
|
|
||||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
M.capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||||
|
|
||||||
function M.setup(client)
|
function M.setup(client)
|
||||||
-- Return a nested function so that we can continue invoking `setup` in the
|
-- Return a nested function so that we can continue invoking `setup` in the
|
||||||
-- familiar way.
|
-- familiar way.
|
||||||
return function(opts)
|
return function(opts)
|
||||||
opts.on_attach = opts.on_attach or on_attach
|
opts.on_attach = opts.on_attach or M.on_attach
|
||||||
opts.cabailities = opts.cabailities or capabilities
|
opts.cabailities = opts.cabailities or M.capabilities
|
||||||
client.setup(opts)
|
client.setup(opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue