Skip to content

Add client side configuration and cache configuration per file #26

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

Merged
merged 10 commits into from
Mar 28, 2022

Conversation

haplo
Copy link
Collaborator

@haplo haplo commented Dec 3, 2021

Use lru_cache decorator on load_config to remember the black configuration for each file that the plugin processes. If the black configuration changes for any reason (e.g. the user editing the pyproject.toml file for the project) then the LSP server would need to be restarted for python-lsp-black to refresh the configuration.

  • Support plugin configuration (pylsp.plugins.black namespace)
  • Add unit test for plugin configuration.
  • Only enable load_config caching if pylsp.plugins.black.cache_config is set in plugin settings.
  • Add unit test for config caching.
  • Support Black's preview features if pylsp.plugins.black.preview is true.

@haplo haplo added the enhancement New feature or request label Dec 3, 2021
@haplo haplo added this to the v1.2.0 milestone Dec 3, 2021
@haplo haplo linked an issue Dec 3, 2021 that may be closed by this pull request
Use lru_cache decorator on load_config to remember the black configuration
for each file that the plugin processes. If the black configuration
changes for any reason (e.g. the user editing the pyproject.toml file for
the project) then the LSP server would need to be restarted for
python-lsp-black to refresh the configuration.
Also, use those options to get the line length used by Black.
Also, check that line length can be changed from the client
@ccordoba12 ccordoba12 changed the title Cache black configuration per file Add client side configuration and cache configuration per file Mar 21, 2022
This was added in Black 22.1.0
@ccordoba12 ccordoba12 marked this pull request as ready for review March 21, 2022 17:46
@ccordoba12
Copy link
Member

@haplo, this is ready for review.

@ccordoba12 ccordoba12 requested a review from dalthviz March 25, 2022 17:02
@dalthviz dalthviz changed the title Add client side configuration and cache configuration per file PR: Add client side configuration and cache configuration per file Mar 25, 2022
@ccordoba12
Copy link
Member

Pinging @haplo again. I hope you can review this one soon because we need it for Spyder 5.3.0, to be released next Wednesday.

@haplo
Copy link
Collaborator Author

haplo commented Mar 27, 2022

Pinging @haplo again. I hope you can review this one soon because we need it for Spyder 5.3.0, to be released next Wednesday.

Sorry @ccordoba12, I had a busy week. I'm now reviewing all open PRs and will prepare a release once they are all merged.

settings = client_config.plugin_settings("black")

# Use the original, not cached function to load settings if requested
if not settings.get("cache_config", True):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we default to True users could get confused as to why their changes to black configuration files are not being observed (they would need to restart the LSP server). I think either we default to False or we document configuration caching in README. We should document plugin configuration anyway, so maybe we can go with the second option.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm updating the README to document plugin configuration.

Copy link
Member

@ccordoba12 ccordoba12 Mar 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought you wanted this option to be True. I'll change it to False then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My rationale was that caching the black configuration by default could be confusing to users, as black configuration changes (e.g. in pyproject.toml) would need an LSP server restart.

I'm updating the README with this and other details, I think we can merge after that and prepare the release.

"""Return a config object."""
cfg = Config(workspace.root_uri, {}, 0, {})
cfg._plugin_settings = {
"plugins": {"black": {"line_length": 88, "cache_config": True}}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If configuration caching is enabled by default we should have a test that checks that it can be disabled.

Copy link
Member

@ccordoba12 ccordoba12 Mar 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test for this since it was part of your TODOs. See test_cache_config below.

@ccordoba12
Copy link
Member

@haplo, I addressed your review and also added in my last commit (i.e. 5a3ec80) a hook with all config options supported by this plugin.

"plugins": {
"black": {
# Disable this plugin by default because it's third-party.
"enabled": False,
Copy link
Collaborator Author

@haplo haplo Mar 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going to break most users' installations when people upgrade. Would it be too bad if we enabled it by default and documented how to disable it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My rationale is that if the plugin is installed that means it's intended to be used, so having to set the configuration is another step in the way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, no problem. I'll change this option to True then. However, both Autopep8 and Yapf are enabled too, so I don't know which one takes precedence.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had trouble with autopep8 and yapf, maybe because I don't install those features (pip install python-lsp-server[rope,pycodestyle,flake8]). Would be worth checking what happens on a regular install, and either plan code fixes or document in README.

Document configuration caching.
@haplo
Copy link
Collaborator Author

haplo commented Mar 28, 2022

@ccordoba12 I pushed my update to README, please take a look.

Only open issue is defaulting enabled to false, I think we would get a lot of angry users if we did that. Can we leave it enabled by default while still supporting the enabled configuration option to disable it?

Also fix a small error in our Readme
@ccordoba12
Copy link
Member

Can we leave it enabled by default while still supporting the enabled configuration option to disable it?

Sure, no problem. I did it in my last commit.

@ccordoba12 ccordoba12 changed the title PR: Add client side configuration and cache configuration per file Add client side configuration and cache configuration per file Mar 28, 2022
@haplo haplo merged commit e8cfc43 into master Mar 28, 2022
@haplo haplo deleted the cache-config branch March 28, 2022 17:26
@haplo
Copy link
Collaborator Author

haplo commented Mar 28, 2022

@ccordoba12 I released version 1.2.0. It would be great to have a more direct channel to communicate, is there something for python-lsp-server that we could use?

@ccordoba12
Copy link
Member

I released version 1.2.0

Thanks a lot for your help @haplo!

It would be great to have a more direct channel to communicate, is there something for python-lsp-server that we could use?

You mean like a mailing list or Discourse instance?

@haplo
Copy link
Collaborator Author

haplo commented Mar 28, 2022

I released version 1.2.0

Thanks a lot for your help @haplo!

You are welcome, thank you for driving this PR home.

It would be great to have a more direct channel to communicate, is there something for python-lsp-server that we could use?

You mean like a mailing list or Discourse instance?

I was thinking of something real-time, like a Matrix channel or maybe Gitter. That could also be a place for users to ask questions and seek support from the community.

@ccordoba12
Copy link
Member

ccordoba12 commented Apr 4, 2022

I see. Gitter is a good idea, but I don't have time to participate on it. Would you like me to open a Gitter channel for python-lsp-server?

@haplo
Copy link
Collaborator Author

haplo commented Apr 8, 2022

My original idea was to have some real-time communication channel with you and maybe other python-lsp-server maintainers, because right now it's only Github issues. If you use Signal (preferred) or Telegram you can find my phone number in my website, just look at my Github profile.

I still think a Gitter channel would be a good idea to give users a place to talk about python-lsp-server and its plugins. I would check it out from time to time, but also don't plan on participating all the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to cache black configuration per-file
2 participants