pmizio / typescript-tools.nvim

âš¡ TypeScript integration NeoVim deserves âš¡
MIT License
1.48k stars 43 forks source link

[question] - TSTools commands don't get run on save #49

Closed Jezda1337 closed 1 year ago

Jezda1337 commented 1 year ago

Any idea why this commands doesn't work? 🤔 when I run them manually they work, but like this nah

local autocmd = vim.api.nvim_create_autocmd
local Format = vim.api.nvim_create_augroup("Format", { clear = true })
autocmd("BufWritePre", {
    group = Format,
    pattern = "*.ts,*.tsx,*.jsx,*.js",
    callback = function()
        -- if vim.fn.exists(":TypescriptFixAll") then
        --  vim.cmd("TypescriptFixAll!")
        --  vim.cmd("TypescriptRemoveUnused!")
        --  vim.cmd("TypescriptOrganizeImports!")
        --  return nil
        -- end
        if vim.fn.exists(":TSToolsOrganizeImports") then
            vim.cmd("TSToolsOrganizeImports")
            vim.cmd("TSToolsSortImports")
            vim.cmd("TSToolsRemoveUnusedImports")
            return {}
        end
        return {}
    end,
})
KostkaBrukowa commented 1 year ago

Hey! I've just copied this autocmd into my config and it works fine. Can you provide more context? Maybe minimal repro steps? And btw. TypescriptFixAll and TypescriptRemoveUnused are not currently supported by the plugin. We have TSToolsRemoveUnusedImports but it only removes unused imports - not every unused "thing" - as in the TLS. Also "TSToolsOrganizeImports" runs TSToolsSortImports and TSToolsRemoveUnusedImports under the hood so you don't need to call all three of them

Jezda1337 commented 1 year ago

Hey @KostkaBrukowa, thanks for the answer, after I remove TSToolsSortImports and TSToolsRemoveUnusedImports from the code, everything works now. I guess calling all 3 doesn't work but calling only TSToolsOrganizeImports do the thing.