From 1b5f0d833f6d233a637fc418552eca359dd9d5d0 Mon Sep 17 00:00:00 2001 From: Goulven Clec'h Date: Thu, 19 Dec 2024 19:07:29 +0100 Subject: [PATCH] fix review --- .../csslsrs/src/features/document_symbols.rs | 1 + crates/csslsrs/tests/document_symbols.rs | 123 ++++++++++++++++++ 2 files changed, 124 insertions(+) diff --git a/crates/csslsrs/src/features/document_symbols.rs b/crates/csslsrs/src/features/document_symbols.rs index 41d8688..934cd10 100644 --- a/crates/csslsrs/src/features/document_symbols.rs +++ b/crates/csslsrs/src/features/document_symbols.rs @@ -36,6 +36,7 @@ fn extract_document_symbols( Range::new( position( line_index, + // We need to include the `@` symbol in the selection range. token.text_trimmed_range().start() - TextSize::from(1), encoding, ) diff --git a/crates/csslsrs/tests/document_symbols.rs b/crates/csslsrs/tests/document_symbols.rs index ff81700..ad91f38 100644 --- a/crates/csslsrs/tests/document_symbols.rs +++ b/crates/csslsrs/tests/document_symbols.rs @@ -606,3 +606,126 @@ fn test_css_variables() { ], ); } + +#[test] +fn test_at_rule_with_nested_properties() { + let mut ls = LanguageService::default(); + + assert_document_symbols( + &mut ls, + "@font-palette-values --my-palette {\n font-family: Bixa;\n base-palette: 1;\n override-colors: 0 #ff0000;\n}", + vec![DocumentSymbol { + name: "@font-palette-values".to_string(), + detail: None, + kind: SymbolKind::NAMESPACE, + tags: None, + deprecated: None, + range: Range { + start: Position { + line: 0, + character: 0, + }, + end: Position { + line: 4, + character: 1, + }, + }, + selection_range: Range { + start: Position { + line: 0, + character: 0, + }, + end: Position { + line: 0, + character: 20, + }, + }, + children: Some(vec![ + DocumentSymbol { + name: "font-family".to_string(), + detail: None, + kind: SymbolKind::PROPERTY, + tags: None, + deprecated: None, + range: Range { + start: Position { + line: 1, + character: 2, + }, + end: Position { + line: 1, + character: 19, + }, + }, + selection_range: Range { + start: Position { + line: 1, + character: 2, + }, + end: Position { + line: 1, + character: 13, + }, + }, + children: None, + }, + DocumentSymbol { + name: "base-palette".to_string(), + detail: None, + kind: SymbolKind::PROPERTY, + tags: None, + deprecated: None, + range: Range { + start: Position { + line: 2, + character: 2, + }, + end: Position { + line: 2, + character: 17, + }, + }, + selection_range: Range { + start: Position { + line: 2, + character: 2, + }, + end: Position { + line: 2, + character: 14, + }, + }, + children: None, + }, + DocumentSymbol { + name: "override-colors".to_string(), + detail: None, + kind: SymbolKind::PROPERTY, + tags: None, + deprecated: None, + range: Range { + start: Position { + line: 3, + character: 2, + }, + end: Position { + line: 3, + character: 28, + }, + }, + selection_range: Range { + start: Position { + line: 3, + character: 2, + }, + end: Position { + line: 3, + character: 17, + }, + }, + children: None, + }, + ]), + }], + ); +}