Skip to content

Commit

Permalink
Move impls to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Jan 23, 2025
1 parent 2ee235d commit e213b05
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions crates/ark/src/lsp/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,15 @@ pub(crate) enum KernelNotification {
DidOpenVirtualDocument(DidOpenVirtualDocumentParams),
}

#[derive(Debug)]
pub(crate) struct DidOpenVirtualDocumentParams {
pub(crate) uri: String,
pub(crate) contents: String,
}

impl KernelNotification {
pub(crate) fn trace(&self) -> TraceKernelNotification {
TraceKernelNotification { inner: self }
}
}

/// A thin wrapper struct with a custom `Debug` method more appropriate for trace logs
pub(crate) struct TraceKernelNotification<'a> {
inner: &'a KernelNotification,
}

impl std::fmt::Debug for TraceKernelNotification<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.inner {
KernelNotification::DidChangeConsoleInputs(_) => f.write_str("DidChangeConsoleInputs"),
KernelNotification::DidOpenVirtualDocument(params) => f
.debug_struct("DidOpenVirtualDocument")
.field("uri", &params.uri)
.field("contents", &"<snip>")
.finish(),
// NOTE: Uncomment if we have notifications we don't care to specially handle
//notification => std::fmt::Debug::fmt(notification, f),
}
}
#[derive(Debug)]
pub(crate) struct DidOpenVirtualDocumentParams {
pub(crate) uri: String,
pub(crate) contents: String,
}

#[derive(Debug)]
Expand Down Expand Up @@ -610,3 +590,24 @@ pub(crate) fn publish_diagnostics(uri: Url, diagnostics: Vec<Diagnostic>, versio
version,
));
}

impl KernelNotification {
pub(crate) fn trace(&self) -> TraceKernelNotification {
TraceKernelNotification { inner: self }
}
}

impl std::fmt::Debug for TraceKernelNotification<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.inner {
KernelNotification::DidChangeConsoleInputs(_) => f.write_str("DidChangeConsoleInputs"),
KernelNotification::DidOpenVirtualDocument(params) => f
.debug_struct("DidOpenVirtualDocument")
.field("uri", &params.uri)
.field("contents", &"<snip>")
.finish(),
// NOTE: Uncomment if we have notifications we don't care to specially handle
//notification => std::fmt::Debug::fmt(notification, f),
}
}
}

0 comments on commit e213b05

Please sign in to comment.