Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support error diagnostics #5

Open
travisstaloch opened this issue Sep 30, 2023 · 2 comments
Open

support error diagnostics #5

travisstaloch opened this issue Sep 30, 2023 · 2 comments

Comments

@travisstaloch
Copy link

I notice that there are no inline diagnostics / squiggles shown on lint or build errors and would like to work to improve this.

I looked at this code

lapce-zig/src/main.rs

Lines 93 to 97 in 1c8a0c6

Initialize::METHOD => {
let params: InitializeParams = serde_json::from_value(params).unwrap();
if let Err(e) = initialize(params) {
PLUGIN_RPC.stderr(&format!("plugin returned with error: {e}"))
}
.

I wonder if doing something like this could work? https://github.com/lapce-community/lapce-cpp-clangd/blob/bf47542fdd9804745f62759252845548f3e645ab/src/main.rs#L190C3-L202C4

The problem is that I have no idea how test a plugin locally.

Would it just be a matter of making the changes, building this project and copying the resulting wasm file into my local lapce-zig plugin folder? 🤔

@travisstaloch
Copy link
Author

Well I've been able to build a .wasm file from this plugin with the following changes. And I copied the .wasm into my local plugin folder but nothing seems to be happening after restarting the editor.

/tmp/lapce-zig $ cargo build
   Compiling lapce-zig v0.0.2 (/tmp/lapce-zig)
    Finished dev [unoptimized + debuginfo] target(s) in 0.46s
/tmp/lapce-zig $ cp target/wasm32-wasi/debug/lapce-zig.wasm ~/.local/share/lapce-stable/plugins/ghishadow.lapce-zig/lapce-zig.wasm 
diff --git a/src/main.rs b/src/main.rs
index 16de26b..fca9322 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,7 @@
 use anyhow::Result;
 use lapce_plugin::{
     psp_types::{
-        lsp_types::{request::Initialize, DocumentFilter, DocumentSelector, InitializeParams, Url},
+        lsp_types::{request::Initialize, DocumentFilter, DocumentSelector, InitializeParams, Url, MessageType},
         Request,
     },
     register_plugin, Http, LapcePlugin, VoltEnvironment, PLUGIN_RPC,
@@ -89,11 +89,14 @@ fn initialize(params: InitializeParams) -> Result<()> {
 impl LapcePlugin for State {
     fn handle_request(&mut self, _id: u64, method: String, params: Value) {
         #[allow(clippy::single_match)]
+        // panic!("foo");
         match method.as_str() {
             Initialize::METHOD => {
                 let params: InitializeParams = serde_json::from_value(params).unwrap();
                 if let Err(e) = initialize(params) {
-                    PLUGIN_RPC.stderr(&format!("plugin returned with error: {e}"))
+                    // PLUGIN_RPC.stderr(&format!("plugin returned with error: {e}"))
+                    PLUGIN_RPC.window_log_message(MessageType::ERROR, e.to_string());
+                    PLUGIN_RPC.window_show_message(MessageType::ERROR, e.to_string());
                 }
             }
             _ => {}
diff --git a/volt.toml b/volt.toml
index 1ca1e2d..eb234f0 100644
--- a/volt.toml
+++ b/volt.toml
@@ -10,7 +10,10 @@ wasm = "lapce-zig.wasm"
 
 [activation]
 language = ["zig"]
-workspace-contains = ["*/build.zig"]
+workspace-contains = [
+    "*/build.zig", 
+    "*/*.zig"
+]
 

You can see I even tried adding a panic!() in handle_request(). But nothing seems to happen when I type a jibberish line into an otherwise well formed build.zig file.

Makes me think that handle_request() is never being called.

@travisstaloch
Copy link
Author

I think this has been mostly solved by lapce/lapce#2650.

I'm going to leave this open until i have a chance to try out the above change with the next nightly release - probably later tonight - to see if there is any value in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant