Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

Run :TSLspOrganizeSync as formatter? #109

Discussion options

You must be logged in to vote

The safest way to do this is to set up a command that does both, something like this (untested but it should make sense):

_G.formatting = function()
    local bufnr = vim.api.nvim_get_current_buf()
    local tsserver_is_attached = false
    for _, client in ipairs(vim.lsp.buf_get_clients(bufnr)) do
        if client.name == "tsserver" then
            tsserver_is_attached = true
            break
        end
    end

    if tsserver_is_attached then
        require("nvim-lsp-ts-utils").organize_imports_sync(bufnr)
    end
    vim.lsp.buf.formatting_seq_sync()
end

If you really want to set this up as a null-ls formatter, it's possible, but it's pretty hacky and I can't guarantee that it'll…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@agriffis
Comment options

@agriffis
Comment options

@jose-elias-alvarez
Comment options

Answer selected by agriffis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants