-
Notifications
You must be signed in to change notification settings - Fork 194
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
Support initializationOptions
to configure the server
#459
Merged
ccordoba12
merged 8 commits into
python-lsp:develop
from
tkrabel-db:bugfix-support-init-opts
Oct 20, 2023
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2dad2ae
Support initializationOptions
tkrabel-db 274afb1
black format
tkrabel-db 8d70bf7
unti tests
tkrabel-db f7634f1
black
tkrabel-db 173d3eb
fix unit test patching workspace.update_config
tkrabel-db 13a57b8
Merge branch 'develop' into bugfix-support-init-opts
tkrabel-db 6a7c1a9
minor fix
tkrabel-db 4e5db37
refactor unit tests
tkrabel-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright 2021- Python Language Server Contributors. | ||
|
||
import os | ||
from unittest.mock import patch | ||
|
||
from test.fixtures import CALL_TIMEOUT_IN_SECONDS | ||
ccordoba12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from test.test_notebook_document import wait_for_condition | ||
|
||
import pytest | ||
|
||
from pylsp import IS_WIN | ||
|
||
|
||
INITIALIZATION_OPTIONS = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using this as an example as this is a real world example for when to override confs |
||
"pylsp": { | ||
"plugins": { | ||
"flake8": {"enabled": True}, | ||
"pycodestyle": {"enabled": False}, | ||
"pyflakes": {"enabled": False}, | ||
}, | ||
} | ||
} | ||
|
||
|
||
@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows") | ||
def test_set_flake8_using_init_opts(client_server_pair): | ||
client, server = client_server_pair | ||
client._endpoint.request( | ||
"initialize", | ||
{ | ||
"processId": 1234, | ||
"rootPath": os.path.dirname(__file__), | ||
"initializationOptions": INITIALIZATION_OPTIONS, | ||
}, | ||
).result(timeout=CALL_TIMEOUT_IN_SECONDS) | ||
for key, value in INITIALIZATION_OPTIONS["pylsp"]["plugins"].items(): | ||
assert server.workspace._config.settings().get("plugins").get(key).get( | ||
"enabled" | ||
) == value.get("enabled") | ||
|
||
|
||
@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows") | ||
def test_set_flake8_using_workspace_did_change_configuration(client_server_pair): | ||
client, server = client_server_pair | ||
client._endpoint.request( | ||
"initialize", | ||
{ | ||
"processId": 1234, | ||
"rootPath": os.path.dirname(__file__), | ||
}, | ||
).result(timeout=CALL_TIMEOUT_IN_SECONDS) | ||
assert ( | ||
server.workspace._config.settings().get("plugins").get("flake8").get("enabled") | ||
is False | ||
) | ||
|
||
with patch.object(server.workspace, "update_config") as mock_update_config: | ||
client._endpoint.notify( | ||
"workspace/didChangeConfiguration", | ||
{"settings": INITIALIZATION_OPTIONS}, | ||
) | ||
wait_for_condition(lambda: mock_update_config.call_count >= 1) | ||
|
||
for key, value in INITIALIZATION_OPTIONS["pylsp"]["plugins"].items(): | ||
assert server.workspace._config.settings().get("plugins").get(key).get( | ||
"enabled" | ||
) == value.get("enabled") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Language servers typically don't scope initialization settings to server name because, unlike the workspace settings, those are specific to the server itself and don't have any chance of conflicting with other settings.
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 am happy to address this, but it seems that there is lack of consensus on whether
initializationOptions
should be used for server 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.
pylsp
is the options namespace used for this server, so I'm fine with using it here.