Skip to content

Commit

Permalink
LS: Explicitly ignore Cancel & SetTrace without polluting logs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaput authored Oct 25, 2024
1 parent 02fca5c commit f98c2b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
11 changes: 9 additions & 2 deletions crates/cairo-lang-language-server/src/server/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use lsp_server::{ErrorCode, ExtractError, Notification, Request, RequestId};
use lsp_types::notification::{
Cancel, DidChangeConfiguration, DidChangeTextDocument, DidChangeWatchedFiles,
DidCloseTextDocument, DidOpenTextDocument, DidSaveTextDocument,
Notification as NotificationTrait,
Notification as NotificationTrait, SetTrace,
};
use lsp_types::request::{
CodeActionRequest, Completion, ExecuteCommand, Formatting, GotoDefinition, HoverRequest,
Expand Down Expand Up @@ -79,7 +79,6 @@ pub fn request<'a>(request: Request) -> Task<'a> {

pub fn notification<'a>(notification: Notification) -> Task<'a> {
match notification.method.as_str() {
Cancel::METHOD => local_notification_task::<Cancel>(notification),
DidChangeTextDocument::METHOD => {
local_notification_task::<DidChangeTextDocument>(notification)
}
Expand All @@ -94,6 +93,14 @@ pub fn notification<'a>(notification: Notification) -> Task<'a> {
}
DidOpenTextDocument::METHOD => local_notification_task::<DidOpenTextDocument>(notification),
DidSaveTextDocument::METHOD => local_notification_task::<DidSaveTextDocument>(notification),

// Ignoring $/cancelRequest because CairoLS does cancellation inside-out when the state is
// mutated, and we allow ourselves to ignore the corner case of user hitting ESC manually.
Cancel::METHOD => Ok(Task::nothing()),

// Ignoring $/setTrace because CairoLS never emits $/logTrace notifications anyway.
SetTrace::METHOD => Ok(Task::nothing()),

method => {
warn!("received notification {method} which does not have a handler");

Expand Down
18 changes: 3 additions & 15 deletions crates/cairo-lang-language-server/src/server/routing/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use cairo_lang_filesystem::db::{
AsFilesGroupMut, FilesGroup, FilesGroupEx, PrivRawFileContentQuery,
};
use lsp_types::notification::{
Cancel, DidChangeConfiguration, DidChangeTextDocument, DidChangeWatchedFiles,
DidCloseTextDocument, DidOpenTextDocument, DidSaveTextDocument, Notification,
DidChangeConfiguration, DidChangeTextDocument, DidChangeWatchedFiles, DidCloseTextDocument,
DidOpenTextDocument, DidSaveTextDocument, Notification,
};
use lsp_types::request::{
CodeActionRequest, Completion, ExecuteCommand, Formatting, GotoDefinition, HoverRequest,
Request, SemanticTokensFullRequest,
};
use lsp_types::{
CancelParams, CodeActionParams, CodeActionResponse, CompletionParams, CompletionResponse,
CodeActionParams, CodeActionResponse, CompletionParams, CompletionResponse,
DidChangeConfigurationParams, DidChangeTextDocumentParams, DidChangeWatchedFilesParams,
DidCloseTextDocumentParams, DidOpenTextDocumentParams, DidSaveTextDocumentParams,
DocumentFormattingParams, ExecuteCommandParams, GotoDefinitionParams, GotoDefinitionResponse,
Expand Down Expand Up @@ -132,18 +132,6 @@ impl BackgroundDocumentRequestHandler for Formatting {
}
}

impl SyncNotificationHandler for Cancel {
#[tracing::instrument(name = "$/cancelRequest", skip_all)]
fn run(
_state: &mut State,
_notifier: Notifier,
_requester: &mut Requester<'_>,
_params: CancelParams,
) -> LSPResult<()> {
Ok(())
}
}

impl SyncNotificationHandler for DidChangeTextDocument {
#[tracing::instrument(
name = "textDocument/didChange",
Expand Down

0 comments on commit f98c2b0

Please sign in to comment.