Skip to content

aznhe21/lsp-query-format.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

lsp-query-format.nvim

lsp-query-format.nvim

A neovim plugin to query "formattable status" by LSP. "formattable" means vim.lsp.buf.format changes the buffer content.

In practice, you would use lualine.nvim to display the formattable status. See below for more details.

Installation

Using packer.nvim:

use {
  "aznhe21/lsp-query-format.nvim",
  config = function()
    require("lsp-query-format").setup()
  end,
}

Configuration

By default, formattable status is updated only when files are saved. You can update the status more frequently by using autocmd, such as CursorHold. Note: This may be annoying because some LSP servers (such as null-ls) report formatting progress.

require("lsp-query-format").setup {
  update_events = { "BufEnter", "BufWritePost", "CursorHold", "InsertLeave" },
}

Usage

This plugin sets a boolean value to b:lqf_formattable for each buffer. There is also an autocmd, LqfDone, which is executed when the formattable queries are done.

Display formattable status in a statusline:

vim.api.nvim_create_autocmd("User", {
  pattern = "LqfDone",
  callback = function(args)
    vim.b[args.buf].lqf_status = vim.b[args.buf].lqf_formattable and " [F]" or ""
  end,
})
vim.opt.statusline = [[%f%{get(b:, "lqf_status", "")}]]

You can use lualine.nvim for more convenient and customizable display. See below for more details.

Extensions

lualine.nvim

lqf-lualine.mp4

You can use filename_lqf instead of filename to display [F] marker when formatting is available. In addition to filename options, filename_lqf has its own options.

sections = {
  lualine_a = {
    {
      'filename_lqf',
      file_status = true,      -- Displays file status (readonly status, modified status)
      newfile_status = false,  -- Display new file status (new file means no write after created)
      format_status = true,    -- [LQF] Display formattable status
      path = 0,                -- 0: Just the filename
                               -- 1: Relative path
                               -- 2: Absolute path
                               -- 3: Absolute path, with tilde as the home directory

      shorting_target = 40,    -- Shortens path to leave 40 spaces in the window
                               -- for other components. (terrible name, any suggestions?)
      symbols = {
        modified = '[+]',      -- Text to show when the file is modified.
        readonly = '[-]',      -- Text to show when the file is non-modifiable or readonly.
        unnamed = '[No Name]', -- Text to show for unnamed buffers.
        newfile = '[New]',     -- Text to show for new created file before first writting
        formattable = '[F]',   -- [LQF] Text to show for formattable buffers.
      }
    }
  },
}

LICENSE

GPLv3

Releases

No releases published

Packages

No packages published

Languages