Fix mapping system #115
This commit is contained in:
@@ -93,12 +93,12 @@ fn clean_lsp_url(path: &std::path::Path) -> Option<Url> {
|
||||
}
|
||||
|
||||
fn lsp_pos_to_rust_map(pos: &Position) -> RustMap {
|
||||
RustMap(pos.line as usize + 1, pos.character as usize)
|
||||
RustMap(pos.line as usize, pos.character as usize)
|
||||
}
|
||||
|
||||
fn mist_map_to_lsp_pos(map: &MistMap) -> Position {
|
||||
Position {
|
||||
line: map.0.saturating_sub(1) as u32,
|
||||
line: map.0 as u32,
|
||||
character: map.1 as u32,
|
||||
}
|
||||
}
|
||||
@@ -391,7 +391,7 @@ impl Backend {
|
||||
// Fallback: the source has a syntax error that prevents transpilation.
|
||||
// Use the last known working Rust content + mapping to inject the
|
||||
// marker at the nearest valid Rust position.
|
||||
let mist_target = MistMap(line as usize + 1, character as usize);
|
||||
let mist_target = MistMap(line as usize, character as usize);
|
||||
let mut rust_path = crate::from_mist_to_rust(mist_path.to_path_buf());
|
||||
if mist_path.file_name().and_then(|n| n.to_str()) == Some("package.mist") {
|
||||
rust_path.set_file_name("mod.rs");
|
||||
@@ -417,7 +417,7 @@ impl Backend {
|
||||
.map(|(rust, _)| *rust);
|
||||
|
||||
let (modified_rust, rust_pos) = if let Some(next_rust) = rust_next {
|
||||
let lsp_line = (next_rust.0 - 1) as u32;
|
||||
let lsp_line = next_rust.0 as u32;
|
||||
let lsp_col = next_rust.1 as u32;
|
||||
let modified = inject_marker_at(&last_content, lsp_line, lsp_col, &marker)?;
|
||||
let pos = find_marker_position(&modified, &marker)?;
|
||||
@@ -1869,7 +1869,7 @@ async fn handle_ra_notifications(
|
||||
character: if mist_end_pos.line == mist_start_pos.line {
|
||||
mist_end_pos.character.max(mist_start_pos.character + 1)
|
||||
} else {
|
||||
mist_end_pos.character.max(1)
|
||||
mist_end_pos.character.max(0)
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ impl RustCodegen {
|
||||
indent: 0,
|
||||
crates: HashMap::new(),
|
||||
mapping: Mapping::new(mist_path),
|
||||
position: RustMap(1, 0),
|
||||
position: RustMap(0, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ impl<T> GenSpanTranslation for Spanned<T> {
|
||||
fn gen_span(&self, cg: &mut RustCodegen) {
|
||||
cg.mapping
|
||||
.map
|
||||
.insert((cg.position, MistMap(self.line, self.column)));
|
||||
.insert((cg.position, MistMap(self.line, self.column - 1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,9 @@ pub bool build(Vec<String> mut args, PathBuf root)
|
||||
serde_json::from_str<rev_mapper::Mapping>(&map_str).expect("Failed to parse map file")
|
||||
});
|
||||
let mist_file = map.mist_path.strip_prefix(&root);
|
||||
let (_, rev_mapper::MistMap(line, column)) = map.find(&rev_mapper::RustMap(span.line_end, span.column_start)).unwrap_or_default();
|
||||
let rust_lookup = rev_mapper::RustMap(span.line_end - 1, span.column_start - 1);
|
||||
match map.find(&rust_lookup) {
|
||||
Some((_, rev_mapper::MistMap(line, column))) => {
|
||||
let mist_msg = MistDiagnosticMessage {
|
||||
message: format!("{}: {}",
|
||||
msg.message.message,
|
||||
@@ -83,6 +85,12 @@ pub bool build(Vec<String> mut args, PathBuf root)
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
diagnostics.push(MistDiagnostic::Rust(msg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Message::BuildFinished(finish)) => {
|
||||
@@ -110,8 +118,8 @@ pub void print_diagnostics(Vec<MistDiagnostic>& diagnostics)
|
||||
let line = get_line(&mut files, &msg);
|
||||
println!("\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}",
|
||||
msg.file_name,
|
||||
msg.line,
|
||||
msg.column,
|
||||
msg.line + 1,
|
||||
msg.column + 1,
|
||||
msg.message,
|
||||
line.unwrap_or_default(),)
|
||||
}
|
||||
@@ -119,8 +127,8 @@ pub void print_diagnostics(Vec<MistDiagnostic>& diagnostics)
|
||||
let line = get_line(&mut files, &msg);
|
||||
println!("\n{}:{}:{}\n \x1b[33mWarning\x1b[0m: {}\n\t{}",
|
||||
msg.file_name,
|
||||
msg.line,
|
||||
msg.column,
|
||||
msg.line + 1,
|
||||
msg.column + 1,
|
||||
msg.message,
|
||||
line.unwrap_or_default(),)
|
||||
}
|
||||
@@ -135,5 +143,5 @@ pub Option<String> get_line(HashMap<PathBuf, Vec<String>> mut& files, MistDiagno
|
||||
let lines = files.entry(src_path.clone()).or_insert_with(() => {
|
||||
fs::read_to_string(src_path).expect("Unable to read mist file").lines().into_iter().map(String::from).collect()
|
||||
});
|
||||
lines.get(msg.line - 1).map((v) => v.trim().to_string())
|
||||
lines.get(msg.line).map((v) => v.trim().to_string())
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ use std::{collections::HashSet, path::PathBuf};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Debug, Default, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
|
||||
Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
|
||||
)]
|
||||
pub struct MistMap(pub usize, pub usize);
|
||||
|
||||
#[derive(
|
||||
Debug, Default, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
|
||||
Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
|
||||
)]
|
||||
pub struct RustMap(pub usize, pub usize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user