Skip to content

Commit

Permalink
Handle bad URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Apr 24, 2023
1 parent a4f48b4 commit a752531
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ impl LanguageServer for Backend {
let link = rule.unwrap().source();
let text = text.unwrap();

let target = Url::parse(link.as_str());
if target.is_err() {
self.client
.show_message(MessageType::ERROR, "link has Invalid URL")
.await;
return Ok(None);
}

let mut links = Vec::new();
for (i, line) in text.lines().enumerate() {
let candidate = line.as_str();
Expand All @@ -169,7 +177,7 @@ impl LanguageServer for Backend {
let end = Position::new(i as u32, link.len() as u32 + sp.unwrap() as u32);
links.push(DocumentLink {
range: Range::new(start, end),
target: Some(Url::parse(link.as_str()).unwrap()),
target: Some(target.unwrap()),
tooltip: None,
data: None,
});
Expand Down

0 comments on commit a752531

Please sign in to comment.