Skip to content

Commit 8450979

Browse files
committed
Don't include comment sections in workspace symbols by default
1 parent a4d669b commit 8450979

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

crates/ark/src/lsp/config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ pub static GLOBAL_SETTINGS: &[Setting<LspConfig>] = &[
3333
.unwrap_or_else(|| SymbolsConfig::default().include_assignments_in_blocks)
3434
},
3535
},
36+
Setting {
37+
key: "positron.r.workspaceSymbols.includeCommentSections",
38+
set: |cfg, v| {
39+
cfg.workspace_symbols.include_comment_sections = v
40+
.as_bool()
41+
.unwrap_or_else(|| WorkspaceSymbolsConfig::default().include_comment_sections)
42+
},
43+
},
3644
];
3745

3846
/// These document settings are updated on a URI basis. Each document has its
@@ -77,6 +85,7 @@ pub static DOCUMENT_SETTINGS: &[Setting<DocumentConfig>] = &[
7785
pub(crate) struct LspConfig {
7886
pub(crate) diagnostics: DiagnosticsConfig,
7987
pub(crate) symbols: SymbolsConfig,
88+
pub(crate) workspace_symbols: WorkspaceSymbolsConfig,
8089
}
8190

8291
#[derive(Serialize, Deserialize, Clone, Debug)]
@@ -85,6 +94,12 @@ pub struct SymbolsConfig {
8594
pub include_assignments_in_blocks: bool,
8695
}
8796

97+
#[derive(Serialize, Deserialize, Clone, Debug)]
98+
pub struct WorkspaceSymbolsConfig {
99+
/// Whether to include sections like `# My section ---` in workspace symbols.
100+
pub include_comment_sections: bool,
101+
}
102+
88103
/// Configuration of a document.
89104
///
90105
/// The naming follows <https://editorconfig.org/> where possible.
@@ -120,6 +135,14 @@ impl Default for SymbolsConfig {
120135
}
121136
}
122137

138+
impl Default for WorkspaceSymbolsConfig {
139+
fn default() -> Self {
140+
Self {
141+
include_comment_sections: false,
142+
}
143+
}
144+
}
145+
123146
impl Default for IndentationConfig {
124147
fn default() -> Self {
125148
Self {

crates/ark/src/lsp/handlers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ pub(crate) async fn handle_initialized(
129129
#[tracing::instrument(level = "info", skip_all)]
130130
pub(crate) fn handle_symbol(
131131
params: WorkspaceSymbolParams,
132+
state: &WorldState,
132133
) -> anyhow::Result<Option<Vec<SymbolInformation>>> {
133-
symbols::symbols(&params)
134+
symbols::symbols(&params, state)
134135
.map(|res| Some(res))
135136
.or_else(|err| {
136137
// Missing doc: Why are we not propagating errors to the frontend?

crates/ark/src/lsp/main_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl GlobalState {
281281
respond(tx, || state_handlers::initialize(params, &mut self.lsp_state, &mut self.world), LspResponse::Initialize)?;
282282
},
283283
LspRequest::WorkspaceSymbol(params) => {
284-
respond(tx, || handlers::handle_symbol(params), LspResponse::WorkspaceSymbol)?;
284+
respond(tx, || handlers::handle_symbol(params, &self.world), LspResponse::WorkspaceSymbol)?;
285285
},
286286
LspRequest::DocumentSymbol(params) => {
287287
respond(tx, || handlers::handle_document_symbol(params, &self.world), LspResponse::DocumentSymbol)?;

crates/ark/src/lsp/symbols.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ fn new_symbol_node(
5656
symbol
5757
}
5858

59-
pub fn symbols(params: &WorkspaceSymbolParams) -> anyhow::Result<Vec<SymbolInformation>> {
59+
pub(crate) fn symbols(
60+
params: &WorkspaceSymbolParams,
61+
state: &WorldState,
62+
) -> anyhow::Result<Vec<SymbolInformation>> {
6063
let query = &params.query;
6164
let mut info: Vec<SymbolInformation> = Vec::new();
6265

@@ -81,17 +84,19 @@ pub fn symbols(params: &WorkspaceSymbolParams) -> anyhow::Result<Vec<SymbolInfor
8184
},
8285

8386
IndexEntryData::Section { level: _, title } => {
84-
info.push(SymbolInformation {
85-
name: title.to_string(),
86-
kind: SymbolKind::STRING,
87-
location: Location {
88-
uri: Url::from_file_path(path).unwrap(),
89-
range: entry.range,
90-
},
91-
tags: None,
92-
deprecated: None,
93-
container_name: None,
94-
});
87+
if state.config.workspace_symbols.include_comment_sections {
88+
info.push(SymbolInformation {
89+
name: title.to_string(),
90+
kind: SymbolKind::STRING,
91+
location: Location {
92+
uri: Url::from_file_path(path).unwrap(),
93+
range: entry.range,
94+
},
95+
tags: None,
96+
deprecated: None,
97+
container_name: None,
98+
});
99+
}
95100
},
96101

97102
IndexEntryData::Variable { name } => {

0 commit comments

Comments
 (0)