Skip to content

Commit

Permalink
Merge pull request #26 from pragmatrix/ci
Browse files Browse the repository at this point in the history
Port examples to Shell3, remove older Shells, and add basic CI support
  • Loading branch information
pragmatrix authored Jun 22, 2024
2 parents e366a74 + 08a86f9 commit aac1bf6
Show file tree
Hide file tree
Showing 50 changed files with 652 additions and 1,668 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: 'qa'
on:
push:
branches:
- master
pull_request:

jobs:
qa:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, windows-2022, macos-14]

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: 'Toolchain'
uses: dtolnay/rust-toolchain@stable

- name: 'Clippy'
run: cargo clippy --all-targets -- -D warnings

- name: 'Test'
run: cargo test --all-targets

formatting:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: 'Install toolchain'
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: 'Check Formatting'
run: |
cargo fmt -- --check
26 changes: 26 additions & 0 deletions .github/workflows/wasm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'qa'
on:
push:
branches:
- master
pull_request:

jobs:
wasm:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: 'Install toolchain'
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown

- name: 'Markdown WASM Example'
run: cargo build --target wasm32-unknown-unknown --example markdown

- name: 'Code Viewer WASM Example'
run: cargo build --target wasm32-unknown-unknown --example code-viewer
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[submodule "rust-analyzer"]
path = rust-analyzer
path = examples/code/rust-analyzer
branch = "2024-04-08"
url = https://github.com/rust-lang/rust-analyzer.git
[submodule "examples/markdown/glyphon"]
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [

exclude = [
"examples/dist",
"rust-analyzer"
"examples/code/rust-analyzer"
]

[workspace.metadata]
Expand Down
44 changes: 44 additions & 0 deletions examples/code/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "code"
version = "0.1.0"
edition = "2021"

[dev-dependencies]

shared = { path = "../shared" }

massive-geometry = { workspace = true }
massive-shell = { workspace = true }
massive-scene = { workspace = true }
massive-shapes = { workspace = true }

postcard = { workspace = true }
anyhow = { workspace = true }
cosmic-text = { workspace = true }
winit = { workspace = true }
chrono = { workspace = true }
tokio = { workspace = true }
serde_json = { workspace = true }

tracing = { workspace = true }
tracing-subscriber = { workspace = true }
tracing-flame = { workspace = true }
tracing-chrome = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]

load-cargo = { path = "rust-analyzer/crates/load-cargo" }
project-model = { path = "rust-analyzer/crates/project-model" }
vfs = { path = "rust-analyzer/crates/vfs" }
base-db = { path = "rust-analyzer/crates/base-db" }
syntax = { path = "rust-analyzer/crates/syntax" }
# Semantics
hir = { path = "rust-analyzer/crates/hir" }
# Syntax highlighting, AnalysisHost
ide = { path = "rust-analyzer/crates/ide" }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]

console_error_panic_hook = "0.1.7"
console_log = "1.0.0"
wasm-bindgen-futures = "0.4.42"
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use std::sync::{Arc, Mutex};

use anyhow::Result;
use cosmic_text::{fontdb, FontSystem};
// use hir::db::DefDatabase;
use massive_scene::PositionedShape;
use tracing::info;
use winit::dpi::LogicalSize;

use massive_geometry::{Camera, SizeI};
use massive_shell::{shell, ApplicationContext};
use shared::{
application,
application::{Application, UpdateResponse},
code_viewer::{self, AttributedCode},
};
use winit::event_loop::EventLoop;

use massive_geometry::{Camera, SizeI};
use massive_shell::Shell;

const CANVAS_ID: &str = "massive-code";

Expand All @@ -19,6 +20,10 @@ fn main() -> Result<()> {
}

async fn async_main() -> Result<()> {
shell::run(code_viewer).await
}

async fn code_viewer(mut ctx: ApplicationContext) -> Result<()> {
// let env_filter = EnvFilter::from_default_env();
// let console_formatter = tracing_subscriber::fmt::Layer::default();
// // let (flame_layer, _flame_guard) = FlameLayer::with_file("./tracing.folded").unwrap();
Expand Down Expand Up @@ -72,12 +77,6 @@ async fn async_main() -> Result<()> {
line_height,
);

// Window

let event_loop = EventLoop::new()?;
let window = application::create_window(&event_loop, Some(CANVAS_ID))?;
let initial_size = window.inner_size();

// Camera

let camera = {
Expand All @@ -88,12 +87,46 @@ async fn async_main() -> Result<()> {

// Application

let application =
application::Application::new(camera, glyph_runs, SizeI::new(1280, height as u64));

// Shell

let font_system = Arc::new(Mutex::new(font_system));
let mut shell = Shell::new(&window, initial_size, font_system.clone()).await?;
shell.run(event_loop, &window, application).await
let initial_size = LogicalSize::new(800., 800.);

let window = ctx.new_window(initial_size, Some(CANVAS_ID))?;
let (mut renderer, mut director) = window
.new_renderer(
Arc::new(Mutex::new(font_system)),
camera,
window.inner_size(),
)
.await?;

let mut application = Application::new(SizeI::new(1280, height as u64));
let mut current_matrix = application.matrix();
let matrix = director.cast(current_matrix);

// Hold the positioned shapes in this context, otherwise they will disappear.
let _positioned_shapes: Vec<_> = glyph_runs
.into_iter()
.map(|run| director.cast(PositionedShape::new(matrix.clone(), run)))
.collect();

director.action()?;

loop {
let window_event = ctx.wait_for_event(&mut renderer).await?;

info!("Window Event: {window_event:?}");

match application.update(window_event) {
UpdateResponse::Exit => return Ok(()),
UpdateResponse::Continue => {}
}

// DI: This check has to be done in the renderer and the renderer has to decide when it
// needs to redraw.
let new_matrix = application.matrix();
if new_matrix != current_matrix {
matrix.update(new_matrix);
current_matrix = new_matrix;
director.action()?;
}
}
}
File renamed without changes.
81 changes: 57 additions & 24 deletions shell/examples/code/main.rs → examples/code/examples/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ use ide::{
};
use load_cargo::{LoadCargoConfig, ProcMacroServerChoice};
use project_model::CargoConfig;
use shared::{application, code_viewer};
use shared::{
application::{Application, UpdateResponse},
code_viewer,
};
use syntax::{AstNode, SyntaxKind, WalkEvent};
use tracing::info;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry};
use vfs::VfsPath;
use winit::event_loop::EventLoop;
use winit::dpi::LogicalSize;

use crate::code_viewer::TextAttribute;
use massive_geometry::{Camera, Color, SizeI};
use massive_scene::PositionedShape;
use massive_shapes::TextWeight;
use massive_shell::Shell;

use crate::code_viewer::TextAttribute;

// Simple file for testing less code.
mod test;
use massive_shell::{shell, ApplicationContext};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -55,11 +56,10 @@ async fn main() -> Result<()> {
// .with(chrome_layer)
.init();

let progress = |p: String| {
let mut handle = io::stdout().lock();
let _ = writeln!(handle, "{}", p.as_str());
};
shell::run(application).await
}

async fn application(mut ctx: ApplicationContext) -> Result<()> {
// let root_path = env::current_dir().unwrap().join(Path::new("Cargo.toml"));
let root_path = env::current_dir()
.unwrap()
Expand All @@ -70,7 +70,7 @@ async fn main() -> Result<()> {
let example_dir = root_path
.parent()
.unwrap()
.join(Path::new("shell/examples/code"));
.join(Path::new("examples/code/examples"));

// FontSystem

Expand Down Expand Up @@ -98,13 +98,18 @@ async fn main() -> Result<()> {
prefill_caches: false,
};

let file_to_show = example_dir.join("main.rs");
// let file_to_show = example_dir.join("test.rs");
let file_to_show = example_dir.join("code.rs");
// let file_to_show = example_dir.join("test.rs.demo");

println!("Looking for {}", file_to_show.display());

let progress_writer = |p: String| {
let mut handle = io::stdout().lock();
let _ = writeln!(handle, "{}", p.as_str());
};

let (db, vfs, _proc_macro_server) =
load_cargo::load_workspace_at(&root_path, &cargo_config, &load_config, &progress)?;
load_cargo::load_workspace_at(&root_path, &cargo_config, &load_config, &progress_writer)?;

println!("db: {db:?}");
println!("vfs: {vfs:?}");
Expand Down Expand Up @@ -254,8 +259,7 @@ async fn main() -> Result<()> {

// Window

let event_loop = EventLoop::new()?;
let window = application::create_window(&event_loop, None)?;
let window = ctx.new_window(LogicalSize::new(1024, 800), None)?;
let initial_size = window.inner_size();

// Camera
Expand All @@ -268,14 +272,43 @@ async fn main() -> Result<()> {

// Application

let application =
application::Application::new(camera, glyph_runs, SizeI::new(1280, height as u64));

// Shell
let mut application = Application::new(SizeI::new(1280, height as u64));

let font_system = Arc::new(Mutex::new(font_system));
let mut shell = Shell::new(&window, initial_size, font_system.clone()).await?;
shell.run(event_loop, &window, application).await

let (mut renderer, mut director) = window
.new_renderer(font_system, camera, initial_size)
.await?;

let mut current_matrix = application.matrix();
let matrix = director.cast(current_matrix);

let _positioned_shapes: Vec<_> = glyph_runs
.into_iter()
.map(|run| director.cast(PositionedShape::new(matrix.clone(), run)))
.collect();

director.action()?;

loop {
let window_event = ctx.wait_for_event(&mut renderer).await?;

info!("Window Event: {window_event:?}");

match application.update(window_event) {
UpdateResponse::Exit => return Ok(()),
UpdateResponse::Continue => {}
}

// DI: This check has to be done in the renderer and the renderer has to decide when it
// needs to redraw.
let new_matrix = application.matrix();
if new_matrix != current_matrix {
matrix.update(new_matrix);
current_matrix = new_matrix;
director.action()?;
}
}
}

fn attribute(tag: HlTag, mods: HlMods) -> (Color, TextWeight) {
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions examples/code/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

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

[dev-dependencies]
shared = { path = "../shared" }

massive-geometry = { workspace = true }
massive-shell = { workspace = true }
massive-scene = { workspace = true }
massive-shapes = { workspace = true }

anyhow = { workspace = true }
cosmic-text = { workspace = true }
winit = { workspace = true }
tokio = { workspace = true }
env_logger = { workspace = true }
Loading

0 comments on commit aac1bf6

Please sign in to comment.