Skip to content

Commit

Permalink
languages/ts: update lspconfig; rename tsserver to ts_ls (NotAShelf#379)
Browse files Browse the repository at this point in the history
Silence lspconfig, Microsoft naming convention is speaking.
  • Loading branch information
NotAShelf authored Sep 24, 2024
1 parent b2b176b commit 4ba16f1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 44 additions & 3 deletions modules/plugins/languages/ts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

cfg = config.vim.languages.ts;

defaultServer = "tsserver";
defaultServer = "ts_ls";
servers = {
tsserver = {
ts_ls = {
package = pkgs.typescript-language-server;
lspConfig = ''
lspconfig.tsserver.setup {
lspconfig.ts_ls.setup {
capabilities = capabilities;
on_attach = attach_keymaps,
cmd = ${
Expand All @@ -49,6 +49,24 @@
}
'';
};

# Here for backwards compatibility. Still consider tsserver a valid
# configuration in the enum, but assert if it's set to *properly*
# redirect the user to the correct server.
tsserver = {
package = pkgs.typescript-language-server;
lspConfig = ''
lspconfig.ts_ls.setup {
capabilities = capabilities;
on_attach = attach_keymaps,
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/typescript-language-server", "--stdio"}''
}
}
'';
};
};

# TODO: specify packages
Expand All @@ -65,6 +83,7 @@
)
'';
};

prettierd = {
package = pkgs.prettierd;
nullConfig = ''
Expand Down Expand Up @@ -94,6 +113,7 @@
};
};
in {
_file = ./ts.nix;
options.vim.languages.ts = {
enable = mkEnableOption "Typescript/Javascript language support";

Expand Down Expand Up @@ -190,11 +210,32 @@ in {
};
})

# Extensions
(mkIf cfg.extensions."ts-error-translator".enable {
vim.startPlugins = ["ts-error-translator"];
vim.pluginRC.ts-error-translator = entryAnywhere ''
require("ts-error-translator").setup(${toLuaObject cfg.extensions.ts-error-translator.setupOpts})
'';
})

# Warn the user if they have set the default server name to tsserver to match upstream (us)
# The name "tsserver" has been deprecated in lspconfig, and now should be called ts_ls. This
# is a purely cosmetic change, but emits a warning if not accounted for.
{
assertions = [
{
assertion = cfg.lsp.enable -> cfg.lsp.server != "tsserver";
message = ''
As of a recent lspconfig update, he `tsserver` configuration has been renamed
to `ts_ls` to match upstream behaviour of `lspconfig`, and the name `tsserver`
is no longer considered valid by nvf. Please set `vim.languages.ts.lsp.server`
to `"ts_ls"` instead of to `${cfg.lsp.server}`
Please see <https://github.com/neovim/nvim-lspconfig/pull/3232> for more details
about this change.
'';
}
];
}
]);
}

0 comments on commit 4ba16f1

Please sign in to comment.