diff --git a/jrpotter/lang/typescript.nix b/jrpotter/lang/typescript.nix index 810bf4a..0abe968 100644 --- a/jrpotter/lang/typescript.nix +++ b/jrpotter/lang/typescript.nix @@ -1,12 +1,21 @@ { pkgs, ... }: { home.packages = with pkgs; [ + nodePackages.prettier nodePackages.typescript-language-server ]; programs.neovim = { 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', "PrettierAsync", { + silent = true, + }) + end, + } ''; }; } diff --git a/jrpotter/neovim/default.nix b/jrpotter/neovim/default.nix index e8ecfd1..e119d7d 100644 --- a/jrpotter/neovim/default.nix +++ b/jrpotter/neovim/default.nix @@ -40,7 +40,7 @@ let "mfussenegger/nvim-dap"; config = '' 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.luasnip pkgs.vimPlugins.nvim-web-devicons + pkgs.vimPlugins.vim-prettier ]; viAlias = true; vimAlias = true; diff --git a/jrpotter/neovim/lua/init/lsp.lua b/jrpotter/neovim/lua/init/lsp.lua index 3009ee0..e5342ab 100644 --- a/jrpotter/neovim/lua/init/lsp.lua +++ b/jrpotter/neovim/lua/init/lsp.lua @@ -1,6 +1,6 @@ local M = {} -local function on_attach(client, bufnr) +function M.on_attach(client, bufnr) local function set_nnoremap(key, func) vim.keymap.set('n', key, func, { buffer = bufnr }) end @@ -12,14 +12,14 @@ local function on_attach(client, bufnr) set_nnoremap('gr', vim.lsp.buf.rename) end -local capabilities = require('cmp_nvim_lsp').default_capabilities() +M.capabilities = require('cmp_nvim_lsp').default_capabilities() function M.setup(client) -- Return a nested function so that we can continue invoking `setup` in the -- familiar way. return function(opts) - opts.on_attach = opts.on_attach or on_attach - opts.cabailities = opts.cabailities or capabilities + opts.on_attach = opts.on_attach or M.on_attach + opts.cabailities = opts.cabailities or M.capabilities client.setup(opts) end end