浏览代码

nixpkgs/neovim: remove typescript.nvim

Thomas Dy 2 周之前
父节点
当前提交
c5e8939955

+ 71 - 23
.config/nixpkgs/neovim/lsp.lua

@@ -16,32 +16,80 @@ end
 if vim.fn.executable("deno") == 1 then
   vim.lsp.enable("deno");
 else
-  require('typescript').setup({
-    server = {
-      init_options = {
-        completionDisableFilterText = true,
-        preferences = {
-          importModuleSpecifierPreference = 'non-relative',
-          -- this prevents renames from aliasing when destructuring
-          providePrefixAndSuffixTextForRename = false,
-        },
+  vim.lsp.config("ts_ls", {
+    init_options = {
+      completionDisableFilterText = true,
+      preferences = {
+        importModuleSpecifierPreference = 'non-relative',
+        -- this prevents renames from aliasing when destructuring
+        providePrefixAndSuffixTextForRename = false,
       },
-      handlers = {
-        ['$/typescriptVersion'] = function(err, result, ctx, config)
-          vim.notify(string.format('Typescript %s', result.version))
+    },
+    handlers = {
+      ['$/typescriptVersion'] = function(err, result, ctx, config)
+        vim.notify(string.format('Typescript %s', result.version))
+      end
+    },
+    flags = {
+      debounce_text_changes = 150,
+    },
+    on_init = function(client)
+      -- mark tsserver as not having formatting available as we rely on
+      -- eslint and dprint for that
+      client.server_capabilities.documentFormattingProvider = false
+      client.server_capabilities.documentRangeFormattingProvider = false
+    end,
+    on_attach = function(client)
+      -- add custom commands, we follow upstream's Lsp* prefix convention
+
+      -- setup custom source actions, unlike code actions these apply to the
+      -- whole file rather than a particular line.
+      local function source_action(usercmd_name, command_name)
+        vim.api.nvim_buf_create_user_command(0, usercmd_name, function()
+          vim.lsp.buf.code_action({
+            context = { only = { command_name } },
+            apply = true,
+          })
+        end, {})
+      end
+
+      source_action("LspAddMissingImports", "source.addMissingImports.ts")
+      source_action("LspOrganizeImports", "source.organizeImports.ts")
+      source_action("LspRemoveUnusedImports", "source.removeUnusedImports.ts")
+
+      -- rename file with import renaming, this does no error checking
+      vim.api.nvim_buf_create_user_command(0, "LspRenameFile", function()
+        local source = vim.api.nvim_buf_get_name(0)
+
+        local function do_rename(target)
+          if target == nil then
+            return
+          end
+
+          -- rename the buffer
+          vim.lsp.util.rename(source, target)
+
+          -- ask LSP to rename imports
+          client:exec_cmd({
+            command = "_typescript.applyRenameFile",
+            arguments = {
+              {
+                sourceUri = vim.uri_from_fname(source),
+                targetUri = vim.uri_from_fname(target),
+              }
+            }
+          })
         end
-      },
-      flags = {
-        debounce_text_changes = 150,
-      },
-      on_init = function(client)
-        -- mark tsserver as not having formatting available as we rely on
-        -- eslint and dprint for that
-        client.server_capabilities.documentFormattingProvider = false
-        client.server_capabilities.documentRangeFormattingProvider = false
-      end,
-    }
+
+        vim.ui.input({
+          prompt = "New Filename: ",
+          completion = "file",
+          default = source,
+        }, do_rename)
+      end, {})
+    end,
   })
+  vim.lsp.enable("ts_ls")
 end
 
 if vim.fn.executable("gopls") == 1 then

+ 0 - 2
.config/nixpkgs/neovim/mappings.lua

@@ -107,8 +107,6 @@ vim.api.nvim_create_autocmd('LspAttach', {
     if client.name == 'ts_ls' then
       -- exclude import statements from reference search (may have false positives)
       vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references default_text=!import\\ <CR>', opts)
-      vim.keymap.set('n', 'gD', '<cmd>Telescope lsp_definitions<CR>', opts)
-      vim.keymap.set('n', 'gd', '<cmd>TypescriptGoToSourceDefinition<CR>', opts)
     end
   end,
 })

+ 0 - 4
.config/nixpkgs/neovim/plugins/default.nix

@@ -7,10 +7,6 @@ let
       dontBuild = false;
     };
 
-    "jose-elias-alvarez/typescript.nvim" = {
-      patches = [ ./typescript-nvim-tsserver.patch ];
-    };
-
     "nvim-treesitter/nvim-treesitter" = {
       # these extra rules causes nvim to crash when looking at a deeply nested
       # JSX expression

+ 0 - 4
.config/nixpkgs/neovim/plugins/sources.json

@@ -51,10 +51,6 @@
     "rev": "205e3369bc83d8cb83f7409c36120e24611f8c5c",
     "sha256": "13qmsnahlj88wxs75kvpn9hj89gnhm4dm6rb400ysrzmmx5ypg39"
   },
-  "jose-elias-alvarez/typescript.nvim": {
-    "rev": "4de85ef699d7e6010528dcfbddc2ed4c2c421467",
-    "sha256": "0rx29i3hmzh2knxx098fvfc0iafx3j08bs1zbv4dxadq56dnhaxm"
-  },
   "sainnhe/sonokai": {
     "rev": "f59c796780655c3b9da442d310ad2f2d735f2e56",
     "sha256": "0sxf6z3yzg4hggad172ljy6vxpnfll9q84pqa7n40m26g2alg29x"

+ 0 - 26
.config/nixpkgs/neovim/plugins/typescript-nvim-tsserver.patch

@@ -1,26 +0,0 @@
-diff --git a/lua/typescript/lsp.lua b/lua/typescript/lsp.lua
-index a2e01ec..3855580 100644
---- a/lua/typescript/lsp.lua
-+++ b/lua/typescript/lsp.lua
-@@ -22,7 +22,7 @@ local renameHandler = ____handlers.renameHandler
- local ____methods = require("typescript.types.methods")
- local TypescriptMethods = ____methods.TypescriptMethods
- local ____lspconfig = require("lspconfig")
--local tsserver = ____lspconfig.tsserver
-+local tsserver = ____lspconfig.ts_ls
- ____exports.setupLsp = function(overrides)
-     local resolvedConfig = __TS__ObjectAssign({}, config, overrides or ({}))
-     local ____resolvedConfig_server_0 = resolvedConfig.server
-diff --git a/lua/typescript/utils.lua b/lua/typescript/utils.lua
-index 4a166bb..252fe8a 100644
---- a/lua/typescript/utils.lua
-+++ b/lua/typescript/utils.lua
-@@ -10,7 +10,7 @@ ____exports.debugLog = function(...)
- end
- ____exports.getClient = function(bufnr)
-     for ____, client in pairs(vim.lsp.get_active_clients({bufnr = bufnr})) do
--        if client.name == "tsserver" then
-+        if client.name == "ts_ls" then
-             return client
-         end
-     end