Skip to content

Commit cac1a54

Browse files
Copilotobserverw
andcommitted
Add example demonstrating default configuration usage
Co-authored-by: observerw <[email protected]>
1 parent 3bf000c commit cac1a54

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

examples/default_configuration.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
"""
2+
Example demonstrating default configurations for LSP clients.
3+
4+
This example shows how the new default configurations work:
5+
1. All clients automatically have sensible defaults
6+
2. Inlay hints and other features are enabled out of the box
7+
3. Users can still override defaults if needed
8+
"""
9+
10+
from __future__ import annotations
11+
12+
from lsp_client.clients.pyright import PyrightClient
13+
from lsp_client.clients.rust_analyzer import RustAnalyzerClient
14+
from lsp_client.utils.config import ConfigurationMap
15+
16+
17+
def example_using_defaults():
18+
"""Example: Using default configuration (no setup required)"""
19+
print("Example 1: Using Default Configuration")
20+
print("-" * 50)
21+
22+
# Create a client - it automatically has default configuration
23+
client = PyrightClient()
24+
25+
# Get the default configuration that was created
26+
config_map = client.create_default_configuration_map()
27+
28+
if config_map:
29+
print("✓ Default configuration is available!")
30+
31+
# Check what inlay hints are enabled
32+
inlay_hints = config_map.get(None, "python.analysis.inlayHints")
33+
print(f" Inlay hints configuration: {inlay_hints}")
34+
35+
# Check type checking mode
36+
type_checking = config_map.get(None, "python.analysis.typeCheckingMode")
37+
print(f" Type checking mode: {type_checking}")
38+
39+
# Check auto-import completions
40+
auto_imports = config_map.get(None, "python.analysis.autoImportCompletions")
41+
print(f" Auto-import completions: {auto_imports}")
42+
43+
print()
44+
45+
46+
def example_with_custom_override():
47+
"""Example: Overriding default configuration"""
48+
print("Example 2: Overriding Default Configuration")
49+
print("-" * 50)
50+
51+
# Create a client
52+
client = RustAnalyzerClient()
53+
54+
# Get defaults - demonstrating that defaults exist
55+
_ = client.create_default_configuration_map()
56+
print("✓ Default configuration created")
57+
58+
# Create custom configuration that overrides some defaults
59+
custom_config = ConfigurationMap()
60+
custom_config.update_global(
61+
{
62+
"rust-analyzer": {
63+
"inlayHints": {
64+
"enable": False, # Disable inlay hints
65+
},
66+
"checkOnSave": {"enable": False}, # Disable check on save
67+
}
68+
}
69+
)
70+
71+
print("✓ Custom configuration created")
72+
print(" - Inlay hints: disabled")
73+
print(" - Check on save: disabled")
74+
75+
# You would set this on the client:
76+
# client.configuration_map = custom_config
77+
78+
print()
79+
80+
81+
def example_inspecting_defaults():
82+
"""Example: Inspecting default configurations for all clients"""
83+
print("Example 3: Inspecting Default Configurations")
84+
print("-" * 50)
85+
86+
from lsp_client.clients import clients
87+
88+
for client_cls in clients:
89+
client = client_cls()
90+
config_map = client.create_default_configuration_map()
91+
92+
if config_map and config_map.has_global_config():
93+
print(f"✓ {client_cls.__name__} has default configuration")
94+
95+
# Try to find inlay hints config
96+
for section in [
97+
"rust-analyzer.inlayHints",
98+
"gopls.hints",
99+
"python.analysis.inlayHints",
100+
"typescript.inlayHints",
101+
"deno.inlayHints",
102+
"pyrefly.inlayHints",
103+
]:
104+
value = config_map.get(None, section)
105+
if value is not None:
106+
print(f" → {section} is configured")
107+
break
108+
109+
print()
110+
111+
112+
if __name__ == "__main__":
113+
print("LSP Client Default Configuration Examples")
114+
print("=" * 50)
115+
print()
116+
117+
example_using_defaults()
118+
example_with_custom_override()
119+
example_inspecting_defaults()
120+
121+
print("=" * 50)
122+
print("All examples completed successfully!")

0 commit comments

Comments
 (0)