From c48402c5448eb642e78a644a9ac479ff487a58de Mon Sep 17 00:00:00 2001 From: Jonatan Waern Date: Wed, 25 Feb 2026 16:56:18 +0100 Subject: [PATCH] Fix double-output of document symbols that are scopes Signed-off-by: Jonatan Waern --- CHANGELOG.md | 2 ++ src/actions/requests.rs | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eac311..661eed6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ - The DLS will now correctly report missing template names in 'in each' constructs - Fixed error where the DLS would fail to match references from within in a template to symbols defined in parents of objects instantiating the template +- Fixed an issue where the DLS document and workspace symbol request would + double-report symbols that contain other symbols (methods, templates, objects) ## 0.9.17 - Fixed linter wrongly throwing an error on space after `defined` keyword diff --git a/src/actions/requests.rs b/src/actions/requests.rs index b4e2f65..2d8c252 100644 --- a/src/actions/requests.rs +++ b/src/actions/requests.rs @@ -213,6 +213,18 @@ fn simplesymbol_to_workspace_symbol(parent_name: &str, } } +// Filter out the flat simplesymbols that will also be output as +// contexts +fn should_output_symbol_for_subsymbol(sym: &SubSymbol) -> bool { + match sym { + SubSymbol::Context(_) => true, + SubSymbol::Simple(simple) => !matches!(simple.kind(), + DMLSymbolKind::CompObject(_) + | DMLSymbolKind::Template + | DMLSymbolKind::Method), + } +} + fn context_to_document_symbol(context: &SymbolContext) -> DocumentSymbol { // Note: This is probably slightly inefficient for simple contexts, // but is unlikely to be a large problem @@ -230,6 +242,7 @@ fn context_to_document_symbol(context: &SymbolContext) -> DocumentSymbol { range: ls_util::dls_to_range(span.range), selection_range: ls_util::dls_to_range(loc.range), children: Some(context.subsymbols.iter() + .filter(|subsymbol|should_output_symbol_for_subsymbol(subsymbol)) .map(subsymbol_to_document_symbol) .collect()), } @@ -259,6 +272,9 @@ fn context_to_workspace_symbols_aux(context: &SymbolContext, }); for child in &context.subsymbols { + if !should_output_symbol_for_subsymbol(child) { + continue; + } match child { SubSymbol::Context(con) => context_to_workspace_symbols_aux( con, Some(&full_name), symbols), @@ -333,8 +349,9 @@ impl RequestAction for DocumentSymbolRequest { .map(|isolated|{ let context = isolated.toplevel.to_context(); // Fold out the toplevel context - let symbols = context.subsymbols.iter().map( - subsymbol_to_document_symbol).collect(); + let symbols = context.subsymbols.iter() + .filter(|s|should_output_symbol_for_subsymbol(s)) + .map(subsymbol_to_document_symbol).collect(); Some(DocumentSymbolResponse::Nested(symbols)) }) .or(Self::fallback_response())