mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-23 12:46:43 +00:00
refactor: rename local variables (cont.) (#1026)
This commit is contained in:
parent
9017e05afa
commit
de8e45a539
50 changed files with 837 additions and 814 deletions
|
|
@ -47,28 +47,28 @@ pub fn snapshot_testing(name: &str, f: &impl Fn(&mut LocalContext, PathBuf)) {
|
|||
#[cfg(windows)]
|
||||
let contents = contents.replace("\r\n", "\n");
|
||||
|
||||
run_with_sources(&contents, |w, p| {
|
||||
run_with_ctx(w, p, f);
|
||||
run_with_sources(&contents, |world, path| {
|
||||
run_with_ctx(world, path, f);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn run_with_ctx<T>(
|
||||
w: &mut LspUniverse,
|
||||
p: PathBuf,
|
||||
verse: &mut LspUniverse,
|
||||
path: PathBuf,
|
||||
f: &impl Fn(&mut LocalContext, PathBuf) -> T,
|
||||
) -> T {
|
||||
let root = w.workspace_root().unwrap();
|
||||
let paths = w
|
||||
let root = verse.workspace_root().unwrap();
|
||||
let paths = verse
|
||||
.shadow_paths()
|
||||
.into_iter()
|
||||
.map(|p| TypstFileId::new(None, VirtualPath::new(p.strip_prefix(&root).unwrap())))
|
||||
.map(|path| TypstFileId::new(None, VirtualPath::new(path.strip_prefix(&root).unwrap())))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let w = w.snapshot();
|
||||
let world = verse.snapshot();
|
||||
|
||||
let source = w.source_by_path(&p).ok().unwrap();
|
||||
let source = world.source_by_path(&path).ok().unwrap();
|
||||
let docs = find_module_level_docs(&source).unwrap_or_default();
|
||||
let properties = get_test_properties(&docs);
|
||||
let supports_html = properties
|
||||
|
|
@ -87,7 +87,7 @@ pub fn run_with_ctx<T>(
|
|||
},
|
||||
..Analysis::default()
|
||||
})
|
||||
.snapshot(w);
|
||||
.snapshot(world);
|
||||
|
||||
ctx.test_package_list(|| {
|
||||
vec![(
|
||||
|
|
@ -97,7 +97,7 @@ pub fn run_with_ctx<T>(
|
|||
});
|
||||
ctx.test_completion_files(|| paths.clone());
|
||||
ctx.test_files(|| paths);
|
||||
f(&mut ctx, p)
|
||||
f(&mut ctx, path)
|
||||
}
|
||||
|
||||
pub fn get_test_properties(s: &str) -> HashMap<&'_ str, &'_ str> {
|
||||
|
|
@ -164,7 +164,7 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
|
|||
let sources = source.split("-----");
|
||||
|
||||
let mut last_pw = None;
|
||||
for (i, source) in sources.enumerate() {
|
||||
for (idx, source) in sources.enumerate() {
|
||||
// find prelude
|
||||
let mut source = source.trim_start();
|
||||
let mut path = None;
|
||||
|
|
@ -179,7 +179,7 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
|
|||
}
|
||||
};
|
||||
|
||||
let path = path.unwrap_or_else(|| format!("/s{i}.typ"));
|
||||
let path = path.unwrap_or_else(|| format!("/s{idx}.typ"));
|
||||
|
||||
let pw = root.join(Path::new(&path));
|
||||
world
|
||||
|
|
@ -307,8 +307,8 @@ pub fn find_test_position_(s: &Source, offset: usize) -> LspPosition {
|
|||
if match_ident {
|
||||
match n.kind() {
|
||||
SyntaxKind::Closure => {
|
||||
let c = n.cast::<ast::Closure>().unwrap();
|
||||
if let Some(name) = c.name() {
|
||||
let closure = n.cast::<ast::Closure>().unwrap();
|
||||
if let Some(name) = closure.name() {
|
||||
if let Some(m) = n.find(name.span()) {
|
||||
n = m;
|
||||
break 'match_loop;
|
||||
|
|
@ -316,8 +316,8 @@ pub fn find_test_position_(s: &Source, offset: usize) -> LspPosition {
|
|||
}
|
||||
}
|
||||
SyntaxKind::LetBinding => {
|
||||
let c = n.cast::<ast::LetBinding>().unwrap();
|
||||
if let Some(name) = c.kind().bindings().first() {
|
||||
let let_binding = n.cast::<ast::LetBinding>().unwrap();
|
||||
if let Some(name) = let_binding.kind().bindings().first() {
|
||||
if let Some(m) = n.find(name.span()) {
|
||||
n = m;
|
||||
break 'match_loop;
|
||||
|
|
@ -397,37 +397,37 @@ fn pos(v: &Value) -> String {
|
|||
}
|
||||
|
||||
impl Redact for RedactFields {
|
||||
fn redact(&self, v: Value) -> Value {
|
||||
match v {
|
||||
Value::Object(mut m) => {
|
||||
for (_, v) in m.iter_mut() {
|
||||
*v = self.redact(v.clone());
|
||||
fn redact(&self, json_val: Value) -> Value {
|
||||
match json_val {
|
||||
Value::Object(mut map) => {
|
||||
for (_, val) in map.iter_mut() {
|
||||
*val = self.redact(val.clone());
|
||||
}
|
||||
for k in self.0.iter().copied() {
|
||||
let Some(t) = m.remove(k) else {
|
||||
for key in self.0.iter().copied() {
|
||||
let Some(t) = map.remove(key) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
match k {
|
||||
match key {
|
||||
"changes" => {
|
||||
let obj = t.as_object().unwrap();
|
||||
m.insert(
|
||||
k.to_owned(),
|
||||
map.insert(
|
||||
key.to_owned(),
|
||||
Value::Object(
|
||||
obj.iter().map(|(k, v)| (file_name(k), v.clone())).collect(),
|
||||
),
|
||||
);
|
||||
}
|
||||
"uri" | "oldUri" | "newUri" | "targetUri" => {
|
||||
m.insert(k.to_owned(), file_name(t.as_str().unwrap()).into());
|
||||
map.insert(key.to_owned(), file_name(t.as_str().unwrap()).into());
|
||||
}
|
||||
"range"
|
||||
| "selectionRange"
|
||||
| "originSelectionRange"
|
||||
| "targetRange"
|
||||
| "targetSelectionRange" => {
|
||||
m.insert(
|
||||
k.to_owned(),
|
||||
map.insert(
|
||||
key.to_owned(),
|
||||
format!("{}:{}", pos(&t["start"]), pos(&t["end"])).into(),
|
||||
);
|
||||
}
|
||||
|
|
@ -441,27 +441,27 @@ impl Redact for RedactFields {
|
|||
"data:image-hash/svg+xml;base64,redacted"
|
||||
});
|
||||
|
||||
m.insert(k.to_owned(), res.into());
|
||||
map.insert(key.to_owned(), res.into());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Value::Object(m)
|
||||
Value::Object(map)
|
||||
}
|
||||
Value::Array(mut a) => {
|
||||
for v in a.iter_mut() {
|
||||
*v = self.redact(v.clone());
|
||||
Value::Array(mut arr) => {
|
||||
for elem in arr.iter_mut() {
|
||||
*elem = self.redact(elem.clone());
|
||||
}
|
||||
Value::Array(a)
|
||||
Value::Array(arr)
|
||||
}
|
||||
Value::String(s) => Value::String(s),
|
||||
v => v,
|
||||
Value::String(content) => Value::String(content),
|
||||
json_val => json_val,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn file_name(k: &str) -> String {
|
||||
let name = Path::new(k).file_name().unwrap();
|
||||
fn file_name(path: &str) -> String {
|
||||
let name = Path::new(path).file_name().unwrap();
|
||||
name.to_str().unwrap().to_owned()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue