Skip to content

Commit 5eece7a

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

File tree

2 files changed

+97
-21
lines changed

2 files changed

+97
-21
lines changed

pyrefly/lib/lsp/non_wasm/server.rs

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ use crate::lsp::non_wasm::queue::HeavyTaskQueue;
187187
use crate::lsp::non_wasm::queue::LspEvent;
188188
use crate::lsp::non_wasm::queue::LspQueue;
189189
use crate::lsp::non_wasm::transaction_manager::TransactionManager;
190+
use crate::lsp::non_wasm::workspace::DisabledLanguageServicesConfig;
190191
use crate::lsp::non_wasm::workspace::LspAnalysisConfig;
191192
use crate::lsp::non_wasm::workspace::Workspace;
192193
use crate::lsp::non_wasm::workspace::Workspaces;
@@ -853,17 +854,28 @@ impl Server {
853854
if let Some(params) = self
854855
.extract_request_params_or_send_err_response::<HoverRequest>(params, &x.id)
855856
{
856-
let default_response = Hover {
857-
contents: HoverContents::Array(Vec::new()),
858-
range: None,
859-
};
860-
let transaction =
861-
ide_transaction_manager.non_committable_transaction(&self.state);
862-
self.send_response(new_response(
863-
x.id,
864-
Ok(self.hover(&transaction, params).unwrap_or(default_response)),
865-
));
866-
ide_transaction_manager.save(transaction);
857+
// Check if hover is disabled
858+
if self.is_service_disabled(&params.text_document_position_params.text_document.uri, |d| d.hover.unwrap_or(false)) {
859+
self.send_response(new_response(
860+
x.id,
861+
Ok(Hover {
862+
contents: HoverContents::Array(Vec::new()),
863+
range: None,
864+
}),
865+
));
866+
} else {
867+
let default_response = Hover {
868+
contents: HoverContents::Array(Vec::new()),
869+
range: None,
870+
};
871+
let transaction =
872+
ide_transaction_manager.non_committable_transaction(&self.state);
873+
self.send_response(new_response(
874+
x.id,
875+
Ok(self.hover(&transaction, params).unwrap_or(default_response)),
876+
));
877+
ide_transaction_manager.save(transaction);
878+
}
867879
}
868880
} else if let Some(params) = as_request::<InlayHintRequest>(&x) {
869881
if let Some(params) = self
@@ -925,16 +937,24 @@ impl Server {
925937
params, &x.id,
926938
)
927939
{
928-
let transaction =
929-
ide_transaction_manager.non_committable_transaction(&self.state);
930-
self.send_response(new_response(
931-
x.id,
932-
Ok(DocumentSymbolResponse::Nested(
933-
self.hierarchical_document_symbols(&transaction, params)
934-
.unwrap_or_default(),
935-
)),
936-
));
937-
ide_transaction_manager.save(transaction);
940+
// Check if document symbols are disabled
941+
if self.is_service_disabled(&params.text_document.uri, |d| d.document_symbol.unwrap_or(false)) {
942+
self.send_response(new_response(
943+
x.id,
944+
Ok(DocumentSymbolResponse::Nested(Vec::new())),
945+
));
946+
} else {
947+
let transaction =
948+
ide_transaction_manager.non_committable_transaction(&self.state);
949+
self.send_response(new_response(
950+
x.id,
951+
Ok(DocumentSymbolResponse::Nested(
952+
self.hierarchical_document_symbols(&transaction, params)
953+
.unwrap_or_default(),
954+
)),
955+
));
956+
ide_transaction_manager.save(transaction);
957+
}
938958
}
939959
} else if let Some(params) = as_request::<WorkspaceSymbolRequest>(&x) {
940960
if let Some(params) = self
@@ -1688,6 +1708,22 @@ impl Server {
16881708
.map(|(handle, _)| handle)
16891709
}
16901710

1711+
/// Check if a specific language service is disabled for the given URI
1712+
fn is_service_disabled(&self, uri: &Url, service_check: impl Fn(&DisabledLanguageServicesConfig) -> bool) -> bool {
1713+
let path = uri.to_file_path().unwrap();
1714+
self.workspaces.get_with(path, |(_, workspace)| {
1715+
// First check the global disable_language_services flag
1716+
if workspace.disable_language_services {
1717+
return true;
1718+
}
1719+
// Then check if this specific service is disabled
1720+
if let Some(disabled_services) = &workspace.disabled_language_services {
1721+
return service_check(disabled_services);
1722+
}
1723+
false
1724+
})
1725+
}
1726+
16911727
fn goto_definition(
16921728
&self,
16931729
transaction: &Transaction<'_>,

pyrefly/lib/lsp/non_wasm/workspace.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub struct Workspace {
6060
python_info: Option<PythonInfo>,
6161
search_path: Option<Vec<PathBuf>>,
6262
pub disable_language_services: bool,
63+
pub disabled_language_services: Option<DisabledLanguageServicesConfig>,
6364
pub display_type_errors: Option<DisplayTypeErrors>,
6465
pub lsp_analysis_config: Option<LspAnalysisConfig>,
6566
}
@@ -152,11 +153,30 @@ impl WeakConfigCache {
152153
}
153154
}
154155

156+
#[derive(Debug, Default, Deserialize, Clone)]
157+
#[serde(rename_all = "camelCase")]
158+
pub struct DisabledLanguageServicesConfig {
159+
pub definition: Option<bool>,
160+
pub type_definition: Option<bool>,
161+
pub code_action: Option<bool>,
162+
pub completion: Option<bool>,
163+
pub document_highlight: Option<bool>,
164+
pub references: Option<bool>,
165+
pub rename: Option<bool>,
166+
pub signature_help: Option<bool>,
167+
pub hover: Option<bool>,
168+
pub inlay_hint: Option<bool>,
169+
pub document_symbol: Option<bool>,
170+
pub workspace_symbol: Option<bool>,
171+
pub semantic_tokens: Option<bool>,
172+
}
173+
155174
#[derive(Debug, Default, Deserialize)]
156175
#[serde(rename_all = "camelCase")]
157176
struct PyreflyClientConfig {
158177
display_type_errors: Option<DisplayTypeErrors>,
159178
disable_language_services: Option<bool>,
179+
disabled_language_services: Option<DisabledLanguageServicesConfig>,
160180
extra_paths: Option<Vec<PathBuf>>,
161181
}
162182

@@ -289,6 +309,9 @@ impl Workspaces {
289309
if let Some(disable_language_services) = pyrefly.disable_language_services {
290310
self.update_disable_language_services(scope_uri, disable_language_services);
291311
}
312+
if let Some(disabled_services) = pyrefly.disabled_language_services {
313+
self.update_disabled_language_services(scope_uri, disabled_services);
314+
}
292315
self.update_display_type_errors(modified, scope_uri, pyrefly.display_type_errors);
293316
}
294317
if let Some(analysis) = config.analysis {
@@ -313,6 +336,23 @@ impl Workspaces {
313336
}
314337
}
315338

339+
/// Update disabled language services configuration for scope_uri, None if default workspace
340+
fn update_disabled_language_services(
341+
&self,
342+
scope_uri: &Option<Url>,
343+
disabled_services: DisabledLanguageServicesConfig,
344+
) {
345+
let mut workspaces = self.workspaces.write();
346+
match scope_uri {
347+
Some(scope_uri) => {
348+
if let Some(workspace) = workspaces.get_mut(&scope_uri.to_file_path().unwrap()) {
349+
workspace.disabled_language_services = Some(disabled_services);
350+
}
351+
}
352+
None => self.default.write().disabled_language_services = Some(disabled_services),
353+
}
354+
}
355+
316356
/// Update typeCheckingMode setting for scope_uri, None if default workspace
317357
fn update_display_type_errors(
318358
&self,

0 commit comments

Comments
 (0)