Git Product home page Git Product logo

cspell.nvim's Introduction

cspell.nvim

A companion plugin for null-ls, adding support for cspell diagnostics and code actions.

Diagnostics

local cspell = require('cspell')
local sources = { cspell.diagnostics }

Defaults

  • Filetypes: {}
  • Method: diagnostics
  • Command: cspell
  • Args: dynamically resolved (see diagnostics source)

Code Actions

local cspell = require('cspell')
local sources = { cspell.diagnostics, cspell.code_actions }

Defaults

  • Filetypes: {}
  • Method: code_action

Configuration options

All the configuration properties are optional and they're used for the code actions.

But if you define them, make sure to add them to both the diagnostics and the code_actions. We need to do that to start reading and parsing the CSpell configuration asynchronously as soon as we get the first diagnostic.

local config = {
  -- The CSpell configuration file can take a few different names this option
  -- lets you specify which name you would like to use when creating a new
  -- config file from within the `Add word to cspell json file` action.
  --
  -- See the currently supported files in https://github.com/davidmh/cspell.nvim/blob/main/lua/cspell/helpers.lua
  config_file_preferred_name = 'cspell.json',

  --- A way to define your own logic to find the CSpell configuration file.
  ---@params cwd The same current working directory defined in the source,
  --             defaulting to vim.loop.cwd()
  ---@return string|nil The path of the json file
  find_json = function(cwd)
  end,

  ---@param cspell string The contents of the CSpell config file
  ---@return table
  encode_json = function(cspell_str)
  end,

  ---@param cspell table A lua table with the CSpell config values
  ---@return string
  encode_json = function(cspell_tbl)
  end,


  --- Callback after a successful execution of a code action.
  ---@param cspell_config_file_path string|nil
  ---@param params GeneratorParams
  ---@action_name 'use_suggestion'|'add_to_json'|'add_to_dictionary'
  on_success = function(cspell_config_file_path, params, action_name)
      -- For example, you can format the cspell config file after you add a word
      if action_name == 'add_to_json' then
          os.execute(
              string.format(
                  "cat %s | jq -S '.words |= sort' | tee %s > /dev/null",
                  cspell_config_file_path,
                  cspell_config_file_path
              )
          )
      end

      -- Note: The cspell_config_file_path param could be nil for the
      -- 'use_suggestion' action
  end
}

local cspell = require('cspell')
local sources = {
  cspell.diagnostics.with({ config = config }),
  cspell.code_actions.with({ config = config }),
}

Notes

  • The code action source depends on the diagnostics, so make sure to register it too.

Tests

The test suite depends on plenary.nvim.

Run ./tests/run.sh in the root of the project to run the suite or use neotest to run individual tests from within Neovim.

To avoid a dependency on any plugin managers, the test suite will set up its plugin runtime under the ./tests directory to always have a plenary version available.

If you run into plenary-related issues while running the tests, make sure you have an up-to-date version of the plugin by clearing that cache with rm -rf .tests/.

All tests expect the latest Neovim master.

TODO

  • Custom configuration examples

Credits

These sources were initially written in jose-elias-alvarez/null-ls.nvim, with contributions from: @JA-Bar, @PumpedSardines, @Saecki, @Sloff, @marianozunino, @mtoohey31 and @yoo.

cspell.nvim's People

Contributors

davidmh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.