Skip to content

Commit

Permalink
dev: don't do complete on definition itself (#135)
Browse files Browse the repository at this point in the history
* dev: don't do completion on definition itself.

* dev: update snapshot hash
  • Loading branch information
Myriad-Dreamin authored Mar 30, 2024
1 parent 36536bb commit f7fd47d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions crates/tinymist-query/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ impl StatefulRequest for CompletionRequest {
let node = root.leaf_at(cursor);
let deref_target = node.and_then(|node| get_deref_target(node, cursor));

if let Some(d) = &deref_target {
let node = d.node();
// skip if is the let binding item, todo, check whether the pattern is exact
if matches!(
node.parent_kind(),
Some(SyntaxKind::LetBinding | SyntaxKind::Closure)
) {
return None;
}
}

let mut match_ident = None;
let mut completion_result = None;
match deref_target {
Expand Down Expand Up @@ -184,15 +195,15 @@ fn complete_path(
if !compl_path.is_dir() {
compl_path = compl_path.parent().unwrap_or(Path::new(""));
}
log::info!("compl_path: {src_path:?} + {path:?} -> {compl_path:?}");
log::debug!("compl_path: {src_path:?} + {path:?} -> {compl_path:?}");

if compl_path.is_absolute() {
log::warn!("absolute path completion is not supported for security consideration {path:?}");
return None;
}

let dirs = ctx.analysis.root.join(compl_path);
log::info!("compl_dirs: {dirs:?}");
log::debug!("compl_dirs: {dirs:?}");
// find directory or files in the path
let mut folder_completions = vec![];
let mut module_completions = vec![];
Expand Down Expand Up @@ -231,7 +242,7 @@ fn complete_path(
let w = pathdiff::diff_paths(&path, base)?;
unix_slash(&w).into()
};
log::info!("compl_label: {label:?}");
log::debug!("compl_label: {label:?}");

if path.is_dir() {
folder_completions.push(Completion {
Expand Down Expand Up @@ -286,7 +297,7 @@ fn complete_path(
..Default::default()
};

log::info!("compl_res: {res:?}");
log::debug!("compl_res: {res:?}");

res
})
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ fn e2e() {
});

let hash = replay_log(&tinymist_binary, &root.join("neovim"));
insta::assert_snapshot!(hash, @"siphash128_13:31d9406095865c1f57603564405d0ec2");
insta::assert_snapshot!(hash, @"siphash128_13:ce75b72cb95e2b46e0aa64da02b6ef50");
}

{
Expand Down

0 comments on commit f7fd47d

Please sign in to comment.