You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pyrefly's LSP server now supports selective disabling of individual language services. This allows users to choose exactly which IDE features they want enabled, providing flexibility for different workflows and preferences.
3
+
Pyrefly's LSP server supports selective disabling of individual language services via command-line arguments. This allows users to choose exactly which IDE features they want enabled, providing flexibility for different workflows and preferences.
4
4
5
5
## Available Language Services
6
6
@@ -22,24 +22,9 @@ The following language services can be selectively disabled:
22
22
23
23
## Usage
24
24
25
-
### VSCode Extension
26
-
27
-
Add the following to your VSCode settings (`.vscode/settings.json` or user settings):
28
-
29
-
```json
30
-
{
31
-
"python.pyrefly.disabledLanguageServices": {
32
-
"hover": true,
33
-
"documentSymbol": true
34
-
}
35
-
}
36
-
```
37
-
38
-
This example disables hover tooltips and document symbols (outline), while keeping all other services enabled.
39
-
40
25
### Command-Line Arguments
41
26
42
-
When starting the LSP server manually, you can use command-line flags:
27
+
When starting the LSP server, you can use command-line flags to disable specific services:
You can also pass these command-line arguments through the VSCode extension settings:
50
+
For editors that support passing arguments to the LSP server (like VSCode), you can configure the arguments through editor settings. For VSCode, use the `pyrefly.lspArguments` setting:
66
51
67
52
```json
68
53
{
@@ -74,26 +59,26 @@ You can also pass these command-line arguments through the VSCode extension sett
74
59
}
75
60
```
76
61
62
+
This allows you to configure which services are disabled without manually starting the LSP server.
63
+
77
64
## Implementation Details
78
65
79
66
### Architecture Decision
80
67
81
-
The selective disabling is implemented at the **binary level** (LSP server) rather than the VSCode extension level. This design decision provides several benefits:
68
+
The selective disabling is implemented at the **binary level** (LSP server) via command-line arguments. This design provides several benefits:
82
69
83
70
1.**Cross-editor compatibility** - Works with any editor that uses Pyrefly's LSP server
84
-
2.**Cleaner architecture** - The server respects capabilities rather than the client filtering
85
-
3.**Performance** - Server doesn't process requests for disabled services
71
+
2.**Cleaner architecture** - The server respects capabilities through standard LSP initialization
72
+
3.**Performance** - Disabled services are not advertised as capabilities
86
73
4.**Maintainability** - Logic is centralized in one place
87
74
88
75
### How It Works
89
76
90
-
1.**Initialization**: Disabled services are communicated to the server via:
91
-
- Command-line arguments (stored in `LspArgs`)
92
-
- IDE configuration (sent via `workspace/configuration` request)
77
+
1.**Initialization**: Disabled services are passed via command-line arguments (stored in `LspArgs`)
93
78
94
79
2.**Capability Negotiation**: The server's `capabilities` function checks disabled services and omits them from the advertised capabilities during LSP initialization.
95
80
96
-
3.**Runtime Checks**: For services that are disabled via IDE configuration after initialization, the server performs runtime checks before processing requests.
81
+
3.**Service Availability**: Once capabilities are negotiated, clients will not request disabled services since they are not advertised.
97
82
98
83
## Use Cases
99
84
@@ -103,10 +88,11 @@ If you're working on a very large codebase and find that certain language servic
103
88
104
89
```json
105
90
{
106
-
"python.pyrefly.disabledLanguageServices": {
107
-
"references": true,
108
-
"workspaceSymbol": true
109
-
}
91
+
"pyrefly.lspArguments": [
92
+
"lsp",
93
+
"--disable-references",
94
+
"--disable-workspace-symbol"
95
+
]
110
96
}
111
97
```
112
98
@@ -116,10 +102,11 @@ If you're using multiple language servers and want to use Pyrefly for type check
116
102
117
103
```json
118
104
{
119
-
"python.pyrefly.disabledLanguageServices": {
120
-
"completion": true,
121
-
"hover": true
122
-
}
105
+
"pyrefly.lspArguments": [
106
+
"lsp",
107
+
"--disable-completion",
108
+
"--disable-hover"
109
+
]
123
110
}
124
111
```
125
112
@@ -129,34 +116,28 @@ For a minimal setup with only type checking and go-to-definition:
129
116
130
117
```json
131
118
{
132
-
"python.pyrefly.disabledLanguageServices": {
133
-
"hover": true,
134
-
"completion": true,
135
-
"signatureHelp": true,
136
-
"documentHighlight": true,
137
-
"documentSymbol": true,
138
-
"workspaceSymbol": true,
139
-
"semanticTokens": true,
140
-
"inlayHint": true
141
-
}
119
+
"pyrefly.lspArguments": [
120
+
"lsp",
121
+
"--disable-hover",
122
+
"--disable-completion",
123
+
"--disable-signature-help",
124
+
"--disable-document-highlight",
125
+
"--disable-document-symbol",
126
+
"--disable-workspace-symbol",
127
+
"--disable-semantic-tokens",
128
+
"--disable-inlay-hint"
129
+
]
142
130
}
143
131
```
144
132
145
-
## Backward Compatibility
146
-
147
-
The existing `python.pyrefly.disableLanguageServices` (plural, present tense) boolean setting still works and will disable **all** language services when set to `true`.
148
-
149
-
The new `python.pyrefly.disabledLanguageServices` (past tense) object allows for selective disabling of individual services. Both settings are fully backward compatible and can be used independently or together.
150
-
151
133
## Testing
152
134
153
-
The implementation includes comprehensive tests to ensure:
154
-
- Individual services can be disabled independently
155
-
- Other services continue to work when one is disabled
156
-
- Configuration changes are applied correctly
157
-
- Command-line arguments work as expected
135
+
The implementation includes tests to ensure:
136
+
- Command-line arguments are correctly parsed
137
+
- Disabled services are omitted from capabilities
138
+
- The LSP server functions correctly with services disabled
158
139
159
140
Run tests with:
160
141
```bash
161
-
cargo test --package pyrefly --lib test::lsp::lsp_interaction::configuration
Copy file name to clipboardExpand all lines: lsp/package.json
-72Lines changed: 0 additions & 72 deletions
Original file line number
Diff line number
Diff line change
@@ -77,78 +77,6 @@
77
77
"default": false,
78
78
"description": "If true, pyrefly will not provide other IDE services like completions, hover, definition, etc. To control type errors, see `python.pyrefly.displayTypeErrors`"
79
79
},
80
-
"python.pyrefly.disabledLanguageServices": {
81
-
"type": "object",
82
-
"default": {},
83
-
"description": "Selectively disable individual language services",
"description": "If 'default', Pyrefly will only provide type check squiggles in the IDE if your file is covered by a Pyrefly configuration. If 'force-off', Pyrefly will never provide type check squiggles in the IDE. If 'force-on', Pyrefly will always provide type check squiggles in the IDE.",
0 commit comments