Skip to content

Commit ac8e19b

Browse files
Copilotkv9898
andcommitted
Add VSCode extension configuration and tests for selective language service disabling
Co-authored-by: kv9898 <[email protected]>
1 parent 5eece7a commit ac8e19b

File tree

3 files changed

+129
-1
lines changed

3 files changed

+129
-1
lines changed

lsp/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,25 @@ to ensure your project is set up properly, see
2424
The following configuration options are IDE-specific and exposed as VSCode
2525
settings:
2626

27-
- `python.pyrefly.disableTypeErrors` [enum: default, force-on, force-off]: by
27+
- `python.pyrefly.displayTypeErrors` [enum: default, force-on, force-off]: by
2828
default, Pyrefly will only provide type errors in your project if a
2929
`pyrefly.toml` is present. Modify this setting to override the IDE
3030
diagnostics.
3131
- `python.pyrefly.disableLanguageServices` [boolean: false]: by default, Pyrefly
3232
will provide both type errors and other language features like go-to
3333
definition, intellisense, hover, etc. Enable this option to keep type errors
3434
from Pyrefly unchanged but use VSCode's Python extension for everything else.
35+
- `python.pyrefly.disabledLanguageServices` [object]: selectively disable
36+
individual language services. This is an object with boolean properties for
37+
each service: `definition`, `typeDefinition`, `codeAction`, `completion`,
38+
`documentHighlight`, `references`, `rename`, `signatureHelp`, `hover`,
39+
`inlayHint`, `documentSymbol`, `workspaceSymbol`, and `semanticTokens`.
40+
For example, to disable hover and document symbols:
41+
```json
42+
"python.pyrefly.disabledLanguageServices": {
43+
"hover": true,
44+
"documentSymbol": true
45+
}
46+
```
3547
- `pyrefly.lspPath` [string: '']: if your platform is not supported, you can
3648
build pyrefly from source and specify the binary here.

lsp/package.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,78 @@
7777
"default": false,
7878
"description": "If true, pyrefly will not provide other IDE services like completions, hover, definition, etc. To control type errors, see `python.pyrefly.displayTypeErrors`"
7979
},
80+
"python.pyrefly.disabledLanguageServices": {
81+
"type": "object",
82+
"default": {},
83+
"description": "Selectively disable individual language services",
84+
"properties": {
85+
"definition": {
86+
"type": "boolean",
87+
"default": false,
88+
"description": "Disable go-to-definition"
89+
},
90+
"typeDefinition": {
91+
"type": "boolean",
92+
"default": false,
93+
"description": "Disable go-to-type-definition"
94+
},
95+
"codeAction": {
96+
"type": "boolean",
97+
"default": false,
98+
"description": "Disable code actions (quick fixes)"
99+
},
100+
"completion": {
101+
"type": "boolean",
102+
"default": false,
103+
"description": "Disable completion (autocomplete)"
104+
},
105+
"documentHighlight": {
106+
"type": "boolean",
107+
"default": false,
108+
"description": "Disable document highlight"
109+
},
110+
"references": {
111+
"type": "boolean",
112+
"default": false,
113+
"description": "Disable find references"
114+
},
115+
"rename": {
116+
"type": "boolean",
117+
"default": false,
118+
"description": "Disable rename"
119+
},
120+
"signatureHelp": {
121+
"type": "boolean",
122+
"default": false,
123+
"description": "Disable signature help (parameter hints)"
124+
},
125+
"hover": {
126+
"type": "boolean",
127+
"default": false,
128+
"description": "Disable hover (tooltips)"
129+
},
130+
"inlayHint": {
131+
"type": "boolean",
132+
"default": false,
133+
"description": "Disable inlay hints"
134+
},
135+
"documentSymbol": {
136+
"type": "boolean",
137+
"default": false,
138+
"description": "Disable document symbols (outline)"
139+
},
140+
"workspaceSymbol": {
141+
"type": "boolean",
142+
"default": false,
143+
"description": "Disable workspace symbols"
144+
},
145+
"semanticTokens": {
146+
"type": "boolean",
147+
"default": false,
148+
"description": "Disable semantic tokens"
149+
}
150+
}
151+
},
80152
"python.pyrefly.displayTypeErrors": {
81153
"type": "string",
82154
"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.",

pyrefly/lib/test/lsp/lsp_interaction/configuration.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,3 +825,47 @@ fn test_diagnostics_file_in_excludes() {
825825

826826
interaction.shutdown();
827827
}
828+
829+
#[test]
830+
fn test_selective_disable_hover() {
831+
let test_files_root = get_test_files_root();
832+
let scope_uri = Url::from_file_path(test_files_root.path()).unwrap();
833+
let mut interaction = LspInteraction::new();
834+
interaction.set_root(test_files_root.path().to_path_buf());
835+
interaction.initialize(InitializeSettings {
836+
workspace_folders: Some(vec![("test".to_owned(), scope_uri.clone())]),
837+
configuration: Some(None),
838+
..Default::default()
839+
});
840+
841+
interaction.server.did_open("foo.py");
842+
843+
// Now configure to disable hover
844+
interaction.server.did_change_configuration();
845+
846+
interaction
847+
.client
848+
.expect_configuration_request(2, Some(vec![&scope_uri]));
849+
interaction.server.send_configuration_response(
850+
2,
851+
serde_json::json!([{
852+
"pyrefly": {
853+
"disabledLanguageServices": {
854+
"hover": true
855+
}
856+
}
857+
}])
858+
);
859+
860+
// Test that hover is now disabled (returns empty response)
861+
interaction.server.hover("foo.py", 6, 16);
862+
interaction.client.expect_response(Response {
863+
id: RequestId::from(2),
864+
result: Some(serde_json::json!({
865+
"contents": []
866+
})),
867+
error: None,
868+
});
869+
870+
interaction.shutdown();
871+
}

0 commit comments

Comments
 (0)