Skip to content

Commit 729ec23

Browse files
committed
Don't include comment sections in workspace symbols by default
1 parent 816b260 commit 729ec23

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

crates/ark/src/lsp/config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,22 @@ pub static SETTINGS: &[Setting] = &[
6262
.unwrap_or_else(|| SymbolsConfig::default().include_assignments_in_blocks)
6363
},
6464
},
65+
Setting {
66+
key: "positron.r.workspaceSymbols.includeCommentSections",
67+
set: |cfg, v| {
68+
cfg.workspace_symbols.include_comment_sections = v
69+
.as_bool()
70+
.unwrap_or_else(|| WorkspaceSymbolsConfig::default().include_comment_sections)
71+
},
72+
},
6573
];
6674

6775
/// Configuration of the LSP
6876
#[derive(Clone, Default, Debug)]
6977
pub(crate) struct LspConfig {
7078
pub(crate) diagnostics: DiagnosticsConfig,
7179
pub(crate) symbols: SymbolsConfig,
80+
pub(crate) workspace_symbols: WorkspaceSymbolsConfig,
7281
pub(crate) document: DocumentConfig,
7382
}
7483

@@ -78,6 +87,12 @@ pub struct SymbolsConfig {
7887
pub include_assignments_in_blocks: bool,
7988
}
8089

90+
#[derive(Serialize, Deserialize, Clone, Debug)]
91+
pub struct WorkspaceSymbolsConfig {
92+
/// Whether to include sections like `# My section ---` in workspace symbols.
93+
pub include_comment_sections: bool,
94+
}
95+
8196
/// Configuration of a document.
8297
///
8398
/// The naming follows <https://editorconfig.org/> where possible.
@@ -141,6 +156,14 @@ impl Default for SymbolsConfig {
141156
}
142157
}
143158

159+
impl Default for WorkspaceSymbolsConfig {
160+
fn default() -> Self {
161+
Self {
162+
include_comment_sections: false,
163+
}
164+
}
165+
}
166+
144167
impl Default for IndentationConfig {
145168
fn default() -> Self {
146169
Self {

crates/ark/src/lsp/handlers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ pub(crate) async fn handle_initialized(
124124
#[tracing::instrument(level = "info", skip_all)]
125125
pub(crate) fn handle_symbol(
126126
params: WorkspaceSymbolParams,
127+
state: &WorldState,
127128
) -> anyhow::Result<Option<Vec<SymbolInformation>>> {
128-
symbols::symbols(&params)
129+
symbols::symbols(&params, state)
129130
.map(|res| Some(res))
130131
.or_else(|err| {
131132
// 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: 18 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,18 +84,21 @@ 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
},
101+
96102
IndexEntryData::Variable { name } => {
97103
info.push(SymbolInformation {
98104
name: name.clone(),

0 commit comments

Comments
 (0)