Skip to content

Commit

Permalink
Backup for debugging signals
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed Feb 21, 2024
1 parent 8b19103 commit 9c0afd1
Show file tree
Hide file tree
Showing 15 changed files with 640 additions and 38 deletions.
7 changes: 7 additions & 0 deletions examples/media/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions examples/media/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "printing"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
42 changes: 42 additions & 0 deletions examples/media/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
mod media;
use media::*;

fn main() {
let mut archive =
WebArchive::new("https://library.example.gov", "best-libarian", "b00k5!");

archive.register(NewsArticle::new(
"Penguins win the Stanley Cup Championship!",
"The Pittsburgh Penguins once again are the best hockey team in the NHL.",
));

archive.register(Book::new(
"Alice's Adventures in Wonderland",
"Lewis Carroll",
"Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “and what is the use of a book,” thought Alice “without pictures or conversations?”"
));

archive.register((
Book::new("Frankenstein", "Mary Shelley", "You will rejoice to hear that no disaster has accompanied the commencement of an enterprise which you have regarded with such evil forebodings. I arrived here yesterday, and my first task is to assure my dear sister of my welfare and increasing confidence in the success of my undertaking."),
NewsArticle::new(
"Frankenstein is real!",
"Find out where he's been living all these years.",
),
));

archive.register(vec![
NewsArticle::new("Queen Elizabeth II", "The British Monarch is a figurehead of the British people."),
NewsArticle::new("Queen Elizabeth II dies at 96", "The British Monarch has passed away."),
NewsArticle::new("Thousands pay Tribute as Britain Says Final Farewell to Its Queen", "More than 100 world leaders and dignitaries are expected to attend the funeral of Queen Elizabeth II."),
]);

archive.register(
("William Shakespeare", vec![
Play::new("Romeo and Juliet", "William Shakespeare", "Romeo: But, soft! what light through yonder window breaks?"),
Play::new("Hamlet", "William Shakespeare", "Hamlet: To be, or not to be, that is the question:"),
Play::new("Macbeth", "William Shakespeare", "Macbeth: Is this a dagger which I see before me, The handle toward my hand?")
]),
);

archive.publish();
}
126 changes: 126 additions & 0 deletions examples/media/src/media.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
pub struct WebArchive {}

impl WebArchive {
pub fn new(
_domain: impl ToString,
_username: impl ToString,
_password: impl ToString,
) -> Self {
WebArchive {}
}

pub fn register<T: Summary>(&mut self, item: T) {
println!("Registered: {}", item.summarize());
}

pub fn publish(self) {
println!("Published!");
}
}

pub trait Summary {
fn summarize(&self) -> String;
}

pub struct NewsArticle {
pub headline: String,
pub content: String,
}

impl NewsArticle {
pub fn new(headline: impl ToString, content: impl ToString) -> Self {
NewsArticle {
headline: headline.to_string(),
content: content.to_string(),
}
}
}

pub struct Play {
pub title: String,
pub author: String,
pub content: String,
}

impl Play {
pub fn new(
title: impl ToString,
author: impl ToString,
content: impl ToString,
) -> Self {
Play {
title: title.to_string(),
author: author.to_string(),
content: content.to_string(),
}
}
}

pub struct Book {
pub title: String,
pub author: String,
pub content: String,
}

impl Book {
pub fn new(
title: impl ToString,
author: impl ToString,
content: impl ToString,
) -> Self {
Self {
title: title.to_string(),
author: author.to_string(),
content: content.to_string(),
}
}
}

impl Summary for String {
fn summarize(&self) -> String {
self.clone()
}
}

impl Summary for Play {
fn summarize(&self) -> String {
format!("\"{}\" by {}", self.title, self.author)
}
}

impl Summary for Book {
fn summarize(&self) -> String {
format!("{}, by {}", self.title, self.author)
}
}

impl Summary for NewsArticle {
fn summarize(&self) -> String {
format!("{}", self.headline)
}
}

impl<T: Summary, U: Summary> Summary for (T, U) {
fn summarize(&self) -> String {
format!("({}, {})", self.0.summarize(), self.1.summarize())
}
}

impl<U: Summary> Summary for (usize, U) {
fn summarize(&self) -> String {
format!("(DOI: {}, {})", self.0, self.1.summarize())
}
}

impl<T: Summary> Summary for Vec<T> {
fn summarize(&self) -> String {
format!(
"[{}]",
self
.iter()
.map(|item| item.summarize())
.collect::<Vec<_>>()
.join(", ")
)
}
}
4 changes: 2 additions & 2 deletions ide/packages/extension/src/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ export class Ctx {
editor.setDecorations(
traitErrorDecorate,
_.flatMap(oib, ob => {
return _.map(ob.traitErrors, e => ({
return _.map(ob.traitErrors, ([e, hashes]) => ({
range: rustRangeToVscodeRange(ob.exprs[e].range),
hoverMessage: this.buildOpenErrorItemCmd(
editor.document.fileName,
ob.hash,
e,
ob.obligations[ob.exprs[e].obligations[0]].hash,
hashes[0],
"trait"
),
}));
Expand Down
2 changes: 2 additions & 0 deletions ide/packages/panoptes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
"@estruyf/vscode": "^1.1.0",
"@floating-ui/react": "^0.26.8",
"@preact/signals-react": "^2.0.0",
"@preact/signals-react-transform": "^0.3.0",
"@types/classnames": "^2.3.1",
"@types/d3-graphviz": "^2.6.8",
"@types/lodash": "^4.14.195",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@types/vscode-webview": "^1.57.4",
"@vitejs/plugin-react": "^4.2.1",
"@vscode/codicons": "^0.0.35",
"@vscode/webview-ui-toolkit": "^1.3.1",
"classnames": "^2.3.2",
Expand Down
6 changes: 4 additions & 2 deletions ide/packages/panoptes/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Filename,
ObligationOutput,
} from "@argus/common/lib";
import { useSignals } from "@preact/signals-react/runtime";
import _ from "lodash";
import React, { useEffect, useState } from "react";

Expand All @@ -14,6 +15,8 @@ const App = ({
}: {
initialData: [Filename, ObligationOutput[]][];
}) => {
useSignals();

const [openFiles, setOpenFiles] =
useState<[Filename, ObligationOutput[]][]>(initialData);

Expand All @@ -36,8 +39,7 @@ const App = ({
case "open-error": {
console.debug("Current highlighted obligation", highlightedObligation);
highlightedObligation.value = payload;
return;
// return setTimeout(() => (highlightedObligation.value = null), 1000);
return setTimeout(() => (highlightedObligation.value = null), 1000);
}

case "open-file": {
Expand Down
12 changes: 5 additions & 7 deletions ide/packages/panoptes/src/File.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
div {
transition: background-color 1s ease-out;
transition: background-color 1s ease-out, border-color 1s ease-out;
}

.ObligationCard {
display: block;
width: 100%;
padding: 1em;
margin-bottom: 1em;
}

span.ErrorCount {
Expand All @@ -20,9 +18,9 @@ span.ErrorCount {
padding: 1em;
}

div.bling {
background-color: var(--vscode-selection-background);
transition: background-color 0s;
.bling {
background-color: var(--vscode-inputOption-activeBackground);
border: 1px solid var(--vscode-inputValidation-errorBorder);
}

.ObligationCard > vscode-text-area {
Expand All @@ -38,6 +36,6 @@ div.bling {
.PrettyObligationArea {
font-family: monospace;
display: block;
padding: 0.15em;
padding: 0 0.15em 0.15em 0.15em;
margin-bottom: 1em;
}
Loading

0 comments on commit 9c0afd1

Please sign in to comment.