Skip to content

Commit 800dc70

Browse files
committed
Add test for comment sections in workspace symbols
1 parent f87b292 commit 800dc70

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

crates/ark/src/lsp/indexer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ fn clear(path: &Path) -> anyhow::Result<()> {
158158
Ok(())
159159
}
160160

161+
#[cfg(test)]
162+
pub(crate) fn indexer_clear() {
163+
let mut index = WORKSPACE_INDEX.lock().unwrap();
164+
index.clear();
165+
}
166+
161167
fn str_from_path(path: &Path) -> anyhow::Result<&str> {
162168
path.to_str().ok_or(anyhow!(
163169
"Couldn't convert path {} to string",

crates/ark/src/lsp/symbols.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ mod tests {
583583
use tower_lsp::lsp_types::Position;
584584

585585
use super::*;
586+
use crate::lsp::config::LspConfig;
587+
use crate::lsp::config::WorkspaceSymbolsConfig;
586588
use crate::lsp::documents::Document;
587589

588590
fn test_symbol(code: &str) -> Vec<DocumentSymbol> {
@@ -894,4 +896,41 @@ a <- function() {
894896

895897
insta::assert_debug_snapshot!(symbols);
896898
}
899+
900+
#[test]
901+
fn test_workspace_symbols_include_comment_sections() {
902+
fn run(include_comment_sections: bool) -> Vec<String> {
903+
let code = "# Section ----\nfoo <- 1";
904+
905+
let mut config = LspConfig::default();
906+
config.workspace_symbols = WorkspaceSymbolsConfig {
907+
include_comment_sections,
908+
};
909+
let mut state = WorldState::default();
910+
state.config = config;
911+
912+
// Index the document
913+
let doc = Document::new(code, None);
914+
indexer::update(&doc, std::path::Path::new("/test.R")).unwrap();
915+
916+
// Query for all symbols
917+
let params = WorkspaceSymbolParams {
918+
query: "Section".to_string(),
919+
..Default::default()
920+
};
921+
let result = super::symbols(&params, &state).unwrap();
922+
let out = result.into_iter().map(|s| s.name).collect();
923+
924+
indexer::indexer_clear();
925+
out
926+
}
927+
928+
// Should include section when true
929+
let with_sections = run(true);
930+
assert!(with_sections.contains(&"Section".to_string()));
931+
932+
// Should not include section when false
933+
let without_sections = run(false);
934+
assert!(!without_sections.contains(&"Section".to_string()));
935+
}
897936
}

0 commit comments

Comments
 (0)