Skip to content

Commit

Permalink
feat: add signature help for simple define- methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocaillard committed Jan 13, 2023
1 parent 7a8cf35 commit 4cc24ed
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
15 changes: 13 additions & 2 deletions components/clarinet-files/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ impl FileLocation {
match manifest_location {
Some(manifest_location) => Ok(manifest_location),
None => Err(format!(
"unable to find manifest location from {}",
self.to_string()
"No Clarinet.toml is associated to the contract {}",
self.get_file_name().unwrap_or_default()
)),
}
}
Expand Down Expand Up @@ -290,6 +290,17 @@ impl FileLocation {
let file = self.to_string();
Ok(file[(base.len() + 1)..].to_string())
}

pub fn get_file_name(&self) -> Option<String> {
match self {
FileLocation::FileSystem { path } => {
path.file_name().and_then(|f| Some(f.to_str()?.to_string()))
}
FileLocation::Url { url } => url
.path_segments()
.and_then(|p| Some(p.last()?.to_string())),
}
}
}

impl FileLocation {
Expand Down
23 changes: 19 additions & 4 deletions components/clarity-lsp/src/vscode_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use lsp_types::request::{
};
use lsp_types::{
DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams,
DidSaveTextDocumentParams, PublishDiagnosticsParams, Url,
DidSaveTextDocumentParams, MessageType, PublishDiagnosticsParams, Url,
};
use serde::Serialize;
use serde_wasm_bindgen::{from_value as decode_from_js, to_value as encode_to_js, Serializer};
Expand All @@ -32,7 +32,7 @@ use crate::utils::log;
#[wasm_bindgen]
pub struct LspVscodeBridge {
client_diagnostic_tx: JsFunction,
_client_notification_tx: JsFunction,
client_notification_tx: JsFunction,
backend_to_client_tx: JsFunction,
editor_state_lock: Arc<RwLock<EditorState>>,
}
Expand All @@ -42,14 +42,14 @@ impl LspVscodeBridge {
#[wasm_bindgen(constructor)]
pub fn new(
client_diagnostic_tx: JsFunction,
_client_notification_tx: JsFunction,
client_notification_tx: JsFunction,
backend_to_client_tx: JsFunction,
) -> LspVscodeBridge {
panic::set_hook(Box::new(console_error_panic_hook::hook));

LspVscodeBridge {
client_diagnostic_tx,
_client_notification_tx,
client_notification_tx,
backend_to_client_tx: backend_to_client_tx.clone(),
editor_state_lock: Arc::new(RwLock::new(EditorState::new())),
}
Expand Down Expand Up @@ -133,6 +133,7 @@ impl LspVscodeBridge {

let mut editor_state_lock = EditorStateInput::RwLock(self.editor_state_lock.clone());
let send_diagnostic = self.client_diagnostic_tx.clone();
let send_notification = self.client_notification_tx.clone();
let file_accessor: Box<dyn FileAccessor> = Box::new(WASMFileSystemAccessor::new(
self.backend_to_client_tx.clone(),
));
Expand All @@ -142,6 +143,20 @@ impl LspVscodeBridge {
process_notification(command, &mut editor_state_lock, Some(&file_accessor)).await;

let mut aggregated_diagnostics = vec![];
if let Err(err) = result {
if err.starts_with("No Clarinet.toml is associated to the contract") {
let _ = send_notification.call2(
&JsValue::NULL,
&encode_to_js(&lsp_types::notification::ShowMessage::METHOD).unwrap(),
&encode_to_js(&lsp_types::ShowMessageParams {
typ: MessageType::WARNING,
message: String::from(&err),
})
.unwrap(),
);
}
return Err(JsValue::from(err));
}
if let Ok(ref mut response) = result {
aggregated_diagnostics.append(&mut response.aggregated_diagnostics);
}
Expand Down

0 comments on commit 4cc24ed

Please sign in to comment.