From dd2df1a0f2d9431c48963e7b58c43a5993057646 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 11 Dec 2024 12:32:48 +0100 Subject: [PATCH] lsp: Fix Hover hint containing paths on windows --- tools/lsp/language/hover.rs | 29 +++++++++++++++++++++++++---- tools/lsp/language/token_info.rs | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/lsp/language/hover.rs b/tools/lsp/language/hover.rs index f10e0f38790..9ee966b3af5 100644 --- a/tools/lsp/language/hover.rs +++ b/tools/lsp/language/hover.rs @@ -163,7 +163,10 @@ export component Test { row-pointer-event => { } } Image { - source: @image-url("test.png") + source: @image-url("assets/unix-test.png"); + } + Image { + source: @image-url("assets\\windows-test.png"); } }"#; let (mut dc, uri, _) = crate::language::test::loaded_document_cache(source.into()); @@ -269,10 +272,28 @@ export component Test { ); // @image-url - let target_path = - uri.join("test.png").unwrap().to_file_path().unwrap().to_string_lossy().to_string(); + let target_path = uri + .join("assets/unix-test.png") + .unwrap() + .to_file_path() + .unwrap() + .to_string_lossy() + .to_string(); + assert_tooltip( + get_tooltip(&mut dc, find_tk("\"assets/unix-test.png\"", 15.into())), + &format!("![{target_path}]({target_path})"), + ); + + // @image-url + let target_path = uri + .join("assets/windows-test.png") + .unwrap() + .to_file_path() + .unwrap() + .to_string_lossy() + .to_string(); assert_tooltip( - get_tooltip(&mut dc, find_tk("@image-url(", 15.into())), + get_tooltip(&mut dc, find_tk("\"assets\\\\windows-test.png\"", 15.into())), &format!("![{target_path}]({target_path})"), ); diff --git a/tools/lsp/language/token_info.rs b/tools/lsp/language/token_info.rs index 4486ac76472..a49d10fdd64 100644 --- a/tools/lsp/language/token_info.rs +++ b/tools/lsp/language/token_info.rs @@ -34,7 +34,7 @@ pub fn token_info(document_cache: &mut DocumentCache, token: SyntaxToken) -> Opt let path = i_slint_compiler::literals::unescape_string(token.text())?; let path = token.source_file.path().parent().map(|p| p.to_path_buf())?.join(path); - return Some(TokenInfo::Image(path)); + return Some(TokenInfo::Image(clean_path(&path))); } loop {