-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ruff server
: Resolve configuration for each document individually
#10950
Conversation
|
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 like the laziness of the current design but I think has the downside (as far as I understand) that we deserialize and store a resolved configuration for each directory. That's unlikely a huge memory issue. It's also unclear to me if the ConfigurationIndex
gets correctly invalidated when:
- I open a file in a directory that inherits the configuration from the parent directory (the configuration is now stored in the index)
- I close the file
- I change the parent configuration (that reloads the configurations of all paths with open documents)
- I reopen the file (I suspect it reuses the old configuration)
I think there's a similar case where creating a new configuration in a specific directory must correctly propagate to all sub-directories). The easiest fix is to simply prune all sub-directory entries, but maybe we can do better?
I wonder if we should instead traverse the workspace eagerly and discovers all configurations or model the index in a way that it tracks whether a path has its own configuration or inherits from the parent (finding the configuration is then the same as finding the first entry where the configuration is not inherited).
It's not uncommon for a language server to spend some time initially to setup the workspace. This could potentially include building up the configuration index as suggested by Micha but I'm ok with the lazy approach as well. Thank you for providing the test plan. Can you expand it by listing down any/all the scenarios that you've tested against? This way I can make sure to not repeat it and come up with any other possible project structure to test this change against. |
It should be correctly invalidated - any time a configuration file gets changed, we clear the entire configuration index before we start the configuration reload (see this line) |
I'm cool with the eager approach! It would definitely be more efficient. |
…es entries for the folder where the config files reside
1de380a
to
a746423
Compare
I've added them to the test plan! |
Summary
Configuration is no longer the property of a workspace but rather of individual documents. Just like the Ruff CLI, each document is configured based on the 'nearest' project configuration. See the Ruff documentation for more details.
To reduce the amount of times we resolve configuration for a file, we have an index for each workspace that stores a reference-counted pointer to a configuration for a given folder. If another file in the same folder is opened, the configuration is simply re-used rather than us re-resolving it.
Guide for reviewing
The first commit is just the restructuring work, which adds some noise to the diff. If you want to quickly understand what's actually changed, I recommend looking at the two commits that come after it. f7c073d makes configuration a property of
DocumentController
/DocumentRef
, moving it out ofWorkspace
, and it also sets up theConfigurationIndex
, though it doesn't implement its key function,get_or_insert
. In the commit after it, fc35618, we implementget_or_insert
.Test Plan
The best way to test this would be to ensure that the behavior matches the Ruff CLI. Open a project with multiple configuration files (or add them yourself), and then introduce problems in certain files that won't show due to their configuration. Add those same problems to a section of the project where those rules are run. Confirm that the lint rules are run as expected with
ruff check
. Then, open your editor and confirm that the diagnostics shown match the CLI output.As an example - I have a workspace with two separate folders,
pandas
andscipy
. I created apyproject.toml
file inpandas/pandas/io
and aruff.toml
file inpandas/pandas/api
. I changed theselect
andpreview
settings in the sub-folder configuration files and confirmed that these were reflected in the diagnostics. I also confirmed that this did not change the diagnostics for thescipy
folder whatsoever.