typescript.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. local status, typescript = pcall(require, "typescript")
  2. if not status then
  3. vim.notify("没有找到 typescript")
  4. return
  5. end
  6. local uConfig = require("uConfig")
  7. local common = require("lsp.common-config")
  8. local opts = {
  9. capabilities = common.capabilities,
  10. flags = common.flags,
  11. on_attach = function(client, bufnr)
  12. -- common.disableFormat(client)
  13. common.keyAttach(bufnr)
  14. --[[
  15. :TypescriptOrganizeImports
  16. :TypescriptRenameFile
  17. :TypescriptAddMissingImports
  18. :TypescriptRemoveUnused
  19. :TypescriptFixAll
  20. :TypescriptGoToSourceDefinition
  21. ]]
  22. local bufopts = { noremap = true, silent = true, buffer = bufnr }
  23. keymap("n", uConfig.lsp.ts_organize, ":TypescriptOrganizeImports<CR>", bufopts)
  24. keymap("n", uConfig.lsp.ts_rename_file, ":TypescriptRenameFile<CR>", bufopts)
  25. keymap("n", uConfig.lsp.ts_add_missing_import, ":TypescriptAddMissingImports<CR>", bufopts)
  26. keymap("n", uConfig.lsp.ts_remove_unused, ":TypescriptRemoveUnused<CR>", bufopts)
  27. keymap("n", uConfig.lsp.ts_fix_all, ":TypescriptFixAll<CR>", bufopts)
  28. keymap("n", uConfig.lsp.ts_goto_source, ":TypescriptGoToSourceDefinition<CR>", bufopts)
  29. end,
  30. }
  31. return {
  32. on_setup = function(_)
  33. typescript.setup({
  34. disable_commands = false, -- prevent the plugin from creating Vim commands
  35. debug = false, -- enable debug logging for commands
  36. go_to_source_definition = {
  37. fallback = true, -- fall back to standard LSP definition on failure
  38. },
  39. server = opts,
  40. })
  41. end,
  42. }