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

Add notification on corelib mismatch #6213

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/cairo-lang-compiler/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl RootDatabaseBuilder {
}

/// Validates that the corelib version matches the expected one.
fn validate_corelib(db: &RootDatabase) -> Result<()> {
pub fn validate_corelib(db: &dyn FilesGroup) -> Result<()> {
let Some(config) = db.crate_config(CrateLongId::Real(CORELIB_CRATE_NAME.into()).intern(db))
else {
return Ok(());
Expand Down
18 changes: 18 additions & 0 deletions crates/cairo-lang-language-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use std::sync::Arc;
use std::time::{Duration, SystemTime};

use anyhow::{bail, Context};
use cairo_lang_compiler::db::validate_corelib;
use cairo_lang_compiler::project::{setup_project, update_crate_roots_from_project_config};
use cairo_lang_defs::db::DefsGroup;
use cairo_lang_defs::ids::{
Expand Down Expand Up @@ -80,6 +81,7 @@ use serde_json::Value;
use tokio::sync::Semaphore;
use tokio::task::spawn_blocking;
use tower_lsp::jsonrpc::{Error as LSPError, Result as LSPResult};
use tower_lsp::lsp_types::notification::Notification;
use tower_lsp::lsp_types::request::Request;
use tower_lsp::lsp_types::*;
use tower_lsp::{Client, ClientSocket, LanguageServer, LspService, Server};
Expand Down Expand Up @@ -597,6 +599,14 @@ impl Backend {
// Try to set up a corelib at least.
try_to_init_unmanaged_core(&*self.config.read().await, db);
}

let corelib_validation = validate_corelib(db);
if let Err(result) = corelib_validation {
let notifier = Notifier::new(&self.client);
spawn_blocking(move || {
notifier.send_notification::<CorelibVersionMismatch>(result.to_string());
});
}
}

Some(ProjectManifestPath::CairoProject(config_path)) => {
Expand Down Expand Up @@ -648,6 +658,14 @@ impl Backend {
}
}

#[derive(Debug)]
struct CorelibVersionMismatch {}

impl Notification for CorelibVersionMismatch {
type Params = String;
const METHOD: &'static str = "corelib/version-mismatch";
}

enum ServerCommands {
Reload,
}
Expand Down
10 changes: 10 additions & 0 deletions vscode-cairo/src/cairols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { isScarbProject } from "./scarbProject";
import { StandaloneLS } from "./standalonels";
import { registerMacroExpandProvider, registerVfsProvider } from "./textDocumentProviders";
import { NotificationType } from "vscode-jsonrpc/lib/common/messages";

export interface LanguageServerExecutableProvider {
languageServerExecutable(): lc.Executable;
Expand Down Expand Up @@ -82,6 +83,15 @@
);
});

client.onNotification(new NotificationType<string>("corelib/version-mismatch"), (params) => {
const errorMessage =
"Corelib version missmatch. If you are using Scarb try reopening the project to fix this error. Resort to `scarb cache clean` if it doesn't help. ERROR: " +

Check warning on line 88 in vscode-cairo/src/cairols.ts

View workflow job for this annotation

GitHub Actions / typos

"missmatch" should be "mismatch".
params;

vscode.window.showErrorMessage(errorMessage);
ctx.log.error(errorMessage);
});

await client.start();

return client;
Expand Down
Loading