Skip to content

Don't emit nested objects as document symbols #859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions crates/ark/src/lsp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ use crate::lsp;
use crate::lsp::diagnostics::DiagnosticsConfig;

/// Configuration of the LSP
#[derive(Clone, Debug)]
#[derive(Clone, Default, Debug)]
pub(crate) struct LspConfig {
pub(crate) diagnostics: DiagnosticsConfig,
pub(crate) symbols: SymbolsConfig,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SymbolsConfig {
/// Whether to emit assignments in `{` bloks as document symbols.
pub include_assignments_in_blocks: bool,
}

/// Configuration of a document.
Expand Down Expand Up @@ -53,17 +60,23 @@ pub(crate) struct VscDiagnosticsConfig {
pub enable: bool,
}

#[derive(Serialize, Deserialize, FieldNamesAsArray, Clone, Debug)]
pub(crate) struct VscSymbolsConfig {
// DEV NOTE: Update `section_from_key()` method after adding a field
pub include_assignments_in_blocks: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(untagged)]
pub(crate) enum VscIndentSize {
Alias(String),
Size(usize),
}

impl Default for LspConfig {
impl Default for SymbolsConfig {
fn default() -> Self {
Self {
diagnostics: Default::default(),
include_assignments_in_blocks: false,
}
}
}
Expand Down Expand Up @@ -134,6 +147,23 @@ impl From<VscDiagnosticsConfig> for DiagnosticsConfig {
}
}

impl VscSymbolsConfig {
pub(crate) fn section_from_key(key: &str) -> &str {
match key {
"include_assignments_in_blocks" => "positron.r.symbols.includeAssignmentsInBlocks",
_ => "unknown", // To be caught via downstream errors
}
}
}

impl From<VscSymbolsConfig> for SymbolsConfig {
fn from(value: VscSymbolsConfig) -> Self {
Self {
include_assignments_in_blocks: value.include_assignments_in_blocks,
}
}
}

pub(crate) fn indent_style_from_lsp(insert_spaces: bool) -> IndentStyle {
if insert_spaces {
IndentStyle::Space
Expand Down
6 changes: 6 additions & 0 deletions crates/ark/src/lsp/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use crate::lsp::completions::provide_completions;
use crate::lsp::completions::resolve_completion;
use crate::lsp::config::VscDiagnosticsConfig;
use crate::lsp::config::VscDocumentConfig;
use crate::lsp::config::VscSymbolsConfig;
use crate::lsp::definitions::goto_definition;
use crate::lsp::document_context::DocumentContext;
use crate::lsp::encoding::convert_lsp_range_to_tree_sitter_range;
Expand Down Expand Up @@ -109,12 +110,17 @@ pub(crate) async fn handle_initialized(
VscDocumentConfig::FIELD_NAMES_AS_ARRAY.to_vec(),
VscDocumentConfig::section_from_key,
);
let mut config_symbols_regs: Vec<Registration> = collect_regs(
VscSymbolsConfig::FIELD_NAMES_AS_ARRAY.to_vec(),
VscSymbolsConfig::section_from_key,
);
let mut config_diagnostics_regs: Vec<Registration> = collect_regs(
VscDiagnosticsConfig::FIELD_NAMES_AS_ARRAY.to_vec(),
VscDiagnosticsConfig::section_from_key,
);

regs.append(&mut config_document_regs);
regs.append(&mut config_symbols_regs);
regs.append(&mut config_diagnostics_regs);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
source: crates/ark/src/lsp/symbols.rs
expression: "test_symbol(\"foo <- function() { bar <- function() 1 }\")"
---
[
DocumentSymbol {
name: "foo",
detail: Some(
"function()",
),
kind: Function,
tags: None,
deprecated: None,
range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 0,
character: 41,
},
},
selection_range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 0,
character: 41,
},
},
children: Some(
[
DocumentSymbol {
name: "bar",
detail: Some(
"function()",
),
kind: Function,
tags: None,
deprecated: None,
range: Range {
start: Position {
line: 0,
character: 20,
},
end: Position {
line: 0,
character: 39,
},
},
selection_range: Range {
start: Position {
line: 0,
character: 20,
},
end: Position {
line: 0,
character: 39,
},
},
children: Some(
[],
),
},
],
),
},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
source: crates/ark/src/lsp/symbols.rs
expression: "test_symbol(\"\nlocal({\n inner1 <- 1 # Not a symbol\n})\na <- function() {\n inner2 <- 2 # Not a symbol\n inner3 <- function() 3 # Symbol\n}\n\")"
---
[
DocumentSymbol {
name: "a",
detail: Some(
"function()",
),
kind: Function,
tags: None,
deprecated: None,
range: Range {
start: Position {
line: 4,
character: 0,
},
end: Position {
line: 7,
character: 1,
},
},
selection_range: Range {
start: Position {
line: 4,
character: 0,
},
end: Position {
line: 7,
character: 1,
},
},
children: Some(
[
DocumentSymbol {
name: "inner3",
detail: Some(
"function()",
),
kind: Function,
tags: None,
deprecated: None,
range: Range {
start: Position {
line: 6,
character: 2,
},
end: Position {
line: 6,
character: 24,
},
},
selection_range: Range {
start: Position {
line: 6,
character: 2,
},
end: Position {
line: 6,
character: 24,
},
},
children: Some(
[],
),
},
],
),
},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
source: crates/ark/src/lsp/symbols.rs
expression: symbols
---
[
DocumentSymbol {
name: "inner1",
detail: None,
kind: Variable,
tags: None,
deprecated: None,
range: Range {
start: Position {
line: 2,
character: 2,
},
end: Position {
line: 2,
character: 8,
},
},
selection_range: Range {
start: Position {
line: 2,
character: 2,
},
end: Position {
line: 2,
character: 8,
},
},
children: Some(
[],
),
},
DocumentSymbol {
name: "a",
detail: Some(
"function()",
),
kind: Function,
tags: None,
deprecated: None,
range: Range {
start: Position {
line: 4,
character: 0,
},
end: Position {
line: 7,
character: 1,
},
},
selection_range: Range {
start: Position {
line: 4,
character: 0,
},
end: Position {
line: 7,
character: 1,
},
},
children: Some(
[
DocumentSymbol {
name: "inner2",
detail: None,
kind: Variable,
tags: None,
deprecated: None,
range: Range {
start: Position {
line: 5,
character: 2,
},
end: Position {
line: 5,
character: 8,
},
},
selection_range: Range {
start: Position {
line: 5,
character: 2,
},
end: Position {
line: 5,
character: 8,
},
},
children: Some(
[],
),
},
DocumentSymbol {
name: "inner3",
detail: Some(
"function()",
),
kind: Function,
tags: None,
deprecated: None,
range: Range {
start: Position {
line: 6,
character: 2,
},
end: Position {
line: 6,
character: 24,
},
},
selection_range: Range {
start: Position {
line: 6,
character: 2,
},
end: Position {
line: 6,
character: 24,
},
},
children: Some(
[],
),
},
],
),
},
]
Loading
Loading