Skip to main content

hanzo_client/apis/
lsp_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`post_lsp_complete`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum PostLspCompleteError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`post_lsp_diagnostics`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum PostLspDiagnosticsError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`post_lsp_hover`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PostLspHoverError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`post_lsp_locate`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PostLspLocateError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`post_lsp_symbols`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PostLspSymbolsError {
50    UnknownValue(serde_json::Value),
51}
52
53
54/// Offers the candidates a language server has at a position, typed and resolved through the repository's dependencies rather than guessed from text.
55pub async fn post_lsp_complete(configuration: &configuration::Configuration, query: models::Query) -> Result<models::Answer, Error<PostLspCompleteError>> {
56    // add a prefix to parameters to efficiently prevent name collisions
57    let p_query = query;
58
59    let uri_str = format!("{}/v1/lsp/complete", configuration.base_path);
60    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
61
62    if let Some(ref user_agent) = configuration.user_agent {
63        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64    }
65    if let Some(ref token) = configuration.bearer_access_token {
66        req_builder = req_builder.bearer_auth(token.to_owned());
67    };
68    req_builder = req_builder.json(&p_query);
69
70    let req = req_builder.build()?;
71    let resp = configuration.client.execute(req).await?;
72
73    let status = resp.status();
74    let content_type = resp
75        .headers()
76        .get("content-type")
77        .and_then(|v| v.to_str().ok())
78        .unwrap_or("application/octet-stream");
79    let content_type = super::ContentType::from(content_type);
80
81    if !status.is_client_error() && !status.is_server_error() {
82        let content = resp.text().await?;
83        match content_type {
84            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
85            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Answer`"))),
86            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Answer`")))),
87        }
88    } else {
89        let content = resp.text().await?;
90        let entity: Option<PostLspCompleteError> = serde_json::from_str(&content).ok();
91        Err(Error::ResponseError(ResponseContent { status, content, entity }))
92    }
93}
94
95/// Reports every problem the language server finds in one file — compile errors, type errors and lints, each with its span and its severity (1 error, 2 warning, 3 information, 4 hint). The position is ignored.
96pub async fn post_lsp_diagnostics(configuration: &configuration::Configuration, query: models::Query) -> Result<models::Answer, Error<PostLspDiagnosticsError>> {
97    // add a prefix to parameters to efficiently prevent name collisions
98    let p_query = query;
99
100    let uri_str = format!("{}/v1/lsp/diagnostics", configuration.base_path);
101    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
102
103    if let Some(ref user_agent) = configuration.user_agent {
104        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
105    }
106    if let Some(ref token) = configuration.bearer_access_token {
107        req_builder = req_builder.bearer_auth(token.to_owned());
108    };
109    req_builder = req_builder.json(&p_query);
110
111    let req = req_builder.build()?;
112    let resp = configuration.client.execute(req).await?;
113
114    let status = resp.status();
115    let content_type = resp
116        .headers()
117        .get("content-type")
118        .and_then(|v| v.to_str().ok())
119        .unwrap_or("application/octet-stream");
120    let content_type = super::ContentType::from(content_type);
121
122    if !status.is_client_error() && !status.is_server_error() {
123        let content = resp.text().await?;
124        match content_type {
125            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
126            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Answer`"))),
127            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Answer`")))),
128        }
129    } else {
130        let content = resp.text().await?;
131        let entity: Option<PostLspDiagnosticsError> = serde_json::from_str(&content).ok();
132        Err(Error::ResponseError(ResponseContent { status, content, entity }))
133    }
134}
135
136/// Renders the type and documentation of the symbol at a position, as the language server itself renders it.  Positions are the LSP's: line and character are 0-BASED and character counts UTF-16 code units, so an editor's 1-based line must have 1 subtracted before it is sent. The repository is named by slug and is always one in the caller's own org; rev pins a branch, tag or commit sha, and empty means the default branch.
137pub async fn post_lsp_hover(configuration: &configuration::Configuration, query: models::Query) -> Result<models::Answer, Error<PostLspHoverError>> {
138    // add a prefix to parameters to efficiently prevent name collisions
139    let p_query = query;
140
141    let uri_str = format!("{}/v1/lsp/hover", configuration.base_path);
142    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
143
144    if let Some(ref user_agent) = configuration.user_agent {
145        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
146    }
147    if let Some(ref token) = configuration.bearer_access_token {
148        req_builder = req_builder.bearer_auth(token.to_owned());
149    };
150    req_builder = req_builder.json(&p_query);
151
152    let req = req_builder.build()?;
153    let resp = configuration.client.execute(req).await?;
154
155    let status = resp.status();
156    let content_type = resp
157        .headers()
158        .get("content-type")
159        .and_then(|v| v.to_str().ok())
160        .unwrap_or("application/octet-stream");
161    let content_type = super::ContentType::from(content_type);
162
163    if !status.is_client_error() && !status.is_server_error() {
164        let content = resp.text().await?;
165        match content_type {
166            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
167            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Answer`"))),
168            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Answer`")))),
169        }
170    } else {
171        let content = resp.text().await?;
172        let entity: Option<PostLspHoverError> = serde_json::from_str(&content).ok();
173        Err(Error::ResponseError(ResponseContent { status, content, entity }))
174    }
175}
176
177/// Finds where a symbol lives: its definition, its references, its type or its implementations, chosen by relation (definition, reference, type, implementation — empty means definition).  It resolves THROUGH dependencies. An answer whose external flag is set left the repository, and its path is then the module coordinate it landed in — which is the question a static index cannot answer and this service exists for.
178pub async fn post_lsp_locate(configuration: &configuration::Configuration, query: models::Query) -> Result<models::Answer, Error<PostLspLocateError>> {
179    // add a prefix to parameters to efficiently prevent name collisions
180    let p_query = query;
181
182    let uri_str = format!("{}/v1/lsp/locate", configuration.base_path);
183    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
184
185    if let Some(ref user_agent) = configuration.user_agent {
186        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
187    }
188    if let Some(ref token) = configuration.bearer_access_token {
189        req_builder = req_builder.bearer_auth(token.to_owned());
190    };
191    req_builder = req_builder.json(&p_query);
192
193    let req = req_builder.build()?;
194    let resp = configuration.client.execute(req).await?;
195
196    let status = resp.status();
197    let content_type = resp
198        .headers()
199        .get("content-type")
200        .and_then(|v| v.to_str().ok())
201        .unwrap_or("application/octet-stream");
202    let content_type = super::ContentType::from(content_type);
203
204    if !status.is_client_error() && !status.is_server_error() {
205        let content = resp.text().await?;
206        match content_type {
207            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
208            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Answer`"))),
209            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Answer`")))),
210        }
211    } else {
212        let content = resp.text().await?;
213        let entity: Option<PostLspLocateError> = serde_json::from_str(&content).ok();
214        Err(Error::ResponseError(ResponseContent { status, content, entity }))
215    }
216}
217
218/// Outlines one file: every declaration in it, with its kind and its span. The position is ignored — the answer is the whole file.
219pub async fn post_lsp_symbols(configuration: &configuration::Configuration, query: models::Query) -> Result<models::Answer, Error<PostLspSymbolsError>> {
220    // add a prefix to parameters to efficiently prevent name collisions
221    let p_query = query;
222
223    let uri_str = format!("{}/v1/lsp/symbols", configuration.base_path);
224    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
225
226    if let Some(ref user_agent) = configuration.user_agent {
227        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
228    }
229    if let Some(ref token) = configuration.bearer_access_token {
230        req_builder = req_builder.bearer_auth(token.to_owned());
231    };
232    req_builder = req_builder.json(&p_query);
233
234    let req = req_builder.build()?;
235    let resp = configuration.client.execute(req).await?;
236
237    let status = resp.status();
238    let content_type = resp
239        .headers()
240        .get("content-type")
241        .and_then(|v| v.to_str().ok())
242        .unwrap_or("application/octet-stream");
243    let content_type = super::ContentType::from(content_type);
244
245    if !status.is_client_error() && !status.is_server_error() {
246        let content = resp.text().await?;
247        match content_type {
248            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
249            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Answer`"))),
250            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Answer`")))),
251        }
252    } else {
253        let content = resp.text().await?;
254        let entity: Option<PostLspSymbolsError> = serde_json::from_str(&content).ok();
255        Err(Error::ResponseError(ResponseContent { status, content, entity }))
256    }
257}
258