Skip to content

Commit

Permalink
Merge pull request #114 from RyanGreenup/include-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Feel-ix-343 authored May 28, 2024
2 parents 76fc5f4 + 798653f commit b39f500
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,14 @@ new_file_folder_path = ""
# This is also imported from obsidian if not specified: specifically the option titled "New file location"
daily_notes_folder = ""
# Whether markdown links should include an extension or not
# for example [File](file.md) or [File](file)
include_md_extension_md_link = false
# Whether wikilinks should include an extension or not (needed for Markor compatibility)
# for example [[File]] or [[File.md]]
include_md_extension_wikilink = false
```
Expand Down
19 changes: 16 additions & 3 deletions src/completion/link_completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,15 @@ impl<'a> LinkCompleter<'a> for MarkdownLinkCompleter<'a> {

/// Will add <$1> to the refname if it contains spaces
fn completion_text_edit(&self, display: Option<&str>, refname: &str) -> CompletionTextEdit {
let ext = if self.settings().include_md_extension_md_link {
".md"
} else {
""
};

let link_ref_text = match refname.contains(' ') {
true => format!("<{}>", refname),
false => refname.to_owned(),
true => format!("<{}{}>", refname, ext),
false => format!("{}{}", refname, ext),
};

CompletionTextEdit::Edit(TextEdit {
Expand Down Expand Up @@ -347,6 +353,11 @@ impl<'a> LinkCompleter<'a> for WikiLinkCompleter<'a> {
}

fn completion_text_edit(&self, display: Option<&str>, refname: &str) -> CompletionTextEdit {
let ext = if self.settings().include_md_extension_wikilink {
".md"
} else {
""
};
CompletionTextEdit::Edit(TextEdit {
range: Range {
start: Position {
Expand All @@ -358,9 +369,11 @@ impl<'a> LinkCompleter<'a> for WikiLinkCompleter<'a> {
character: (self.chars_in_line).min(self.character + 2_u32),
},
},

new_text: format!(
"{}{}]]${{2:}}",
"{}{}{}]]${{2:}}",
refname,
ext,
display
.map(|display| format!("|{}", display))
.unwrap_or("".to_string())
Expand Down
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub struct Settings {
pub semantic_tokens: bool,
pub tags_in_codeblocks: bool,
pub references_in_codeblocks: bool,
pub include_md_extension_md_link: bool,
pub include_md_extension_wikilink: bool,
}

impl Settings {
Expand Down Expand Up @@ -57,6 +59,8 @@ impl Settings {
.set_default("semantic_tokens", true)?
.set_default("tags_in_codeblocks", true)?
.set_default("references_in_codeblocks", true)?
.set_default("include_md_extension_md_link", false)?
.set_default("include_md_extension_wikilink", false)?
.set_override_option(
"semantic_tokens",
capabilities.text_document.as_ref().and_then(|it| {
Expand Down

0 comments on commit b39f500

Please sign in to comment.