ts.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. local common = require("lsp.common-config")
  2. local keybindings = require("keybindings")
  3. local ts_utils = require("nvim-lsp-ts-utils")
  4. local opts = {
  5. flags = common.flags,
  6. capabilities = common.capabilities,
  7. -- https://github.com/jose-elias-alvarez/nvim-lsp-ts-utils/blob/main/lua/nvim-lsp-ts-utils/utils.lua
  8. -- 传入 tsserver 初始化参数
  9. -- make inlay hints work
  10. init_options = {
  11. hostInfo = "neovim",
  12. preferences = {
  13. includeInlayParameterNameHints = "all",
  14. includeInlayParameterNameHintsWhenArgumentMatchesName = true,
  15. includeInlayFunctionParameterTypeHints = true,
  16. includeInlayVariableTypeHints = true,
  17. includeInlayPropertyDeclarationTypeHints = true,
  18. includeInlayFunctionLikeReturnTypeHints = true,
  19. includeInlayEnumMemberValueHints = true,
  20. },
  21. },
  22. on_attach = function(client, bufnr)
  23. common.disableFormat(client)
  24. common.keyAttach(bufnr)
  25. -- defaults
  26. ts_utils.setup({
  27. debug = false,
  28. disable_commands = false,
  29. enable_import_on_completion = false,
  30. -- import all
  31. import_all_timeout = 5000, -- ms
  32. -- lower numbers = higher priority
  33. import_all_priorities = {
  34. same_file = 1, -- add to existing import statement
  35. local_files = 2, -- git files or files with relative path markers
  36. buffer_content = 3, -- loaded buffer content
  37. buffers = 4, -- loaded buffer names
  38. },
  39. import_all_scan_buffers = 100,
  40. import_all_select_source = false,
  41. -- if false will avoid organizing imports
  42. always_organize_imports = true,
  43. -- filter diagnostics
  44. filter_out_diagnostics_by_severity = {},
  45. -- https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
  46. filter_out_diagnostics_by_code = {
  47. 80001,
  48. },
  49. -- inlay hints
  50. auto_inlay_hints = true,
  51. inlay_hints_highlight = "Comment",
  52. inlay_hints_priority = 200, -- priority of the hint extmarks
  53. inlay_hints_throttle = 150, -- throttle the inlay hint request
  54. inlay_hints_format = { -- format options for individual hint kind
  55. Type = {},
  56. Parameter = {},
  57. Enum = {},
  58. -- Example format customization for `Type` kind:
  59. -- Type = {
  60. -- highlight = "Comment",
  61. -- text = function(text)
  62. -- return "->" .. text:sub(2)
  63. -- end,
  64. -- },
  65. },
  66. -- update imports on file move
  67. update_imports_on_move = false,
  68. require_confirmation_on_move = false,
  69. watch_dir = nil,
  70. })
  71. -- required to fix code action ranges and filter diagnostics
  72. ts_utils.setup_client(client)
  73. -- no default maps, so you may want to define some here
  74. keybindings.mapTsLSP(bufnr)
  75. end,
  76. }
  77. return {
  78. on_setup = function(server)
  79. server.setup(opts)
  80. end,
  81. }