From 34662e204952b5164b4e74ea402f27c69d1e864e Mon Sep 17 00:00:00 2001 From: ef3d0c3e Date: Thu, 5 Dec 2024 12:07:58 +0100 Subject: [PATCH] Fix bug in styles --- src/elements/customstyle.rs | 1 - src/elements/style.rs | 2 +- src/lsp/conceal.rs | 2 +- src/lsp/definition.rs | 1 - src/lsp/styles.rs | 14 +++++++------- src/parser/langparser.rs | 3 --- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/elements/customstyle.rs b/src/elements/customstyle.rs index 098219a..34c1683 100644 --- a/src/elements/customstyle.rs +++ b/src/elements/customstyle.rs @@ -14,7 +14,6 @@ use mlua::Function; use mlua::Lua; use crate::document::document::Document; -use crate::document::document::DocumentAccessors; use crate::lua::kernel::KernelContext; use crate::lua::kernel::CTX; use crate::parser::customstyle::CustomStyle; diff --git a/src/elements/style.rs b/src/elements/style.rs index 723125e..719c934 100644 --- a/src/elements/style.rs +++ b/src/elements/style.rs @@ -212,7 +212,7 @@ impl RegexRule for StyleRule { { 0 => styles.add(start.start()..token.end(), crate::lsp::styles::Style::Style("bold".into())), 1 => styles.add(start.start()..token.end(), crate::lsp::styles::Style::Style("italic".into())), - 2 => styles.add(start.start()..token.end(), crate::lsp::styles::Style::Style("underlined".into())), + 2 => styles.add(start.start()..token.end()-1, crate::lsp::styles::Style::Style("underlined".into())), _ => {}, } } diff --git a/src/lsp/conceal.rs b/src/lsp/conceal.rs index 5aecf5b..605050c 100644 --- a/src/lsp/conceal.rs +++ b/src/lsp/conceal.rs @@ -110,8 +110,8 @@ impl<'a> Conceals<'a> { pub fn add(&self, range: Range, text: ConcealTarget) { let range = self.original_source.original_range(range).1; let mut cursor = self.conceals.cursor.borrow_mut(); - cursor.move_to(range.start); + cursor.move_to(range.start); let line = cursor.line; let start_char = cursor.line_pos; diff --git a/src/lsp/definition.rs b/src/lsp/definition.rs index 6dd961b..b0cad44 100644 --- a/src/lsp/definition.rs +++ b/src/lsp/definition.rs @@ -1,4 +1,3 @@ -use std::borrow::BorrowMut; use std::cell::RefCell; use std::rc::Rc; diff --git a/src/lsp/styles.rs b/src/lsp/styles.rs index 99d3752..5641760 100644 --- a/src/lsp/styles.rs +++ b/src/lsp/styles.rs @@ -38,7 +38,7 @@ pub struct StylesData { } impl StylesData { - pub fn new(source: Rc) -> Self { + pub fn new(_source: Rc) -> Self { Self { styles: RefCell::new(vec![]), } @@ -99,24 +99,24 @@ impl<'a> Styles<'a> { pub fn add(&self, range: Range, style: Style) { let range = self.original_source.original_range(range).1; - let mut cursor = LineCursor::new(self.original_source.clone()); - cursor.move_to(range.start); + let mut cursor = LineCursor::new(self.source.clone()); - let line = cursor.line; + cursor.move_to(range.start); + let start_line = cursor.line; let start_char = cursor.line_pos; cursor.move_to(range.end); - assert_eq!(line, cursor.line); + let end_line = cursor.line; let end_char = cursor.line_pos; self.styles.styles.borrow_mut().push(StyleInfo { range: tower_lsp::lsp_types::Range { start: Position { - line: line as u32, + line: start_line as u32, character: start_char as u32, }, end: Position { - line: line as u32, + line: end_line as u32, character: end_char as u32, }, }, diff --git a/src/parser/langparser.rs b/src/parser/langparser.rs index 7c81dbe..a7eb95e 100644 --- a/src/parser/langparser.rs +++ b/src/parser/langparser.rs @@ -6,10 +6,7 @@ use crate::document::document::Document; use crate::document::element::DocumentEnd; use crate::document::langdocument::LangDocument; use crate::elements::text::Text; -use crate::lsp::definition::DefinitionData; -use crate::lsp::hints::HintsData; use crate::lsp::semantic::Semantics; -use crate::lsp::semantic::SemanticsData; use super::parser::ParseMode; use super::parser::Parser;