-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests around
ClientCapabilities
As far as I can tell, there are no tests that depend on any of the values contained within `ClientCapabilities`. This commit adds some tests around the construction of the `TextDocumentSyncOptions` field for the server's capabilities. It also fixes a bug that was introduced in the previous commit
- Loading branch information
Showing
2 changed files
with
137 additions
and
2 deletions.
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,136 @@ | ||
from typing import Set | ||
|
||
import pytest | ||
from lsprotocol.types import ( | ||
TEXT_DOCUMENT_DID_OPEN, | ||
TEXT_DOCUMENT_DID_CLOSE, | ||
TEXT_DOCUMENT_DID_SAVE, | ||
TEXT_DOCUMENT_WILL_SAVE, | ||
TEXT_DOCUMENT_WILL_SAVE_WAIT_UNTIL, | ||
ClientCapabilities, | ||
SaveOptions, | ||
TextDocumentClientCapabilities, | ||
TextDocumentSaveRegistrationOptions, | ||
TextDocumentSyncClientCapabilities, | ||
TextDocumentSyncKind, | ||
TextDocumentSyncOptions, | ||
) | ||
|
||
from pygls.capabilities import ServerCapabilitiesBuilder | ||
|
||
|
||
@pytest.mark.parametrize("capabilities,features,options,expected", [ | ||
# textDocument/didOpen | ||
( | ||
ClientCapabilities(), | ||
set(), | ||
{}, | ||
TextDocumentSyncOptions( | ||
open_close=False, | ||
change=TextDocumentSyncKind.Incremental, | ||
save=False, | ||
) | ||
), | ||
( | ||
ClientCapabilities(), | ||
{TEXT_DOCUMENT_DID_OPEN}, | ||
{}, | ||
TextDocumentSyncOptions( | ||
open_close=True, | ||
change=TextDocumentSyncKind.Incremental, | ||
save=False, | ||
) | ||
), | ||
( | ||
ClientCapabilities(), | ||
{TEXT_DOCUMENT_DID_CLOSE}, | ||
{}, | ||
TextDocumentSyncOptions( | ||
open_close=True, | ||
change=TextDocumentSyncKind.Incremental, | ||
save=False, | ||
) | ||
), | ||
# textDocument/willSave & textDocument/willSaveWaitUntil | ||
( | ||
ClientCapabilities(), | ||
{TEXT_DOCUMENT_WILL_SAVE}, | ||
{}, | ||
TextDocumentSyncOptions( | ||
open_close=False, | ||
change=TextDocumentSyncKind.Incremental, | ||
save=False, | ||
) | ||
), | ||
( | ||
ClientCapabilities( | ||
text_document=TextDocumentClientCapabilities( | ||
synchronization=TextDocumentSyncClientCapabilities( | ||
will_save=True | ||
) | ||
) | ||
), | ||
{TEXT_DOCUMENT_WILL_SAVE}, | ||
{}, | ||
TextDocumentSyncOptions( | ||
open_close=False, | ||
change=TextDocumentSyncKind.Incremental, | ||
save=False, | ||
will_save=True | ||
) | ||
), | ||
( | ||
ClientCapabilities( | ||
text_document=TextDocumentClientCapabilities( | ||
synchronization=TextDocumentSyncClientCapabilities( | ||
will_save_wait_until=True | ||
) | ||
) | ||
), | ||
{TEXT_DOCUMENT_WILL_SAVE_WAIT_UNTIL}, | ||
{}, | ||
TextDocumentSyncOptions( | ||
open_close=False, | ||
change=TextDocumentSyncKind.Incremental, | ||
save=False, | ||
will_save_wait_until=True | ||
) | ||
), | ||
# textDocument/didSave | ||
( | ||
ClientCapabilities(), | ||
{TEXT_DOCUMENT_DID_SAVE}, | ||
{}, | ||
TextDocumentSyncOptions( | ||
open_close=False, | ||
change=TextDocumentSyncKind.Incremental, | ||
save=True, | ||
) | ||
), | ||
( | ||
ClientCapabilities(), | ||
{TEXT_DOCUMENT_DID_SAVE}, | ||
{TEXT_DOCUMENT_DID_SAVE: TextDocumentSaveRegistrationOptions(include_text=True)}, | ||
TextDocumentSyncOptions( | ||
open_close=False, | ||
change=TextDocumentSyncKind.Incremental, | ||
save=SaveOptions(include_text=True), | ||
) | ||
) | ||
]) | ||
def test_text_doc_sync_capabilities( | ||
capabilities: ClientCapabilities, | ||
features: Set[str], | ||
options, | ||
expected: TextDocumentSyncOptions | ||
): | ||
"""Ensure that `pygls` can correctly construct server capabilities for the | ||
text document sync features.""" | ||
|
||
builder = ServerCapabilitiesBuilder( | ||
capabilities, features, options, [], TextDocumentSyncKind.Incremental | ||
) | ||
|
||
actual = builder.build().text_document_sync | ||
assert expected == actual |