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 {
|
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 {
|
fn mist_map_to_lsp_pos(map: &MistMap) -> Position {
|
||||||
Position {
|
Position {
|
||||||
line: map.0.saturating_sub(1) as u32,
|
line: map.0 as u32,
|
||||||
character: map.1 as u32,
|
character: map.1 as u32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,7 +391,7 @@ impl Backend {
|
|||||||
// Fallback: the source has a syntax error that prevents transpilation.
|
// Fallback: the source has a syntax error that prevents transpilation.
|
||||||
// Use the last known working Rust content + mapping to inject the
|
// Use the last known working Rust content + mapping to inject the
|
||||||
// marker at the nearest valid Rust position.
|
// 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());
|
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") {
|
if mist_path.file_name().and_then(|n| n.to_str()) == Some("package.mist") {
|
||||||
rust_path.set_file_name("mod.rs");
|
rust_path.set_file_name("mod.rs");
|
||||||
@@ -417,7 +417,7 @@ impl Backend {
|
|||||||
.map(|(rust, _)| *rust);
|
.map(|(rust, _)| *rust);
|
||||||
|
|
||||||
let (modified_rust, rust_pos) = if let Some(next_rust) = rust_next {
|
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 lsp_col = next_rust.1 as u32;
|
||||||
let modified = inject_marker_at(&last_content, lsp_line, lsp_col, &marker)?;
|
let modified = inject_marker_at(&last_content, lsp_line, lsp_col, &marker)?;
|
||||||
let pos = find_marker_position(&modified, &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 {
|
character: if mist_end_pos.line == mist_start_pos.line {
|
||||||
mist_end_pos.character.max(mist_start_pos.character + 1)
|
mist_end_pos.character.max(mist_start_pos.character + 1)
|
||||||
} else {
|
} else {
|
||||||
mist_end_pos.character.max(1)
|
mist_end_pos.character.max(0)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ impl RustCodegen {
|
|||||||
indent: 0,
|
indent: 0,
|
||||||
crates: HashMap::new(),
|
crates: HashMap::new(),
|
||||||
mapping: Mapping::new(mist_path),
|
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) {
|
fn gen_span(&self, cg: &mut RustCodegen) {
|
||||||
cg.mapping
|
cg.mapping
|
||||||
.map
|
.map
|
||||||
.insert((cg.position, MistMap(self.line, self.column)));
|
.insert((cg.position, MistMap(self.line, self.column - 1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,28 +58,36 @@ pub bool build(Vec<String> mut args, PathBuf root)
|
|||||||
serde_json::from_str<rev_mapper::Mapping>(&map_str).expect("Failed to parse map file")
|
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 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);
|
||||||
let mist_msg = MistDiagnosticMessage {
|
match map.find(&rust_lookup) {
|
||||||
message: format!("{}: {}",
|
Some((_, rev_mapper::MistMap(line, column))) => {
|
||||||
msg.message.message,
|
let mist_msg = MistDiagnosticMessage {
|
||||||
span.label.clone().unwrap_or_default()),
|
message: format!("{}: {}",
|
||||||
file_name: if let Ok(mist_file) = mist_file {
|
msg.message.message,
|
||||||
mist_file.to_string_lossy().to_string()
|
span.label.clone().unwrap_or_default()),
|
||||||
} else {
|
file_name: if let Ok(mist_file) = mist_file {
|
||||||
map.mist_path.to_string_lossy().to_string()
|
mist_file.to_string_lossy().to_string()
|
||||||
},
|
} else {
|
||||||
file_path: map.mist_path.clone(),
|
map.mist_path.to_string_lossy().to_string()
|
||||||
line: line,
|
},
|
||||||
column: column,
|
file_path: map.mist_path.clone(),
|
||||||
};
|
line: line,
|
||||||
match msg.message.level {
|
column: column,
|
||||||
cargo_metadata::diagnostic::DiagnosticLevel::Error => {
|
};
|
||||||
diagnostics.push(MistDiagnostic::Error(mist_msg))
|
match msg.message.level {
|
||||||
|
cargo_metadata::diagnostic::DiagnosticLevel::Error => {
|
||||||
|
diagnostics.push(MistDiagnostic::Error(mist_msg))
|
||||||
|
}
|
||||||
|
cargo_metadata::diagnostic::DiagnosticLevel::Warning => {
|
||||||
|
diagnostics.push(MistDiagnostic::Warning(mist_msg))
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cargo_metadata::diagnostic::DiagnosticLevel::Warning => {
|
None => {
|
||||||
diagnostics.push(MistDiagnostic::Warning(mist_msg))
|
diagnostics.push(MistDiagnostic::Rust(msg));
|
||||||
}
|
break;
|
||||||
_ => {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,8 +118,8 @@ pub void print_diagnostics(Vec<MistDiagnostic>& diagnostics)
|
|||||||
let line = get_line(&mut files, &msg);
|
let line = get_line(&mut files, &msg);
|
||||||
println!("\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}",
|
println!("\n{}:{}:{}\n \x1b[31mError\x1b[0m: {}\n\t{}",
|
||||||
msg.file_name,
|
msg.file_name,
|
||||||
msg.line,
|
msg.line + 1,
|
||||||
msg.column,
|
msg.column + 1,
|
||||||
msg.message,
|
msg.message,
|
||||||
line.unwrap_or_default(),)
|
line.unwrap_or_default(),)
|
||||||
}
|
}
|
||||||
@@ -119,8 +127,8 @@ pub void print_diagnostics(Vec<MistDiagnostic>& diagnostics)
|
|||||||
let line = get_line(&mut files, &msg);
|
let line = get_line(&mut files, &msg);
|
||||||
println!("\n{}:{}:{}\n \x1b[33mWarning\x1b[0m: {}\n\t{}",
|
println!("\n{}:{}:{}\n \x1b[33mWarning\x1b[0m: {}\n\t{}",
|
||||||
msg.file_name,
|
msg.file_name,
|
||||||
msg.line,
|
msg.line + 1,
|
||||||
msg.column,
|
msg.column + 1,
|
||||||
msg.message,
|
msg.message,
|
||||||
line.unwrap_or_default(),)
|
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(() => {
|
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()
|
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};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(
|
#[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);
|
pub struct MistMap(pub usize, pub usize);
|
||||||
|
|
||||||
#[derive(
|
#[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);
|
pub struct RustMap(pub usize, pub usize);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user