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

Spell sitter not showing incorrect spelling (/not working) #8

Closed
akinsho opened this issue Apr 28, 2021 · 12 comments · Fixed by #12
Closed

Spell sitter not showing incorrect spelling (/not working) #8

akinsho opened this issue Apr 28, 2021 · 12 comments · Fixed by #12

Comments

@akinsho
Copy link

akinsho commented Apr 28, 2021

Hey thanks for working on this plugin, I've really been missing having spell working in treesitter languages.

Apologies for the it doesn't work type issue but for the life of me I really can't seem to get it to work. I'm not sure if this is because it's still WIP in which case I'll just wait a bit, or if it should be working.

I have the plugin configured as

    use {
      "lewis6991/spellsitter.nvim",
      config = function()
        require("spellsitter").setup {hl = "SpellBad", captures = {"comment"}}
      end
    }

I'm on the latest nvim nightly, I have spell set to 0 my other spell related settings are

--the add helper just does string concatenation more or less
vim.o.spellsuggest = add(12, vim.o.spellsuggest)
vim.o.spelloptions = "camel"
vim.o.spellcapcheck = "" -- don't check for capital letters at start of sentence
vim.o.complete = add("kspell", vim.o.complete)

FWIW it was working when it was based on hunspell although I'm very glad to be done with an external dependency.

@akinsho
Copy link
Author

akinsho commented Apr 28, 2021

I've noticed that if I set spell then I set no spell it seems to maybe work but tbh I could just be mixing that up with the native spell highlighting not being cleared if you set spell then set nospell

@lewis6991
Copy link
Owner

AFAIK set spell shouldn't make a difference. I can confirm the plugin is working my end. A good way to check is to set hl='error':

       require('spellsitter').setup{
         hl = 'error',
       }

I haven't done any testing with any spell options you listed. You may want to try with them commented out.

The whole plugin is only ~170 LOC, so it should be easy to insert a few print statements to see what's going on. Some things to know:

  • on_lines should be called for every screen line that gets redrawn.
  • on_win should be called before on_lines is called.

This plugin is pretty WIP, the concept of it is a bit flawed too since neovims built-in spellchecker has a pretty scattered implementation. Hopefully this plugin can help figure out what we need to do to improve it.

@akinsho
Copy link
Author

akinsho commented Apr 30, 2021

Just tried commenting my settings out as well as changing the highlight, but that doesn't seem to make a difference. I'll clone the repo and poke around when next I get a chance to see if I can find what's going on

@weilbith
Copy link

@akinsho I have the same issue. Did you made it working for you?

@akinsho
Copy link
Author

akinsho commented Jun 17, 2021

@weilbith I recently had to re-install my machine (for unrelated reasons) and now it seems to work, tbh I have no idea what changed, I think I must have removed some plugin or setting somewhere that must have made the difference. I also recently re-added syntax enable to the start of my config. I had removed it because nvim does it by default but turns out there's an issue with how nvim does it and it's done too late

@lewis6991
Copy link
Owner

Are you sure the plugin is working and your not running the regular spellchecker using vims regex syntax engine?

I use this lua function to detect if the regex syntax engine is enabled for a buffer:

  function Syn_stack()
    local c = vim.api.nvim_win_get_cursor(0)
    local stack = vim.fn.synstack(c[1], c[2]+1)
    for i, l in ipairs(stack) do
      stack[i] = vim.fn.synIDattr(l, 'name')
    end
    print(vim.inspect(stack))
  end
  map('n', '<leader>z', ':lua Syn_stack()<CR>', {noremap=true})

@akinsho
Copy link
Author

akinsho commented Jun 17, 2021

@lewis6991 you're right, I just checked the set syntax? and for the filetypes where I see spelling errors the syntax has been set by some syntax plugins in my config. Where there is no syntax it still doesn't work.

@matu3ba
Copy link

matu3ba commented Jul 13, 2021

@akinsho The filetype not being set properly/too late is a known problem nanotee/nvim-lua-guide#69 and neovim/neovim#14774 (comment)
You might want to change the issue title to make clear what caused it.

@akinsho
Copy link
Author

akinsho commented Jul 13, 2021

@matu3ba I don't really know how the issues you're describing relate here. I'm yet to figure out what actually causes this issue for me, so I can't really change the title. My filetypes aren't being set differently than anyone else's, since I depend on vim's default ftdetect for most things.

@yourealwaysbe
Copy link
Contributor

yourealwaysbe commented Jul 20, 2021

For me, it works well when i open a file directly from the command line

$ nvim myfile.java

but when i change file inside nvim

:e myfile.java
:tabnew myfile.java

it does not work unless using the set spell then set nospell trick.

@yourealwaysbe
Copy link
Contributor

Trying to track this down, it looks like the plugin is still going through the motions correctly in that ffi.C.spell_check is being called on all the right parts of the file. However, if the buffer was opened with :e or :tabopen or similar, then ffi.C.spell_check always returns no mistakes.

I found by fiddling with the M.mod_spell_opt method -- making it set and then unset spell -- i could get it to work. This may be a bodge though..

function M.mod_spell_opt()
  local bufnr = api.nvim_get_current_buf()
  if not buf_enabled(bufnr) then return end
  spell_opt[bufnr] = vim.wo.spell
  vim.wo.spell = true
  vim.schedule(function()
      vim.wo.spell = false
  end)
end

@yourealwaysbe
Copy link
Contributor

A bit more playing: this seems to be connected to the nvim-lspconfig plugin. If i uninstall it, then spellsitter doesn't show the behaviour above.

malramsay64 added a commit to malramsay64/spellsitter.nvim that referenced this issue Aug 2, 2021
It seems that there are occasions like in lewis6991#8 where the spelling isn't
working correctly. This is because the value of spelllang hasn't yet
been parsed for the window. This results in the check for the loading of
the language files causing an early return from the spell check
function. The problematic line is [375 of neovim's spell.c](https://github.com/neovim/neovim/blob/1c416892879de6b78038f2cc2f1487eff46abb60/src/nvim/spell.c#L375)

By running the `did_set_spellang` function before running the spell
checks, this ensures that these laguage files have been appropriately
loaded.

Fixes lewis6991#8
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants