Skip to content

Commit

Permalink
fix: correctly return error instead of option
Browse files Browse the repository at this point in the history
Also simplified parsing includes, and removed one yaml lib.
  • Loading branch information
alesbrelih committed Apr 7, 2024
1 parent 5f9e0bd commit a4fbb69
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 171 deletions.
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ serde = "1.0.197"
git2 = "0.18.3"
tree-sitter = "0.20.10"
tree-sitter-yaml = "0.0.1"
yaml-rust = "0.4.5"
reqwest = { version = "0.12.2", features = ["blocking"] }
regex = "1.10.4"
serde_yaml = "0.9.34"
Expand Down
4 changes: 2 additions & 2 deletions src/gitlab_ci_ls_parser/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub trait Git {
&self,
remote_pkg: &str,
remote_tag: &str,
remote_files: &[String],
remote_files: Vec<String>,
) -> anyhow::Result<Vec<GitlabFile>>;
fn fetch_remote(&self, url: Url) -> anyhow::Result<GitlabFile>;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ impl Git for GitImpl {
&self,
remote_pkg: &str,
remote_tag: &str,
remote_files: &[String],
remote_files: Vec<String>,
) -> anyhow::Result<Vec<GitlabFile>> {
if remote_tag.is_empty() || remote_pkg.is_empty() || remote_files.is_empty() {
return Ok(vec![]);
Expand Down
7 changes: 5 additions & 2 deletions src/gitlab_ci_ls_parser/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,18 @@ impl LSPHandlers {
for (document_uri, node) in nodes.iter() {
for (key, content) in node {
if key.eq(word) {
let cnt = self.parser.get_full_definition(
let cnt = match self.parser.get_full_definition(
GitlabElement {
key: key.clone(),
content: Some(content.to_string()),
uri: document_uri.to_string(),
..Default::default()
},
&store,
)?;
) {
Ok(c) => c,
Err(err) => return Some(LSPResult::Error(err)),
};

return Some(LSPResult::Hover(HoverResult {
id: request.id,
Expand Down
24 changes: 16 additions & 8 deletions src/gitlab_ci_ls_parser/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,22 @@ fn handle_result(msg: &Message, result: Option<LSPResult>) -> Option<Message> {
info!("send definition msg: {:?}", diagnostics_result);
Some(diagnostics(diagnostics_result))
}
None => match msg {
Message::Request(req) => Some(Message::Response(Response {
id: req.clone().id,
result: Some(serde_json::Value::Null),
error: None,
})),
_ => None,
},
Some(LSPResult::Error(err)) => {
error!("error handling message: {:?} got error: {:?}", msg, err);
null_response(msg)
}
None => null_response(msg),
}
}

fn null_response(msg: &Message) -> Option<Message> {
match msg {
Message::Request(req) => Some(Message::Response(Response {
id: req.clone().id,
result: Some(serde_json::Value::Null),
error: None,
})),
_ => None,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/gitlab_ci_ls_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub enum LSPResult {
Definition(DefinitionResult),
Diagnostics(DiagnosticsResult),
References(ReferencesResult),
Error(anyhow::Error),
}

#[derive(Debug, Clone)]
Expand Down
Loading

0 comments on commit a4fbb69

Please sign in to comment.