barreiroleo / ltex_extra.nvim

Provides external LTeX file handling (off-spec lsp) and other functions.
GNU General Public License v3.0
132 stars 14 forks source link

File system watcher #31

Open barreiroleo opened 1 year ago

barreiroleo commented 1 year ago

When manually modifying a ltex file, it would be nice to trigger require"ltex_extra".reload().

barreiroleo commented 1 year ago

Quoting JManch's comment to give a proper follow-up as an issue. The PR was a good MVP to merge it in develop branch.

Seems to mostly work well on Windows and Linux apart from one issue I can't work out. As it is, this PR contains a couple potential incompatibilities:

Leaving the path option empty (the root project directory) won't work with the file watcher as it will refresh for all file changes in the working directory. This could be resolved by changing the default path to a relative directory like .ltex or maybe by forcefully disabling the file watcher in this scenario?
Manually setting path to a directory that isn't exclusivelty for ltex files will cause the same problem. I've added a file_watcher option that is disabled by default along with a warning message in the readme to hopefully prevent any issues with this.

The path for saving ltex files now gets set once in on_attach. This prevents stuff from breaking if the user changes their working directory whilst Neovim is open. The downside is that this won't support multiple instances of the ltex lsp, although I don't think this was supported before anyway. Known issue

Spellings manually deleted from the dictionary are not reflected by LSP diagnostics.

Steps to reproduce:

Enable the file watcher and open a document inside a workspace that contains a dictionary with existing spelling overrides
With the document still open, manually delete a spelling entry from the dictionary file
Observe that the Neovim diagnostics do not show deleted word now having incorrect spelling

I can see in the logs that ltex is correctly refreshing with the updated dictionary contents so the file watcher seems to be working fine. What's strange is that the issue only occurs for spellings that existed in the dictionary before opening Neovim. If a definition is added whilst Neovim is running (via code actions or manually), it can be manually deleted from the dictionary file and the change is reflected correctly.