Skip to content

Commit 3bf000c

Browse files
Copilotobserverw
andcommitted
Address code review comments: add public API and improve documentation
Co-authored-by: observerw <[email protected]>
1 parent 9afd8aa commit 3bf000c

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

docs/configuration.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,14 @@ from lsp_client.clients.rust_analyzer import RustAnalyzerClient
202202

203203
client = RustAnalyzerClient()
204204
config_map = client.create_default_configuration_map()
205-
print(config_map._global_config) # View the default settings
205+
206+
# Check if configuration exists
207+
if config_map and config_map.has_global_config():
208+
# Get specific configuration values
209+
inlay_hints_enabled = config_map.get(None, "rust-analyzer.inlayHints.enable")
210+
print(f"Inlay hints enabled: {inlay_hints_enabled}")
211+
212+
# Get entire section
213+
all_inlay_hints = config_map.get(None, "rust-analyzer.inlayHints")
214+
print(f"All inlay hint settings: {all_inlay_hints}")
206215
```

src/lsp_client/client/abc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,28 @@ def create_default_configuration_map(self) -> ConfigurationMap | None:
117117
This method can be overridden by subclasses to provide default configurations
118118
that enable extra features like inlay hints, diagnostics, etc.
119119
120+
The base implementation returns None, meaning no default configuration.
121+
Subclasses that support configuration should override this method to provide
122+
sensible defaults that enable commonly-used features.
123+
120124
Returns:
121125
ConfigurationMap with default settings, or None if no defaults are needed.
126+
127+
Example:
128+
Override this method in a client subclass to provide defaults:
129+
130+
```python
131+
@override
132+
def create_default_configuration_map(self) -> ConfigurationMap | None:
133+
config_map = ConfigurationMap()
134+
config_map.update_global({
135+
"myserver": {
136+
"inlayHints": {"enable": True},
137+
"diagnostics": {"enable": True},
138+
}
139+
})
140+
return config_map
141+
```
122142
"""
123143
return None
124144

src/lsp_client/utils/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,12 @@ def get(self, scope_uri: str | None, section: str | None) -> Any:
105105
logger.warning(f"Failed to parse scope URI: {scope_uri}")
106106

107107
return self._get_section(final_config, section)
108+
109+
def has_global_config(self) -> bool:
110+
"""
111+
Check if the configuration map has any global configuration.
112+
113+
Returns:
114+
True if global configuration is not empty, False otherwise.
115+
"""
116+
return bool(self._global_config)

tests/test_default_configuration.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
@pytest.mark.parametrize("client_cls", clients)
1111
def test_clients_have_default_configuration_method(client_cls):
1212
"""Test that all clients have a create_default_configuration_map method."""
13-
assert hasattr(
14-
client_cls, "create_default_configuration_map"
15-
), f"{client_cls.__name__} should have create_default_configuration_map method"
13+
assert hasattr(client_cls, "create_default_configuration_map"), (
14+
f"{client_cls.__name__} should have create_default_configuration_map method"
15+
)
1616

1717

1818
@pytest.mark.parametrize("client_cls", clients)
1919
def test_default_configuration_returns_valid_type(client_cls):
2020
"""Test that create_default_configuration_map returns None or ConfigurationMap."""
2121
client = client_cls()
2222
result = client.create_default_configuration_map()
23-
assert result is None or isinstance(
24-
result, ConfigurationMap
25-
), f"{client_cls.__name__}.create_default_configuration_map() should return None or ConfigurationMap"
23+
assert result is None or isinstance(result, ConfigurationMap), (
24+
f"{client_cls.__name__}.create_default_configuration_map() should return None or ConfigurationMap"
25+
)
2626

2727

2828
@pytest.mark.parametrize("client_cls", clients)
@@ -59,11 +59,10 @@ def test_default_configuration_has_content(client_cls):
5959
if config_map is None:
6060
pytest.skip(f"{client_cls.__name__} has no default configuration")
6161

62-
# Check that the configuration map has some content
63-
# Access the private attribute to check if global config has content
64-
assert (
65-
config_map._global_config
66-
), f"{client_cls.__name__} default configuration should not be empty"
62+
# Check that the configuration map has some content using public API
63+
assert config_map.has_global_config(), (
64+
f"{client_cls.__name__} default configuration should not be empty"
65+
)
6766

6867

6968
@pytest.mark.asyncio

0 commit comments

Comments
 (0)