Skip to content

Commit 330265d

Browse files
committed
chore: improve typing of get_capability
1 parent d7dc13a commit 330265d

4 files changed

Lines changed: 1060 additions & 19 deletions

File tree

pygls/capabilities.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
# limitations under the License. #
1616
############################################################################
1717
import logging
18-
from functools import reduce
1918
from typing import Any, Dict, List, Optional, Set, TypeVar, Union
2019

2120
from lsprotocol import types
2221

22+
from pygls.lsp._capabilities import get_capability
23+
2324
logger = logging.getLogger(__name__)
2425
T = TypeVar("T")
2526

@@ -32,22 +33,6 @@
3233
)
3334

3435

35-
def get_capability(
36-
client_capabilities: types.ClientCapabilities, field: str, default: Any = None
37-
) -> Any:
38-
"""Check if ClientCapabilities has some nested value without raising
39-
AttributeError.
40-
e.g. get_capability('text_document.synchronization.will_save')
41-
"""
42-
try:
43-
value = reduce(getattr, field.split("."), client_capabilities)
44-
except AttributeError:
45-
return default
46-
47-
# If we reach the desired leaf value but it's None, return the default.
48-
return default if value is None else value
49-
50-
5136
class ServerCapabilitiesBuilder:
5237
"""Create `ServerCapabilities` instance depending on builtin and user registered
5338
features.

0 commit comments

Comments
 (0)