Skip to content

Commit

Permalink
lsp: Fix Hover hint containing paths on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
hunger committed Dec 11, 2024
1 parent c794f87 commit dd2df1a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 25 additions & 4 deletions tools/lsp/language/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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})"),
);

Expand Down
2 changes: 1 addition & 1 deletion tools/lsp/language/token_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit dd2df1a

Please sign in to comment.