barreiroleo / ltex_extra.nvim

Provides external LTeX file handling (off-spec lsp) and other functions.
GNU General Public License v3.0
148 stars 16 forks source link
grammar latex lsp ltex lua markdown nvim vim
🚧 Dev branch will be merged soon. Please take a look at the Deprecations notes in dev branch.
# LTeX_extra.nvim
Provides implementations for non-LSP LTeX commands.
Developed and tested in Nightly. It's not required for you
[![Lua](https://img.shields.io/badge/Lua-blue.svg?style=for-the-badge&logo=lua)](http://www.lua.org) ![Work In Progress](https://img.shields.io/badge/Work%20In%20Progress-orange?style=for-the-badge) ![Neovim](https://img.shields.io/badge/NeoVim-%2357A143.svg?&style=for-the-badge&logo=neovim&logoColor=white)

LTeX language server provides some code actions off the LSP specifications. These commands require client implementations for things like file system operations.

LTeX_extra is a companion plugin for LTeX language server that provides such implementations for Neovim. The current supported methods are: addToDictionary, disableRule, hideFalsePositive.

Features

[!WARNING] The following demos may contain orthographic horrors.

Code Actions

Add word to dictionary, Hide false positive, and Disable rule

https://user-images.githubusercontent.com/48270301/177694689-b6b12b4a-3981-47fe-aa88-567697f797bd.mp4

Custom Export Path

Give you compatibility with official vscode extension, and flexibility to do things like global dictionaries.

https://user-images.githubusercontent.com/48270301/177694714-2f9d7477-26b6-4bf5-a47e-63ce2f82d76a.mp4

Load on Start

Load ltex files on server start.

https://user-images.githubusercontent.com/48270301/177694724-736159ab-c202-4325-ad23-405c76676b79.mp4

Installation

🚧 This plugin will be rewritten and as consequence I want to support just one method to initialize the plugin. The chosen one probably will be based on the LspAttach autocommand. I won't support the server initialization through this plugin anymore. It was a bad decision, doesn't provide much value and is hard to maintain.

This plugin requires an instance of ltex_ls language server available to attach. ltex-ls is available at mason.nvim.

Install the plugin with your favorite plugin manager using {"barreiroleo/ltex-extra.nvim"}. Then add require("ltex_extra").setup() to your config.

There are two recommended methods:

  1. Call the setup from on_attach function of your server. Example with lspconfig, minor changes are required for mason handler: lua require("lspconfig").ltex.setup { capabilities = your_capabilities, on_attach = function(client, bufnr) -- rest of your on_attach process. require("ltex_extra").setup { your_opts } end, settings = { ltex = { your settings } } }
  2. Use the handler which ltex_extra provide to call the server. Example of use with lazy.nvim:

    return {
       "barreiroleo/ltex_extra.nvim",
       ft = { "markdown", "tex" },
       dependencies = { "neovim/nvim-lspconfig" },
       -- yes, you can use the opts field, just I'm showing the setup explicitly
       config = function()
           require("ltex_extra").setup {
               your_ltex_extra_opts,
               server_opts = {
                   capabilities = your_capabilities,
                   on_attach = function(client, bufnr)
                       -- your on_attach process
                   end,
                   settings = {
                       ltex = { your settings }
                   }
               },
           }
       end
    }

Configuration

Here are the settings available on ltex_extra. You don't need explicit define each one, just modify what you need.

Notes: You can pass to setup the arguments that you are interested in and omit the rest. At the moment, if you have dictionary, disabledRules and hiddenFalsePositives defined in your ltex settings, they aren't backed up.

require("ltex_extra").setup {
    -- table <string> : languages for witch dictionaries will be loaded, e.g. { "es-AR", "en-US" }
    -- https://valentjn.github.io/ltex/supported-languages.html#natural-languages
    load_langs = { "en-US" } -- en-US as default
    -- boolean : whether to load dictionaries on startup
    init_check = true,
    -- string : relative or absolute path to store dictionaries
    -- e.g. subfolder in the project root or the current working directory: ".ltex"
    -- e.g. shared files for all projects:  vim.fn.expand("~") .. "/.local/share/ltex"
    path = "", -- project root or current working directory
    -- string : "none", "trace", "debug", "info", "warn", "error", "fatal"
    log_level = "none",
    -- table : configurations of the ltex language server.
    -- Only if you are calling the server from ltex_extra
    server_opts = nil
}

FAQ

Force reload

If you experience hangs with the server/plugin, you can force a reload of the LTeX files by running require("ltex_extra").reload()

https://user-images.githubusercontent.com/48270301/177694740-bc8bdb4c-0f6b-4f63-98af-54ec23196f27.mp4

Lspsaga:

Some users of lspsaga has reported issues with code actions. I don't use lspsaga, so PRs are welcome. Just make sure to test without that plugin enabled as well.

https://user-images.githubusercontent.com/39244876/201530888-077e76ad-211c-408f-80dc-89ba59751532.mov

Thanks to @felipejoribeiro for the screen recording

Contributors

Thanks to these people for your time, effort and ideas.