use super::*;
#[test]
fn sass_symbol_hover_renders_unopened_target_definition_from_disk() -> TestResult {
let workspace_path = std::env::temp_dir().join(format!(
"omena-lsp-disk-sass-hover-{}-{}",
std::process::id(),
current_time_millis()
));
let src_dir = workspace_path.join("src");
let source_style_path = src_dir.join("App.module.scss");
let token_style_path = src_dir.join("_tokens.scss");
fs::create_dir_all(src_dir.as_path())?;
fs::write(token_style_path.as_path(), "$brand: #fff;\n")?;
let workspace_uri = path_to_file_uri(workspace_path.as_path());
let source_style_uri = path_to_file_uri(source_style_path.as_path());
let source_style_text = "@use \"./tokens\" as *;\n.foo { color: $brand; }\n";
let mut state = LspShellState::default();
handle_lsp_message(
&mut state,
json!({
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"workspaceFolders": [
{
"uri": workspace_uri,
"name": "workspace",
},
],
},
}),
);
handle_lsp_message(
&mut state,
json!({
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"textDocument": {
"uri": source_style_uri,
"languageId": "scss",
"version": 1,
"text": source_style_text,
},
},
}),
);
let hover_response = handle_lsp_message(
&mut state,
json!({
"jsonrpc": "2.0",
"id": 2,
"method": "textDocument/hover",
"params": {
"textDocument": {
"uri": path_to_file_uri(source_style_path.as_path()),
},
"position": parser_position_for_byte_offset(
source_style_text,
fixture_find(
source_style_text,
"$brand",
"style fixture contains brand variable",
)? + 1,
),
},
}),
);
let hover_text = hover_response
.as_ref()
.and_then(|value| value.pointer("/result/contents/value"))
.and_then(Value::as_str)
.unwrap_or_default();
assert!(hover_text.contains("$brand: #fff"));
let _ = fs::remove_dir_all(workspace_path.as_path());
Ok(())
}