From 3fa6f2bc613b926e140efcc5d0d3be02ff64e3db Mon Sep 17 00:00:00 2001 From: Felix Zeller Date: Fri, 22 Mar 2024 17:05:20 -0400 Subject: [PATCH] remove tag completion code --- src/completion/mod.rs | 384 ------------------------------------------ 1 file changed, 384 deletions(-) diff --git a/src/completion/mod.rs b/src/completion/mod.rs index 4b2e4762..f3a0abcb 100644 --- a/src/completion/mod.rs +++ b/src/completion/mod.rs @@ -58,47 +58,6 @@ pub trait Completable<'a, T: Completer<'a>> : Sized { /// Range indexes for one line of the file; NOT THE WHOLE FILE type LineRange = std::ops::Range; -#[derive(Debug, PartialEq, Eq)] -pub struct CompletableTag { - full_range: LineRange, - /// Tag name and range not including the '#' - inputted_tag: (String, LineRange) -} - -fn get_completable_tag(line: &Vec, cursor_character: usize) -> Option { - static PARTIAL_TAG_REGEX: Lazy = Lazy::new(|| { - Regex::new(r"\#(?[a-zA-Z0-9\/]*)").unwrap() - }); - - let line_string = String::from_iter(line); - - let captures_iter = PARTIAL_TAG_REGEX.captures_iter(&line_string); - - return captures_iter - .flat_map(|captures| { - - let (full, tag_text) = ( - captures.get(0)?, - captures.name("text")?, - ); - - // check if the cursor is in the tag - let preceding_character = cursor_character - 1; // User is inserting into the position after the character they are looking at; "#tag|" cursor is a position 4; I want pos 3; the end of the tag - if preceding_character >= full.range().start && preceding_character < full.range().end { // end is exclusive - return Some(CompletableTag { - full_range: full.range(), - inputted_tag: (tag_text.as_str().to_string(), tag_text.range()) - }) - } else { - return None - } - - }) - .next() - - - -} pub fn get_completions( vault: &Vault, @@ -127,349 +86,6 @@ pub fn get_completions( .or_else(|| run_completer::(completion_context, &path, params.text_document_position.position.line, params.text_document_position.position.character)) } -// -// if let Some(index) = get_wikilink_index(&selected_line, character) { -// -// // completions for wikilinks `[[text|` where | is the cursor -// let range = Range { -// start: Position { -// line: line as u32, -// character: index as u32 + 1, -// }, -// end: Position { -// line: line as u32, -// character: character as u32, -// }, -// }; -// -// let cmp_text = selected_line.get(index + 1..character)?; -// -// return match *cmp_text { -// [] => Some(CompletionResponse::List(CompletionList { -// items: initial_completion_files -// .iter() -// .map(|path| { -// match std::fs::metadata(path).and_then(|meta| meta.modified()) { -// Ok(modified) => (path, modified), -// Err(_) => (path, SystemTime::UNIX_EPOCH), -// } -// }) -// .sorted_by_key(|(_, modified)| *modified) -// .take(15) -// .filter_map(|(path_i, _)| { -// Some( -// vault -// .select_referenceable_nodes(Some(path_i)) -// .into_iter() -// .filter(|referenceable| { -// !matches!(referenceable, Referenceable::Tag(_, _)) -// && !matches!( -// referenceable, -// Referenceable::Footnote(_, _) -// ) -// }) -// .collect_vec(), -// ) -// }) -// .flatten() -// .filter_map(|referenceable| { -// default_completion_item(vault, &referenceable, None) -// }) -// .collect::>(), -// is_incomplete: true, -// })), -// [' ', ref text @ ..] if !text.contains(&']') => { -// let blocks = vault.select_blocks(); -// -// let matches = fuzzy_match(&String::from_iter(text), blocks); -// -// let rand_id = nanoid!( -// 5, -// &[ -// 'a', 'b', 'c', 'd', 'e', 'f', 'g', '1', '2', '3', '4', '5', '6', '7', '8', -// '9' -// ] -// ); -// -// return Some(CompletionResponse::List(CompletionList { -// is_incomplete: true, -// items: matches -// .into_par_iter() -// .take(50) -// .filter(|(block, _)| { -// String::from_iter(selected_line.clone()).trim() != block.text -// }) -// .flat_map(|(block, rank)| { -// let path_ref = get_obsidian_ref_path(vault.root_dir(), &block.file)?; -// let file_name = block.file.file_stem()?.to_str()?; -// -// let url = Url::from_file_path(&block.file).ok()?; -// Some(CompletionItem { -// label: block.text.clone(), -// sort_text: Some(rank.to_string()), -// documentation: Some(Documentation::MarkupContent(MarkupContent { -// kind: MarkupKind::Markdown, -// value: (block.range.start.line as isize - 5 -// ..=block.range.start.line as isize + 5) -// .flat_map(|i| Some((vault.select_line(&block.file, i)?, i))) -// .map(|(iter, ln)| { -// if ln == block.range.start.line as isize { -// format!("**{}**\n", String::from_iter(iter).trim()) -// // highlight the block to be references -// } else { -// String::from_iter(iter) -// } -// }) -// .join(""), -// })), -// filter_text: Some(format!(" {}", block.text)), -// text_edit: Some(CompletionTextEdit::Edit(TextEdit { -// range, -// new_text: format!("{}#^{}", file_name, rand_id), -// })), -// command: Some(Command { -// title: "Insert Block Reference Into File".into(), -// command: "apply_edits".into(), -// arguments: Some(vec![serde_json::to_value( -// tower_lsp::lsp_types::WorkspaceEdit { -// changes: Some( -// vec![( -// url, -// vec![TextEdit { -// range: Range { -// start: Position { -// line: block.range.end.line, -// character: block -// .range -// .end -// .character -// - 1, -// }, -// end: Position { -// line: block.range.end.line, -// character: block -// .range -// .end -// .character -// - 1, -// }, -// }, -// new_text: format!(" ^{}", rand_id), -// }], -// )] -// .into_iter() -// .collect(), -// ), -// change_annotations: None, -// document_changes: None, -// }, -// ) -// .ok()?]), -// }), -// ..Default::default() -// }) -// }) -// .collect(), -// })); -// } -// ref filter_text @ [..] if !filter_text.contains(&']') => { -// let all_links = MatchableReferenceable::from_vault(vault); -// let matches = fuzzy_match(&String::from_iter(filter_text), all_links); -// -// return Some(CompletionResponse::List(CompletionList { -// is_incomplete: true, -// items: matches -// .into_iter() -// .take(30) -// .filter(|(MatchableReferenceable(r, name), _)| { -// !(*name == String::from_iter(filter_text) && matches!(r, Referenceable::UnresovledFile(..) | Referenceable::UnresolvedHeading(..) | Referenceable::UnresovledIndexedBlock(..))) -// }) -// .filter_map(|(MatchableReferenceable(referenceable, _), rank)| { -// default_completion_item( -// vault, -// &referenceable, -// Some(CompletionTextEdit::Edit(TextEdit { -// range, -// new_text: referenceable.get_refname(&vault.root_dir())?.file_refname()? -// })), -// ) -// .and_then(|item| Some(CompletionItem { -// sort_text: Some(rank.to_string()), -// filter_text: Some(referenceable.get_refname(&vault.root_dir())?.to_string()), -// ..item -// })) -// }) -// .collect::>(), -// })); -// } -// _ => None, -// }; -// } else if let Some(partialmdlink) = get_completable_mdlink(&selected_line, character) { -// match partialmdlink { -// CompletableMDLink { -// path, -// infile_ref, -// full_range, -// display, -// partial, -// } => { -// let inputted_refname = format!( -// "{}{}", -// path.0, -// infile_ref -// .clone() -// .map(|(string, _)| format!("#{}", string)) -// .unwrap_or("".to_string()) -// ); -// -// -// let all_links = MatchableReferenceable::from_vault(vault); -// -// let matches = fuzzy_match(&inputted_refname, all_links); -// -// return Some(CompletionResponse::List(CompletionList { -// is_incomplete: true, -// items: matches -// .into_iter() -// .take(50) -// .filter(|(MatchableReferenceable(r, name), _)| -// !(*name == inputted_refname && matches!(r, Referenceable::UnresovledFile(..) | Referenceable::UnresolvedHeading(..) | Referenceable::UnresovledIndexedBlock(..))) -// ) -// .flat_map(|(MatchableReferenceable(referenceable, _), rank)| { -// default_completion_item( -// vault, -// &referenceable, -// Some(CompletionTextEdit::Edit(TextEdit { -// range: Range { -// start: Position { -// line: line as u32, -// character: full_range.start as u32, -// }, -// end: Position { -// line: line as u32, -// character: full_range.end as u32, -// }, -// }, -// new_text: format!( -// "[${{1:{}}}]({}{}{}{})", -// match ( -// display.0.as_str(), -// referenceable.get_refname(vault.root_dir())?.infile_ref -// ) { -// ("", Some(infile_ref_text)) => infile_ref_text.clone(), -// ("", None) => { -// match referenceable { -// Referenceable::File(_, mdfile) => { -// match mdfile.headings.first() { -// Some(heading) => { -// heading.heading_text.clone() -// } -// None => "".to_string(), -// } -// } -// -// _ => "".to_string(), -// } -// } -// (display_text, _) => display_text.to_string(), -// }, -// if referenceable -// .get_refname(vault.root_dir())? -// .path? -// .contains(" ") -// { -// "<" -// } else { -// "" -// }, -// referenceable -// .get_refname(vault.root_dir())? -// .link_file_key()?, -// match referenceable -// .get_refname(vault.root_dir())? -// .infile_ref -// { -// Some(string) => format!("#{}", string), -// None => "".to_string(), -// }, -// if referenceable -// .get_refname(vault.root_dir())? -// .path? -// .contains(" ") -// { -// ">" -// } else { -// "" -// }, -// ), -// })), -// ) -// .and_then(|item| { -// Some(CompletionItem { -// label: format!("{}{}", -// referenceable.get_refname(vault.root_dir())?.link_file_key()?, -// referenceable.get_refname(vault.root_dir())?.infile_ref.map(|thing| format!("#{}", thing)).unwrap_or("".into()) -// ), -// sort_text: Some(rank.to_string()), -// insert_text_format: Some(InsertTextFormat::SNIPPET), -// filter_text: Some(format!( -// "[{}]({}", -// display.0, -// referenceable.get_refname(vault.root_dir())?.to_string() -// )), -// ..item -// }) -// }) -// }) -// .collect::>(), -// })); -// } -// } -// } else if let Some(CompletableTag{ full_range, inputted_tag: (completable_tag_name, tag_name_range) }) = get_completable_tag(&selected_line, character) { -// // Initial Tag completion -// let tag_refereneables = -// vault -// .select_referenceable_nodes(None) -// .into_iter() -// .flat_map(|referenceable| match referenceable { -// tag @ Referenceable::Tag(_, _) => Some(tag), -// _ => None, -// }) -// .flat_map(|tag| Some(MatchableReferenceable(tag.clone(), tag.get_refname(&vault.root_dir())?.path?))) -// .collect_vec(); -// -// let matches = fuzzy_match(&completable_tag_name, tag_refereneables); -// -// return Some(CompletionResponse::List(CompletionList { -// is_incomplete: true, -// items: matches -// .into_iter() -// .take(20) -// .filter(|(MatchableReferenceable(_, tag_name), _)| *tag_name != completable_tag_name) -// .flat_map(|(MatchableReferenceable(tag, tag_name), ranking)| { -// default_completion_item(vault, &tag, Some(CompletionTextEdit::Edit(TextEdit { -// new_text: format!("#{}", tag_name.clone()), -// range: Range { -// start: Position { -// line: line as u32, -// character: full_range.start as u32, -// }, -// end: Position { -// line: line as u32, -// character: full_range.end as u32, -// }, -// } -// }))) -// .map(|item| CompletionItem { -// label: tag_name.clone(), -// sort_text: Some(ranking.to_string()), -// filter_text: Some(format!("#{}", tag_name)), -// ..item -// }) -// }) -// .unique_by(|c| c.label.to_owned()) -// .collect_vec(), -// })); // } else if character // .checked_sub(1) // .and_then(|start| selected_line.get(start..character))