-
Notifications
You must be signed in to change notification settings - Fork 19
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
Conversation
0fc4a14
to
4f2e051
Compare
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.
4f2e051
to
bc56959
Compare
bb1e1c4
to
6be2701
Compare
Also, use those options to get the line length used by Black.
Also, check that line length can be changed from the client
6be2701
to
568a9f5
Compare
Also add a test for that.
b41310f
to
96d8d90
Compare
This was added in Black 22.1.0
39309c7
to
204766c
Compare
@haplo, this is ready for review. |
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. |
pylsp_black/plugin.py
Outdated
settings = client_config.plugin_settings("black") | ||
|
||
# Use the original, not cached function to load settings if requested | ||
if not settings.get("cache_config", True): |
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.
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.
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'm updating the README to document plugin configuration.
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.
Sorry, I thought you wanted this option to be True
. I'll change it to False
then.
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.
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.
tests/test_plugin.py
Outdated
"""Return a config object.""" | ||
cfg = Config(workspace.root_uri, {}, 0, {}) | ||
cfg._plugin_settings = { | ||
"plugins": {"black": {"line_length": 88, "cache_config": True}} |
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.
If configuration caching is enabled by default we should have a test that checks that it can be disabled.
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 added a test for this since it was part of your TODOs. See test_cache_config
below.
750455b
to
5a3ec80
Compare
pylsp_black/plugin.py
Outdated
"plugins": { | ||
"black": { | ||
# Disable this plugin by default because it's third-party. | ||
"enabled": False, |
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 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?
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.
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.
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.
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.
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 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.
@ccordoba12 I pushed my update to README, please take a look. Only open issue is defaulting |
Also fix a small error in our Readme
Sure, no problem. I did it in my last commit. |
@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? |
Thanks a lot for your help @haplo!
You mean like a mailing list or Discourse instance? |
You are welcome, thank you for driving this PR home.
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. |
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? |
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. |
Use
lru_cache
decorator onload_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.pylsp.plugins.black
namespace)load_config
caching ifpylsp.plugins.black.cache_config
is set in plugin settings.pylsp.plugins.black.preview
istrue
.