-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: respect language settings of imported files #75
base: main
Are you sure you want to change the base?
Conversation
cspell only respects the language of the main config, thus making it impossible to add new languages exclusively by importing them. This commit appends all the languages found in imported files to the main config automatically.
One thing I noticed is that cspell normally allows trailing commas in json, this implementation does not. Maybe there is an easy way to fix that. |
Another thing I noticed is that now the config needs a way to be reset. I only deleted the files manually, but that does not sound like a great way to do things, as it needs to be done every time a language is added. I think it would be good to expose a function that resets / deletes the internal cspell.json for the current working directory, but I am kind of new to this and unsure on how to do that. Then every user could invoke the call as they please. E.g. I would probably just clear the file on VimEnter or SessionEnter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do a more thorough review in the next few days; I don't have much bandwidth at the moment.
In the meantime, there are some minor linting issues, and I left a comment regarding the language property.
Exposing a cleanup function is going to be tricky, as we depend on the configuration params to build the combined config path. Maybe a new config option to build the combined file unconditionally?
lua/cspell/helpers.lua
Outdated
and type(cspell_config.language) == "string" | ||
and cspell_config.language ~= '' | ||
then | ||
cspell_json.language = cspell_json.language .. "," .. cspell_config.language |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appending languages unconditionally would result in strings like en,en
which is not necessarily a problem, but we should look into consolidating unique languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used your set_create to make the languages unique now.
I'm very thankful you're taking your time to look into this! I see your point and I guess I'm mixing in a different issue... I think once the plugin is loaded, it just uses the first cspell file it found. However, I'm working a lot with sessions and when I switch my session, the plugin keeps using the old cspell.json. I feel like both of these things are connected and could be resolved simultaneously, but I could be wrong. Just for my understanding, can An option to just force the rebuild every time (if that is what you mean) would probably be the easiest to implement. And at least on my machine, cspell takes like 1s to run anyway, another few milliseconds to rewrite a rather small file would hardly be noticeable. Other than that I'll let my mind wander a little, maybe some other idea comes to mind. Have a nice weekend! |
also moves from params.cwd to vim.fn.getcwd(-1,-1) (the global cwd) because params.cwd is only set once to the first working directory encountered and is never updated afterwards, no matter what happens to the global cwd
I thought a little bit and also had to debug some stuff and I found out that the It also allowed me to introduce an option which forces a rewrite of the Last but not least I noticed occasionally that deep folder structures were generated for the internal cspell.json. I added another gsub to also replace |
Not quite, For example, working on a monorepo with the following structure:
You may want of focus on working on For those cases, you can use the Using Using I can solve the issue by consuming local cwd = params.cwd or require('null-ls.utils').get_root() I also noticed that changing the cwd keeps appending to the cached For example, working on the following projects:
Let's say I start by editing That doesn't seem right.
I don't have a way to test against Windows, I would be comfortable with anything you decide on that, as long as it's covered by a test. |
Thank you for your in-depth feedback! It looks like I have a lot to learn about the plugin still. I'll look into it more, especially what the caches are doing and how that will interact with resets. I feel like the usage of the Thank you again for your time and effort! |
also removes option to reset paths on cwd change as it caused unintended behavior
provide cwd = func(params) to set the cwd, reset_cspell = func(params) to reset the caches and cspell_import_files = func(params) to set general imports
My new approach is injecting For example, I currently use this: local null_ls = require("null-ls")
local cspell_last_session = ""
null_ls.setup({
fallback_severity = vim.diagnostic.severity.HINT,
sources = {
require("cspell").diagnostics.with({
config = {
cspell_import_files = function(_)
return { vim.fn.expand("$APPDATA") .. "/npm/node_modules/@cspell/dict-de-de/cspell-ext.json" }
end,
cwd = function(_)
return vim.fn.getcwd()
end,
reset_cspell = function(params)
if params ~= nil and params.cwd ~= nil and vim.v.this_session ~= cspell_last_session then
cspell_last_session = vim.v.this_session
return true
else
return false
end
end,
},
}),
},
}) All the information in params is available because I pass params when calling cwd and reset_cspell. I also just now figured out how to escape all the right characters on windows to get the tests to run at all. Now I have to debug my runtime errors and also figure out what to test and how. |
Unfortunately, I currently find very little time to work on this. I hope to in the future, but it's probably unrealistic at least in the next month or two. I'm not quite sure what to do with this merge request during that time. We could leave it as it is, I could open a new one when I think I made significant progress or convert it to a draft. Anything is fine by me, but I wanted to let you know. |
No worries, happy to review that new version whenever you're ready. |
cspell only respects the language of the main config, thus making it impossible to add new languages exclusively by importing them. This pull request appends all the languages found in imported files to the main config automatically.
Fixes #74