Browse Source

fix(lsp,typescript): Breaking when switching between tsx and ts files

my-config
connorgmeean 3 years ago
parent
commit
b8d8e88762
  1. 7
      lua/doom/modules/langs/typescript/init.lua
  2. 13
      lua/doom/utils/init.lua

7
lua/doom/modules/langs/typescript/init.lua

@ -1,3 +1,5 @@
local utils = require('doom.utils');
local typescript = {} local typescript = {}
typescript.settings = { typescript.settings = {
@ -7,7 +9,8 @@ typescript.autocmds = {
{ {
"FileType", "FileType",
"typescript,typescriptreact", "typescript,typescriptreact",
function() utils.make_run_once_function(function()
print('Configuring typescript')
local langs_utils = require('doom.modules.langs.utils') local langs_utils = require('doom.modules.langs.utils')
langs_utils.use_lsp('tsserver') langs_utils.use_lsp('tsserver')
@ -26,7 +29,7 @@ typescript.autocmds = {
null_ls.builtins.diagnostics.eslint_d, null_ls.builtins.diagnostics.eslint_d,
}) })
end end
end, end),
once = true, once = true,
}, },
} }

13
lua/doom/utils/init.lua

@ -224,6 +224,19 @@ utils.is_module_enabled = function(plugin)
return false return false
end end
--- Returns a function that can only be run once
---@param fn function
---@return function
utils.make_run_once_function = function(fn)
local has_run = false
return function(...)
if not has_run then
fn(...)
has_run = true
end
end
end
--- Rounds a number, optionally to the nearest decimal place --- Rounds a number, optionally to the nearest decimal place
--- @param num number - Value to round --- @param num number - Value to round
--- @param decimalplace number|nil - Number of decimal places --- @param decimalplace number|nil - Number of decimal places

Loading…
Cancel
Save