davidmh / cspell.nvim

A companion plugin for null-ls/none-ls, adding support for CSpell diagnostics and code actions.
85 stars 15 forks source link

enableFiletypes doesn't work as expected #20

Closed MKrbm closed 1 year ago

MKrbm commented 1 year ago

image With above settings, I expected that spellcheck will only be enabled for markdown files, but in reality, spell check is triggered for all files.

This cspell.json file is valid config file for cspell as adding "enabled" : false will prevent spellchecking for all files.

davidmh commented 1 year ago

That sounds like a conflict with the command we use to invoke CSpell.

In order to lint the current buffer with unsaved changes, we use the stdin.

It would be the equivalent of doing something like:

cat client/src/config.ts | cspell lint --language-id typescript stdin://client/src/config.ts

But instead of using cat, we're just sending the contents of the buffer.

CSpell doesn't seem to respect the enabledFileTypes option when we pass the path of the file. Probably an overlook in the CSpell code?

There are two possible ways for you to work around that limitation with the current state of the plugin and CSpell:

  1. You can replace the use of enabledFileTypes with the ignorePaths option.

    That option does work with this plugin, see: https://github.com/davidmh/cspell.nvim/pull/9

  2. You could define the filetypes you want to enable through the filetypes option from null-ls.

I would also invest some time in asking the CSpell team if that's intended behavior.

MKrbm commented 1 year ago

Thank you! I'll work around with filetypes option for null-ls.

MKrbm commented 1 year ago

Is this problem something do with the issue where diagnostics doesn't recognize the errors for newly edited sentences until I run :e?

davidmh commented 1 year ago

Hi @MKrbm sorry I missed that last comment. I haven't experienced that issue before, could you open a new issue for that?

It would also be easier to debug with a minimal configuration. You can take this file as an example: https://github.com/davidmh/cspell.nvim/blob/0e9c586bd7f7ab3f1f2f000a084121203e0ee62c/tests/minimal_init.lua

And you can add your own configuration right after this line:

https://github.com/davidmh/cspell.nvim/blob/0e9c586bd7f7ab3f1f2f000a084121203e0ee62c/tests/minimal_init.lua#L35

Something like:

    local null_ls = require("null-ls")
    local cspell = require("cspell")
    local sources = {
        cspell.diagnostics,
        cspell.code_actions,
    }

    null_ls.setup({ sources = sources })

Then you can start Neovim using that configuration as:

nvim -u minimal_init.lua some-other-file-to-lint.ts