From de983979c40b64660ba7a904b92e8a47cf21ee3d Mon Sep 17 00:00:00 2001 From: ef3d0c3e Date: Sun, 1 Dec 2024 14:18:38 +0100 Subject: [PATCH] Fix bug with lists --- src/elements/list.rs | 28 ++++++++++++++-------------- src/elements/section.rs | 2 +- src/lsp/definition.rs | 5 +++-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/elements/list.rs b/src/elements/list.rs index 17781c6..b24d8a5 100644 --- a/src/elements/list.rs +++ b/src/elements/list.rs @@ -340,6 +340,20 @@ impl Rule for ListRule { } } + if let Some(hints) = + Hints::from_source(cursor.source.clone(), &state.shared.lsp) + { + let mut label = String::new(); + for (_, id) in &depth + { + if !label.is_empty() { + label.push('.'); + } + label.push_str(id.to_string().as_str()); + } + hints.add(captures.get(1).unwrap().end(), label); + } + // Content let entry_start = captures.get(3).unwrap().start(); let mut entry_content = captures.get(3).unwrap().as_str().to_string(); @@ -396,20 +410,6 @@ impl Rule for ListRule { ListRule::push_markers(&token, state, document, &vec![], &depth); } - if let Some(hints) = - Hints::from_source(token.source(), &state.shared.lsp) - { - let mut label = String::new(); - for (_, id) in &depth - { - if !label.is_empty() { - label.push('.'); - } - label.push_str(id.to_string().as_str()); - } - hints.add(captures.get(1).unwrap().end(), label); - } - state.push( document, Box::new(ListEntry { diff --git a/src/elements/section.rs b/src/elements/section.rs index 1c4fee9..6c3ad02 100644 --- a/src/elements/section.rs +++ b/src/elements/section.rs @@ -590,7 +590,7 @@ nml.section.push("6", 6, "", "refname") section_name { delta_line == 0, delta_start == 1 }; section_heading { delta_line == 1, delta_start == 0, length == 2 }; - section_reference { delta_line == 0, delta_start == 2, length == 3 }; + section_reference { delta_line == 0, delta_start == 2, length == 4 }; section_kind { delta_line == 0, delta_start == 4, length == 1 }; section_name { delta_line == 0, delta_start == 1 }; diff --git a/src/lsp/definition.rs b/src/lsp/definition.rs index 5e2a871..6dd961b 100644 --- a/src/lsp/definition.rs +++ b/src/lsp/definition.rs @@ -1,3 +1,4 @@ +use std::borrow::BorrowMut; use std::cell::RefCell; use std::rc::Rc; @@ -53,9 +54,9 @@ fn from_source_impl( return from_source_impl(location.source(), target, lsp, original); } else if let Ok(sourcefile) = source.downcast_rc::() { let borrow = lsp.as_ref().unwrap().borrow(); - let definitions = borrow.definitions.get(&original.source()).unwrap(); - let mut db = definitions.definitions.borrow_mut(); + if let Some(def_data) = borrow.definitions.get(&original.source()) { + let mut db = def_data.definitions.borrow_mut(); let token = original.source().original_range(original.range).1; // Resolve target