Merge branch 'trunk' into 1281-scale-nicely-when-code_font_size-changes

This commit is contained in:
Anton-4 2021-10-08 12:35:49 +02:00 committed by GitHub
commit 664ef04e5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 1171 additions and 216 deletions

433
Cargo.lock generated
View File

@ -59,6 +59,28 @@ dependencies = [
"memchr",
]
[[package]]
name = "alsa"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75c4da790adcb2ce5e758c064b4f3ec17a30349f9961d3e5e6c9688b052a9e18"
dependencies = [
"alsa-sys",
"bitflags",
"libc",
"nix 0.20.0",
]
[[package]]
name = "alsa-sys"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8fee663d06c4e303404ef5f40488a53e062f89ba8bfed81f42325aafad1527"
dependencies = [
"libc",
"pkg-config",
]
[[package]]
name = "andrew"
version = "0.3.1"
@ -192,6 +214,25 @@ dependencies = [
"serde",
]
[[package]]
name = "bindgen"
version = "0.56.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239"
dependencies = [
"bitflags",
"cexpr",
"clang-sys",
"lazy_static",
"lazycell",
"peeking_take_while",
"proc-macro2 1.0.29",
"quote 1.0.9",
"regex",
"rustc-hash",
"shlex",
]
[[package]]
name = "bit-set"
version = "0.5.2"
@ -314,6 +355,12 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
[[package]]
name = "bytes"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]]
name = "calloop"
version = "0.6.5"
@ -338,6 +385,24 @@ name = "cc"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0"
dependencies = [
"jobserver",
]
[[package]]
name = "cesu8"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cexpr"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27"
dependencies = [
"nom 5.1.2",
]
[[package]]
name = "cfg-if"
@ -367,6 +432,17 @@ dependencies = [
"num-traits",
]
[[package]]
name = "clang-sys"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10612c0ec0e0a1ff0e97980647cb058a6e7aedb913d01d009c406b8b7d0b26ee"
dependencies = [
"glob",
"libc",
"libloading 0.7.0",
]
[[package]]
name = "clap"
version = "2.33.3"
@ -407,6 +483,12 @@ dependencies = [
"syn 1.0.76",
]
[[package]]
name = "claxon"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bfbf56724aa9eca8afa4fcfadeb479e722935bb2a0900c2d37e0cc477af0688"
[[package]]
name = "cli_utils"
version = "0.1.0"
@ -496,6 +578,16 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "combine"
version = "4.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a909e4d93292cd8e9c42e189f61681eff9d67b6541f96b8a1a737f23737bd001"
dependencies = [
"bytes 1.1.0",
"memchr",
]
[[package]]
name = "confy"
version = "0.4.0"
@ -628,6 +720,50 @@ dependencies = [
"objc",
]
[[package]]
name = "coreaudio-rs"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11894b20ebfe1ff903cbdc52259693389eea03b94918a2def2c30c3bf227ad88"
dependencies = [
"bitflags",
"coreaudio-sys",
]
[[package]]
name = "coreaudio-sys"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b7e3347be6a09b46aba228d6608386739fb70beff4f61e07422da87b0bb31fa"
dependencies = [
"bindgen",
]
[[package]]
name = "cpal"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98f45f0a21f617cd2c788889ef710b63f075c949259593ea09c826f1e47a2418"
dependencies = [
"alsa",
"core-foundation-sys 0.8.2",
"coreaudio-rs",
"jni",
"js-sys",
"lazy_static",
"libc",
"mach",
"ndk 0.3.0",
"ndk-glue 0.3.0",
"nix 0.20.0",
"oboe",
"parking_lot",
"stdweb",
"thiserror",
"web-sys",
"winapi 0.3.9",
]
[[package]]
name = "cpufeatures"
version = "0.2.1"
@ -1415,6 +1551,12 @@ version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7"
[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "glow"
version = "0.11.0"
@ -1548,6 +1690,12 @@ dependencies = [
"libc",
]
[[package]]
name = "hound"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549"
[[package]]
name = "humantime"
version = "2.1.0"
@ -1776,12 +1924,35 @@ version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "jni"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec"
dependencies = [
"cesu8",
"combine",
"jni-sys",
"log",
"thiserror",
"walkdir",
]
[[package]]
name = "jni-sys"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jobserver"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa"
dependencies = [
"libc",
]
[[package]]
name = "js-sys"
version = "0.3.54"
@ -1835,6 +2006,17 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a"
[[package]]
name = "lewton"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "777b48df9aaab155475a83a7df3070395ea1ac6902f5cd062b8f2b028075c030"
dependencies = [
"byteorder",
"ogg",
"tinyvec",
]
[[package]]
name = "libc"
version = "0.2.101"
@ -2038,6 +2220,26 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c835948974f68e0bd58636fc6c5b1fbff7b297e3046f11b3b3c18bbac012c6d"
[[package]]
name = "minimp3"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985438f75febf74c392071a975a29641b420dd84431135a6e6db721de4b74372"
dependencies = [
"minimp3-sys",
"slice-deque",
"thiserror",
]
[[package]]
name = "minimp3-sys"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e21c73734c69dc95696c9ed8926a2b393171d98b3f5f5935686a26a487ab9b90"
dependencies = [
"cc",
]
[[package]]
name = "miniz_oxide"
version = "0.4.4"
@ -2132,7 +2334,32 @@ checksum = "5eb167c1febed0a496639034d0c76b3b74263636045db5489eee52143c246e73"
dependencies = [
"jni-sys",
"ndk-sys",
"num_enum",
"num_enum 0.4.3",
"thiserror",
]
[[package]]
name = "ndk"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8794322172319b972f528bf90c6b467be0079f1fa82780ffb431088e741a73ab"
dependencies = [
"jni-sys",
"ndk-sys",
"num_enum 0.5.4",
"thiserror",
]
[[package]]
name = "ndk"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d64d6af06fde0e527b1ba5c7b79a6cc89cfc46325b0b2887dffe8f70197e0c3c"
dependencies = [
"bitflags",
"jni-sys",
"ndk-sys",
"num_enum 0.5.4",
"thiserror",
]
@ -2145,7 +2372,35 @@ dependencies = [
"lazy_static",
"libc",
"log",
"ndk",
"ndk 0.2.1",
"ndk-macro",
"ndk-sys",
]
[[package]]
name = "ndk-glue"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5caf0c24d51ac1c905c27d4eda4fa0635bbe0de596b8f79235e0b17a4d29385"
dependencies = [
"lazy_static",
"libc",
"log",
"ndk 0.3.0",
"ndk-macro",
"ndk-sys",
]
[[package]]
name = "ndk-glue"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3e9e94628f24e7a3cb5b96a2dc5683acd9230bf11991c2a1677b87695138420"
dependencies = [
"lazy_static",
"libc",
"log",
"ndk 0.4.0",
"ndk-macro",
"ndk-sys",
]
@ -2157,7 +2412,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05d1c6307dc424d0f65b9b06e94f88248e6305726b14729fd67a5e47b2dc481d"
dependencies = [
"darling 0.10.2",
"proc-macro-crate",
"proc-macro-crate 0.1.5",
"proc-macro2 1.0.29",
"quote 1.0.9",
"syn 1.0.76",
@ -2217,6 +2472,16 @@ dependencies = [
"libc",
]
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"memchr",
"version_check",
]
[[package]]
name = "nom"
version = "7.0.0"
@ -2234,6 +2499,17 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fa586da3e43cc7df44aae0e21ed2e743218b876de3f38035683d30bd8a3828e"
[[package]]
name = "num-derive"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
dependencies = [
"proc-macro2 1.0.29",
"quote 1.0.9",
"syn 1.0.76",
]
[[package]]
name = "num-traits"
version = "0.2.14"
@ -2260,7 +2536,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca565a7df06f3d4b485494f25ba05da1435950f4dc263440eda7a6fa9b8e36e4"
dependencies = [
"derivative",
"num_enum_derive",
"num_enum_derive 0.4.3",
]
[[package]]
name = "num_enum"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9bd055fb730c4f8f4f57d45d35cd6b3f0980535b056dc7ff119cee6a66ed6f"
dependencies = [
"derivative",
"num_enum_derive 0.5.4",
]
[[package]]
@ -2269,7 +2555,19 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffa5a33ddddfee04c0283a7653987d634e880347e96b5b2ed64de07efb59db9d"
dependencies = [
"proc-macro-crate",
"proc-macro-crate 0.1.5",
"proc-macro2 1.0.29",
"quote 1.0.9",
"syn 1.0.76",
]
[[package]]
name = "num_enum_derive"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9"
dependencies = [
"proc-macro-crate 1.1.0",
"proc-macro2 1.0.29",
"quote 1.0.9",
"syn 1.0.76",
@ -2348,6 +2646,38 @@ dependencies = [
"memchr",
]
[[package]]
name = "oboe"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e15e22bc67e047fe342a32ecba55f555e3be6166b04dd157cd0f803dfa9f48e1"
dependencies = [
"jni",
"ndk 0.4.0",
"ndk-glue 0.4.0",
"num-derive",
"num-traits",
"oboe-sys",
]
[[package]]
name = "oboe-sys"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "338142ae5ab0aaedc8275aa8f67f460e43ae0fca76a695a742d56da0a269eadc"
dependencies = [
"cc",
]
[[package]]
name = "ogg"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6951b4e8bf21c8193da321bcce9c9dd2e13c858fe078bf9054a288b419ae5d6e"
dependencies = [
"byteorder",
]
[[package]]
name = "once_cell"
version = "1.8.0"
@ -2476,6 +2806,12 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "percent-encoding"
version = "2.1.0"
@ -2671,6 +3007,16 @@ dependencies = [
"toml",
]
[[package]]
name = "proc-macro-crate"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83"
dependencies = [
"thiserror",
"toml",
]
[[package]]
name = "proc-macro-error"
version = "0.4.12"
@ -3228,8 +3574,10 @@ dependencies = [
"libc",
"page_size",
"pretty_assertions 0.6.1",
"roc_builtins",
"roc_can",
"roc_collections",
"roc_load",
"roc_module",
"roc_parse",
"roc_problem",
@ -3414,14 +3762,19 @@ dependencies = [
"maplit",
"pretty_assertions 0.5.1",
"pulldown-cmark",
"roc_ast",
"roc_builtins",
"roc_can",
"roc_code_markup",
"roc_collections",
"roc_fmt",
"roc_load",
"roc_module",
"roc_parse",
"roc_region",
"roc_types",
"tempfile",
"uuid",
]
[[package]]
@ -3469,10 +3822,12 @@ dependencies = [
"roc_solve",
"roc_types",
"roc_unify",
"rodio",
"ropey",
"serde",
"snafu",
"tempfile",
"threadpool",
"uuid",
"ven_graph",
"wgpu",
@ -3817,6 +4172,19 @@ dependencies = [
"snafu",
]
[[package]]
name = "rodio"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d98f5e557b61525057e2bc142c8cd7f0e70d75dc32852309bec440e6e046bf9"
dependencies = [
"claxon",
"cpal",
"hound",
"lewton",
"minimp3",
]
[[package]]
name = "ropey"
version = "1.3.1"
@ -4068,6 +4436,12 @@ dependencies = [
"opaque-debug 0.3.0",
]
[[package]]
name = "shlex"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
[[package]]
name = "siphasher"
version = "0.3.7"
@ -4100,6 +4474,17 @@ version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590"
[[package]]
name = "slice-deque"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31ef6ee280cdefba6d2d0b4b78a84a1c1a3f3a4cec98c2d4231c8bc225de0f25"
dependencies = [
"libc",
"mach",
"winapi 0.3.9",
]
[[package]]
name = "slotmap"
version = "1.0.6"
@ -4205,6 +4590,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "stdweb"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e"
[[package]]
name = "strip-ansi-escapes"
version = "0.1.1"
@ -4423,6 +4814,15 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "threadpool"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa"
dependencies = [
"num_cpus",
]
[[package]]
name = "time"
version = "0.1.43"
@ -4443,13 +4843,28 @@ dependencies = [
"serde_json",
]
[[package]]
name = "tinyvec"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7"
dependencies = [
"tinyvec_macros",
]
[[package]]
name = "tinyvec_macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092"
dependencies = [
"bytes",
"bytes 0.5.6",
"fnv",
"memchr",
"num_cpus",
@ -5262,8 +5677,8 @@ dependencies = [
"log",
"mio",
"mio-extras",
"ndk",
"ndk-glue",
"ndk 0.2.1",
"ndk-glue 0.2.1",
"ndk-sys",
"objc",
"parking_lot",
@ -5331,7 +5746,7 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7"
dependencies = [
"nom",
"nom 7.0.0",
]
[[package]]

View File

@ -8,6 +8,7 @@ install-other-libs:
FROM +prep-debian
RUN apt -y install wget git
RUN apt -y install libxcb-shape0-dev libxcb-xfixes0-dev # for editor clipboard
RUN apt -y install libasound2-dev # for editor sounds
RUN apt -y install libunwind-dev pkg-config libx11-dev zlib1g-dev
install-zig-llvm-valgrind-clippy-rustfmt:

View File

@ -7,6 +7,11 @@ If you already know [Elm](https://elm-lang.org/), then [Roc for Elm Programmers]
If you're curious about where the language's name and logo came from,
[here's an explanation](https://github.com/rtfeldman/roc/blob/trunk/name-and-logo.md).
## State of Roc
Roc is not ready for production yet. You are likely to encounter bugs. Publishing packages or documentation is not yet supported.
Many programs can however be compiled correctly. Check out [examples](examples) and [examples/benchmarks](examples/benchmarks). There are minimal platforms for Rust, Zig, C and an HTTP server. We are hard at work to make programming in Roc a delightful experience!
## Getting started
1. [Install Rust](https://rustup.rs/)
@ -19,7 +24,7 @@ If you're curious about where the language's name and logo came from,
### Examples
Took a look at the `examples` folder, `examples/benchmarks` contains some larger examples.
Took a look at the [examples folder](examples), [examples/benchmarks](examples/benchmarks) contains some larger examples.
Run examples as follows:
1. Navigate to `/examples`

View File

@ -7,6 +7,7 @@ edition = "2018"
description = "AST as used by the editor and (soon) docs. In contrast to the compiler, these types do not keep track of a location in a file."
[dependencies]
roc_builtins = { path = "../compiler/builtins"}
roc_can = { path = "../compiler/can" }
roc_collections = { path = "../compiler/collections" }
roc_region = { path = "../compiler/region" }
@ -15,6 +16,7 @@ roc_parse = { path = "../compiler/parse" }
roc_problem = { path = "../compiler/problem" }
roc_types = { path = "../compiler/types" }
roc_unify = { path = "../compiler/unify"}
roc_load = { path = "../compiler/load" }
arraystring = "0.3.0"
bumpalo = { version = "3.6.1", features = ["collections"] }
libc = "0.2"

View File

@ -9,7 +9,7 @@ use crate::{
def::def::References,
expr::{
expr2::{Expr2, ExprId, WhenBranch},
expr_to_expr2::to_expr2,
expr_to_expr2::expr_to_expr2,
output::Output,
record_field::RecordField,
},
@ -147,7 +147,8 @@ fn canonicalize_field<'a>(
// Both a label and a value, e.g. `{ name: "blah" }`
RequiredValue(label, _, loc_expr) => {
let field_var = env.var_store.fresh();
let (loc_can_expr, output) = to_expr2(env, scope, &loc_expr.value, loc_expr.region);
let (loc_can_expr, output) =
expr_to_expr2(env, scope, &loc_expr.value, loc_expr.region);
Ok(CanonicalField::LabelAndValue {
label: label.value,
@ -211,7 +212,7 @@ pub(crate) fn canonicalize_when_branch<'a>(
}
let (value, mut branch_output) =
to_expr2(env, &mut scope, &branch.value.value, branch.value.region);
expr_to_expr2(env, &mut scope, &branch.value.value, branch.value.region);
let value_id = env.pool.add(value);
env.set_region(value_id, branch.value.region);
@ -219,7 +220,7 @@ pub(crate) fn canonicalize_when_branch<'a>(
None => None,
Some(loc_expr) => {
let (can_guard, guard_branch_output) =
to_expr2(env, &mut scope, &loc_expr.value, loc_expr.region);
expr_to_expr2(env, &mut scope, &loc_expr.value, loc_expr.region);
let expr_id = env.pool.add(can_guard);
env.set_region(expr_id, loc_expr.region);

View File

@ -27,7 +27,7 @@ use ven_graph::{strongly_connected_components, topological_sort_into_groups};
use crate::{
lang::{
core::{
expr::{expr2::Expr2, expr_to_expr2::to_expr2, output::Output},
expr::{expr2::Expr2, expr_to_expr2::expr_to_expr2, output::Output},
fun_def::FunctionDef,
pattern::{self, symbols_from_pattern, to_pattern_id, Pattern2, PatternId},
types::{to_annotation2, Alias, Annotation2, Signature, Type2, TypeId},
@ -472,7 +472,7 @@ fn canonicalize_pending_def<'a>(
};
let (loc_can_expr, can_output) =
to_expr2(env, scope, &loc_expr.value, loc_expr.region);
expr_to_expr2(env, scope, &loc_expr.value, loc_expr.region);
output.references.union_mut(can_output.references.clone());
@ -639,7 +639,8 @@ fn canonicalize_pending_def<'a>(
env.closure_name_symbol = Some(*defined_symbol);
};
let (loc_can_expr, can_output) = to_expr2(env, scope, &loc_expr.value, loc_expr.region);
let (loc_can_expr, can_output) =
expr_to_expr2(env, scope, &loc_expr.value, loc_expr.region);
output.references.union_mut(can_output.references.clone());

View File

@ -20,11 +20,11 @@ pub fn defs_to_defs2<'a>(
) -> Vec<Def2> {
parsed_defs
.iter()
.map(|loc| to_def2_from_def(arena, env, scope, &loc.value, region))
.map(|loc| def_to_def2(arena, env, scope, &loc.value, region))
.collect()
}
pub fn to_def2_from_def<'a>(
pub fn def_to_def2<'a>(
arena: &'a Bump,
env: &mut Env<'a>,
scope: &mut Scope,
@ -34,8 +34,8 @@ pub fn to_def2_from_def<'a>(
use roc_parse::ast::Def::*;
match parsed_def {
SpaceBefore(inner_def, _) => to_def2_from_def(arena, env, scope, inner_def, region),
SpaceAfter(inner_def, _) => to_def2_from_def(arena, env, scope, inner_def, region),
SpaceBefore(inner_def, _) => def_to_def2(arena, env, scope, inner_def, region),
SpaceAfter(inner_def, _) => def_to_def2(arena, env, scope, inner_def, region),
Body(&loc_pattern, &loc_expr) => {
// TODO loc_pattern use identifier
let expr2 = loc_expr_to_expr2(arena, loc_expr, env, scope, region).0;

View File

@ -36,12 +36,12 @@ pub fn loc_expr_to_expr2<'a>(
) -> (Expr2, Output) {
let desugared_loc_expr = desugar_expr(arena, arena.alloc(loc_expr));
to_expr2(env, scope, arena.alloc(desugared_loc_expr.value), region)
expr_to_expr2(env, scope, arena.alloc(desugared_loc_expr.value), region)
}
const ZERO: Region = Region::zero();
pub fn to_expr2<'a>(
pub fn expr_to_expr2<'a>(
env: &mut Env<'a>,
scope: &mut Scope,
parse_expr: &'a roc_parse::ast::Expr<'a>,
@ -139,7 +139,7 @@ pub fn to_expr2<'a>(
let elems: PoolVec<ExprId> = PoolVec::with_capacity(items.len() as u32, env.pool);
for (node_id, item) in elems.iter_node_ids().zip(items.iter()) {
let (expr, sub_output) = to_expr2(env, scope, &item.value, item.region);
let (expr, sub_output) = expr_to_expr2(env, scope, &item.value, item.region);
output_ref.union(sub_output);
@ -188,7 +188,7 @@ pub fn to_expr2<'a>(
final_comments: _,
} => {
let (can_update, update_out) =
to_expr2(env, scope, &loc_update.value, loc_update.region);
expr_to_expr2(env, scope, &loc_update.value, loc_update.region);
if let Expr2::Var(symbol) = &can_update {
match canonicalize_fields(env, scope, fields) {
@ -309,10 +309,11 @@ pub fn to_expr2<'a>(
let mut output = Output::default();
for (condition, then_branch) in branches.iter() {
let (cond, cond_output) = to_expr2(env, scope, &condition.value, condition.region);
let (cond, cond_output) =
expr_to_expr2(env, scope, &condition.value, condition.region);
let (then_expr, then_output) =
to_expr2(env, scope, &then_branch.value, then_branch.region);
expr_to_expr2(env, scope, &then_branch.value, then_branch.region);
output.references.union_mut(cond_output.references);
output.references.union_mut(then_output.references);
@ -321,7 +322,7 @@ pub fn to_expr2<'a>(
}
let (else_expr, else_output) =
to_expr2(env, scope, &final_else.value, final_else.region);
expr_to_expr2(env, scope, &final_else.value, final_else.region);
output.references.union_mut(else_output.references);
@ -338,7 +339,8 @@ pub fn to_expr2<'a>(
When(loc_cond, branches) => {
// Infer the condition expression's type.
let cond_var = env.var_store.fresh();
let (can_cond, mut output) = to_expr2(env, scope, &loc_cond.value, loc_cond.region);
let (can_cond, mut output) =
expr_to_expr2(env, scope, &loc_cond.value, loc_cond.region);
// the condition can never be a tail-call
output.tail_call = None;
@ -411,7 +413,7 @@ pub fn to_expr2<'a>(
}
let (body_expr, new_output) =
to_expr2(env, &mut scope, &loc_body_expr.value, loc_body_expr.region);
expr_to_expr2(env, &mut scope, &loc_body_expr.value, loc_body_expr.region);
let mut captured_symbols: MutSet<Symbol> =
new_output.references.lookups.iter().copied().collect();
@ -501,7 +503,7 @@ pub fn to_expr2<'a>(
let fn_region = loc_fn.region;
// Canonicalize the function expression and its arguments
let (fn_expr, mut output) = to_expr2(env, scope, &loc_fn.value, fn_region);
let (fn_expr, mut output) = expr_to_expr2(env, scope, &loc_fn.value, fn_region);
// The function's return type
let args = PoolVec::with_capacity(loc_args.len() as u32, env.pool);
@ -592,7 +594,8 @@ pub fn to_expr2<'a>(
// The def as a whole is a tail call iff its return expression is a tail call.
// Use its output as a starting point because its tail_call already has the right answer!
let (ret_expr, mut output) = to_expr2(env, &mut scope, &loc_ret.value, loc_ret.region);
let (ret_expr, mut output) =
expr_to_expr2(env, &mut scope, &loc_ret.value, loc_ret.region);
output
.introduced_variables
@ -704,7 +707,7 @@ pub fn to_expr_id<'a>(
parse_expr: &'a roc_parse::ast::Expr<'a>,
region: Region,
) -> (ExprId, Output) {
let (expr, output) = to_expr2(env, scope, parse_expr, region);
let (expr, output) = expr_to_expr2(env, scope, parse_expr, region);
(env.add(expr, region), output)
}

View File

@ -1,6 +1,6 @@
pub mod expr2;
pub mod expr2_to_string;
pub(crate) mod expr_to_expr2;
pub mod expr_to_expr2;
mod introduced_vars;
pub(crate) mod output;
pub mod record_field;

View File

@ -3,7 +3,7 @@ use roc_parse::ast::StrLiteral;
use crate::{
ast_error::{ASTResult, UnexpectedASTNode},
lang::{core::expr::expr_to_expr2::to_expr2, env::Env, scope::Scope},
lang::{core::expr::expr_to_expr2::expr_to_expr2, env::Env, scope::Scope},
mem_pool::{pool::Pool, pool_str::PoolStr, pool_vec::PoolVec},
};
@ -94,7 +94,7 @@ fn flatten_str_lines<'a>(
}
let (loc_expr, new_output) =
to_expr2(env, scope, loc_expr.value, loc_expr.region);
expr_to_expr2(env, scope, loc_expr.value, loc_expr.region);
output.union(new_output);

View File

@ -3,5 +3,6 @@ mod canonicalization;
pub mod constrain;
pub mod lang;
pub mod mem_pool;
pub mod module;
pub mod parse;
pub mod solve_type;

39
ast/src/module.rs Normal file
View File

@ -0,0 +1,39 @@
use std::path::Path;
use bumpalo::Bump;
use roc_collections::all::MutMap;
use roc_load::file::LoadedModule;
pub fn load_module(src_file: &Path) -> LoadedModule {
let subs_by_module = MutMap::default();
let arena = Bump::new();
let loaded = roc_load::file::load_and_typecheck(
&arena,
src_file.to_path_buf(),
arena.alloc(roc_builtins::std::standard_stdlib()),
src_file.parent().unwrap_or_else(|| {
panic!(
"src_file {:?} did not have a parent directory but I need to have one.",
src_file
)
}),
subs_by_module,
8,
roc_can::builtins::builtin_defs_map,
);
match loaded {
Ok(x) => x,
Err(roc_load::file::LoadingProblem::FormattedReport(report)) => {
panic!(
"Failed to load module from src_file {:?}. Report: {:?}",
src_file, report
);
}
Err(e) => panic!(
"Failed to load module from src_file {:?}: {:?}",
src_file, e
),
}
}

View File

@ -1,7 +1,7 @@
use std::time::Duration;
use cli_utils::bench_utils::{
bench_cfold, bench_deriv, bench_nqueens, bench_quicksort, bench_rbtree_ck, bench_rbtree_delete,
bench_cfold, bench_deriv, bench_nqueens, bench_quicksort, bench_rbtree_ck,
};
use criterion::{measurement::WallTime, BenchmarkGroup, Criterion, SamplingMode};

View File

@ -240,7 +240,7 @@ pub fn build_app<'a>() -> App<'a> {
}
pub fn docs(files: Vec<PathBuf>) {
roc_docs::generate(
roc_docs::generate_docs_html(
files,
roc_builtins::std::standard_stdlib(),
Path::new("./generated-docs"),

View File

@ -19,7 +19,7 @@ pub fn new_comma_mn(expr_id: ExprId, parent_id_opt: Option<MarkNodeId>) -> Marku
MarkupNode::Text {
content: nodes::COMMA.to_owned(),
ast_node_id: ASTNodeId::AExprId(expr_id),
syn_high_style: HighlightStyle::Blank,
syn_high_style: HighlightStyle::Comma,
attributes: Attributes::default(),
parent_id_opt,
newlines_at_end: 0,

View File

@ -13,7 +13,6 @@ use super::{
};
use crate::markup_error::{ExpectedTextNode, NestedNodeMissingChild, NestedNodeRequired};
use bumpalo::Bump;
use roc_ast::{
ast_error::ASTResult,
lang::{
@ -305,9 +304,8 @@ fn new_markup_node(
mark_node_pool.add(node)
}
pub fn def2_to_markup<'a, 'b>(
arena: &'a Bump,
env: &mut Env<'b>,
pub fn def2_to_markup<'a>(
env: &mut Env<'a>,
def2: &Def2,
def2_node_id: DefId,
mark_node_pool: &mut SlowPool,
@ -321,7 +319,6 @@ pub fn def2_to_markup<'a, 'b>(
expr_id,
} => {
let expr_mn_id = expr2_to_markup(
arena,
env,
env.pool.get(*expr_id),
*expr_id,
@ -347,9 +344,8 @@ pub fn def2_to_markup<'a, 'b>(
}
// make Markup Nodes: generate String representation, assign Highlighting Style
pub fn expr2_to_markup<'a, 'b>(
arena: &'a Bump,
env: &mut Env<'b>,
pub fn expr2_to_markup<'a>(
env: &mut Env<'a>,
expr2: &Expr2,
expr2_node_id: ExprId,
mark_node_pool: &mut SlowPool,
@ -380,7 +376,7 @@ pub fn expr2_to_markup<'a, 'b>(
),
Expr2::Call { expr: expr_id, .. } => {
let expr = env.pool.get(*expr_id);
expr2_to_markup(arena, env, expr, *expr_id, mark_node_pool, interns)?
expr2_to_markup(env, expr, *expr_id, mark_node_pool, interns)?
}
Expr2::Var(symbol) => {
//TODO make bump_format with arena
@ -398,7 +394,6 @@ pub fn expr2_to_markup<'a, 'b>(
let sub_expr2 = env.pool.get(*node_id);
children_ids.push(expr2_to_markup(
arena,
env,
sub_expr2,
*node_id,
@ -460,7 +455,6 @@ pub fn expr2_to_markup<'a, 'b>(
let sub_expr2 = env.pool.get(*sub_expr2_node_id);
children_ids.push(expr2_to_markup(
arena,
env,
sub_expr2,
*sub_expr2_node_id,
@ -520,7 +514,6 @@ pub fn expr2_to_markup<'a, 'b>(
expr_var: _,
} => {
let body_mn_id = expr2_to_markup(
arena,
env,
env.pool.get(*expr_id),
*expr_id,
@ -797,9 +790,8 @@ fn add_header_mn_list(
.collect()
}
pub fn ast_to_mark_nodes<'a, 'b>(
arena: &'a Bump,
env: &mut Env<'b>,
pub fn ast_to_mark_nodes<'a>(
env: &mut Env<'a>,
ast: &AST,
mark_node_pool: &mut SlowPool,
interns: &Interns,
@ -809,11 +801,11 @@ pub fn ast_to_mark_nodes<'a, 'b>(
for &def_id in ast.def_ids.iter() {
let def2 = env.pool.get(def_id);
let expr2_markup_id = def2_to_markup(arena, env, def2, def_id, mark_node_pool, interns)?;
let def2_markup_id = def2_to_markup(env, def2, def_id, mark_node_pool, interns)?;
set_parent_for_all(expr2_markup_id, mark_node_pool);
set_parent_for_all(def2_markup_id, mark_node_pool);
all_mark_node_ids.push(expr2_markup_id);
all_mark_node_ids.push(def2_markup_id);
}
Ok(all_mark_node_ids)

View File

@ -6,6 +6,7 @@ use crate::colors::{self, from_hsb, RgbaTup};
#[derive(Hash, Eq, PartialEq, Copy, Clone, Debug, Deserialize, Serialize)]
pub enum HighlightStyle {
Operator, // =+-<>...
Comma,
String,
FunctionName,
Type,
@ -25,6 +26,7 @@ pub fn default_highlight_map() -> HashMap<HighlightStyle, RgbaTup> {
let mut highlight_map = HashMap::new();
[
(Operator, colors::WHITE),
(Comma, from_hsb(258, 50, 90)),
(String, from_hsb(346, 65, 97)),
(FunctionName, colors::WHITE),
(Type, colors::WHITE),

View File

@ -83,7 +83,7 @@ impl Scope {
self.idents.len()
}
pub fn lookup(&mut self, ident: &Ident, region: Region) -> Result<Symbol, RuntimeError> {
pub fn lookup(&self, ident: &Ident, region: Region) -> Result<Symbol, RuntimeError> {
match self.idents.get(ident) {
Some((symbol, _)) => Ok(*symbol),
None => Err(RuntimeError::LookupNotInScope(

View File

@ -9,9 +9,12 @@ edition = "2018"
[dependencies]
pulldown-cmark = { version = "0.8", default-features = false }
roc_ast = { path = "../ast" }
roc_load = { path = "../compiler/load" }
roc_builtins = { path = "../compiler/builtins" }
roc_can = { path = "../compiler/can" }
roc_code_markup = { path = "../code_markup"}
roc_fmt = { path = "../compiler/fmt" }
roc_module = { path = "../compiler/module" }
roc_region = { path = "../compiler/region" }
roc_types = { path = "../compiler/types" }
@ -22,3 +25,5 @@ bumpalo = { version = "3.2", features = ["collections"] }
[dev-dependencies]
pretty_assertions = "0.5.1"
maplit = "1.0.1"
tempfile = "3.2.0"
uuid = { version = "0.8", features = ["v4"] }

79
docs/src/def.rs Normal file
View File

@ -0,0 +1,79 @@
use bumpalo::{collections::String as BumpString, Bump};
use roc_ast::{
ast_error::ASTResult,
lang::{self, core::def::def_to_def2::def_to_def2},
mem_pool::pool::Pool,
};
use roc_code_markup::{markup::nodes::def2_to_markup, slow_pool::SlowPool};
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds};
use roc_region::all::Region;
use roc_types::subs::VarStore;
use crate::html::mark_node_to_html;
// html is written to buf
pub fn defs_to_html<'a>(
buf: &mut BumpString<'a>,
defs: Vec<roc_parse::ast::Def<'a>>,
env_module_id: ModuleId,
env_module_ids: &'a ModuleIds,
interns: &Interns,
) {
let mut env_pool = Pool::with_capacity(1024);
let env_arena = Bump::new();
let mut var_store = VarStore::default();
let dep_idents = IdentIds::exposed_builtins(8);
let exposed_ident_ids = IdentIds::default();
let def_arena = Bump::new();
let mut env = lang::env::Env::new(
env_module_id,
&env_arena,
&mut env_pool,
&mut var_store,
dep_idents,
env_module_ids,
exposed_ident_ids,
);
let mut scope = lang::scope::Scope::new(env.home, env.pool, env.var_store);
let region = Region::new(0, 0, 0, 0);
for def in defs.iter() {
// TODO remove unwrap
write_def_to_bump_str_html(&def_arena, &mut env, &mut scope, region, def, interns, buf)
.unwrap();
}
}
fn write_def_to_bump_str_html<'a, 'b>(
arena: &'a Bump,
env: &mut lang::env::Env<'a>,
scope: &mut lang::scope::Scope,
region: Region,
def: &'a roc_parse::ast::Def<'a>,
interns: &Interns,
buf: &mut BumpString<'b>,
) -> ASTResult<()> {
let def2 = def_to_def2(arena, env, scope, def, region);
let def2_id = env.pool.add(def2);
let mut mark_node_pool = SlowPool::default();
let def2_markup_id = def2_to_markup(
env,
env.pool.get(def2_id),
def2_id,
&mut mark_node_pool,
interns,
)?;
let def2_markup_node = mark_node_pool.get(def2_markup_id);
mark_node_to_html(def2_markup_node, &mark_node_pool, buf);
Ok(())
}

73
docs/src/expr.rs Normal file
View File

@ -0,0 +1,73 @@
use crate::html::mark_node_to_html;
use bumpalo::{collections::String as BumpString, Bump};
use roc_ast::{
ast_error::ASTResult,
lang::{self, core::expr::expr_to_expr2::expr_to_expr2},
mem_pool::pool::Pool,
};
use roc_code_markup::{markup::nodes::expr2_to_markup, slow_pool::SlowPool};
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds};
use roc_parse::ast::Expr;
use roc_region::all::Region;
use roc_types::subs::VarStore;
// html is written to buf
pub fn expr_to_html<'a>(
buf: &mut BumpString<'a>,
expr: Expr<'a>,
env_module_id: ModuleId,
env_module_ids: &'a ModuleIds,
interns: &Interns,
) {
let mut env_pool = Pool::with_capacity(1024);
let env_arena = Bump::new();
let mut var_store = VarStore::default();
let dep_idents = IdentIds::exposed_builtins(8);
let exposed_ident_ids = IdentIds::default();
let mut env = lang::env::Env::new(
env_module_id,
&env_arena,
&mut env_pool,
&mut var_store,
dep_idents,
env_module_ids,
exposed_ident_ids,
);
let mut scope = lang::scope::Scope::new(env.home, env.pool, env.var_store);
let region = Region::new(0, 0, 0, 0);
// TODO remove unwrap
write_expr_to_bump_str_html(&mut env, &mut scope, region, &expr, interns, buf).unwrap();
}
fn write_expr_to_bump_str_html<'a, 'b>(
env: &mut lang::env::Env<'a>,
scope: &mut lang::scope::Scope,
region: Region,
expr: &'a Expr,
interns: &Interns,
buf: &mut BumpString<'b>,
) -> ASTResult<()> {
let (expr2, _) = expr_to_expr2(env, scope, expr, region);
let expr2_id = env.pool.add(expr2);
let mut mark_node_pool = SlowPool::default();
let expr2_markup_id = expr2_to_markup(
env,
env.pool.get(expr2_id),
expr2_id,
&mut mark_node_pool,
interns,
)?;
let expr2_markup_node = mark_node_pool.get(expr2_markup_id);
mark_node_to_html(expr2_markup_node, &mark_node_pool, buf);
Ok(())
}

80
docs/src/html.rs Normal file
View File

@ -0,0 +1,80 @@
use bumpalo::collections::String as BumpString;
use roc_code_markup::{markup::nodes::MarkupNode, slow_pool::SlowPool};
// determine appropriate css class for MarkupNode
pub fn mark_node_to_html<'a>(
mark_node: &MarkupNode,
mark_node_pool: &SlowPool,
buf: &mut BumpString<'a>,
) {
let additional_newlines: usize;
match mark_node {
MarkupNode::Nested {
children_ids,
newlines_at_end,
..
} => {
for &child_id in children_ids {
mark_node_to_html(mark_node_pool.get(child_id), mark_node_pool, buf)
}
additional_newlines = *newlines_at_end;
}
MarkupNode::Text {
content,
syn_high_style,
newlines_at_end,
..
} => {
use roc_code_markup::syntax_highlight::HighlightStyle::*;
let css_class = match syn_high_style {
Operator => "operator",
Comma => "comma",
String => "string",
FunctionName => "function_name",
Type => "type",
Bracket => "bracket",
Number => "number",
PackageRelated => "package-related",
Variable => "variable",
RecordField => "recordfield",
Import => "import",
Provides => "provides",
Blank => "blank",
};
write_html_to_buf(content, css_class, buf);
additional_newlines = *newlines_at_end;
}
MarkupNode::Blank {
newlines_at_end, ..
} => {
let mut content_str = " ".to_string();
for _ in 0..*newlines_at_end {
content_str.push('\n');
}
write_html_to_buf(&content_str, "blank", buf);
additional_newlines = *newlines_at_end;
}
}
for _ in 0..additional_newlines {
buf.push('\n')
}
}
fn write_html_to_buf<'a>(content: &str, css_class: &'static str, buf: &mut BumpString<'a>) {
let opening_tag: String = ["<span class=\"syntax-", css_class, "\">"].concat();
buf.push_str(opening_tag.as_str());
buf.push_str(content);
buf.push_str("</span>");
}

View File

@ -1,6 +1,8 @@
extern crate pulldown_cmark;
extern crate roc_load;
use bumpalo::Bump;
use bumpalo::{collections::String as BumpString, collections::Vec as BumpVec, Bump};
use def::defs_to_html;
use expr::expr_to_html;
use roc_builtins::std::StdLib;
use roc_can::builtins::builtin_defs_map;
use roc_can::scope::Scope;
@ -9,15 +11,19 @@ use roc_load::docs::DocEntry::DocDef;
use roc_load::docs::{DocEntry, TypeAnnotation};
use roc_load::docs::{ModuleDocumentation, RecordField};
use roc_load::file::{LoadedModule, LoadingProblem};
use roc_module::symbol::{IdentIds, Interns, ModuleId};
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds};
use roc_parse::ident::{parse_ident, Ident};
use roc_parse::parser::State;
use roc_parse::parser::{State, SyntaxError};
use roc_region::all::Region;
use std::fs;
use std::path::{Path, PathBuf};
pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
let files_docs = files_to_documentations(filenames, std_lib);
mod def;
mod expr;
mod html;
pub fn generate_docs_html(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
let loaded_modules = load_modules_for_files(filenames, std_lib);
let mut arena = Bump::new();
//
@ -26,7 +32,7 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
name: "roc/builtins".to_string(),
version: "1.0.0".to_string(),
docs: "Package introduction or README.".to_string(),
modules: files_docs,
modules: loaded_modules,
};
if !build_dir.exists() {
@ -53,11 +59,11 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
.expect("TODO gracefully handle failing to make the favicon");
let template_html = include_str!("./static/index.html")
.replace("<!-- search.js -->", &format!("{}search.js", base_href()))
.replace("<!-- styles.css -->", &format!("{}styles.css", base_href()))
.replace("<!-- search.js -->", &format!("{}search.js", base_url()))
.replace("<!-- styles.css -->", &format!("{}styles.css", base_url()))
.replace(
"<!-- favicon.svg -->",
&format!("{}favicon.svg", base_href()),
&format!("{}favicon.svg", base_url()),
)
.replace(
"<!-- Module links -->",
@ -79,8 +85,8 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
for loaded_module in package.modules.iter_mut() {
arena.reset();
let mut exports: bumpalo::collections::Vec<&str> =
bumpalo::collections::Vec::with_capacity_in(loaded_module.exposed_values.len(), &arena);
let mut exports: BumpVec<&str> =
BumpVec::with_capacity_in(loaded_module.exposed_values.len(), &arena);
// TODO should this also include exposed_aliases?
for symbol in loaded_module.exposed_values.iter() {
@ -89,8 +95,8 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
let exports = exports.into_bump_slice();
for module in loaded_module.documentation.values_mut() {
let module_dir = build_dir.join(module.name.replace(".", "/").as_str());
for module_docs in loaded_module.documentation.values() {
let module_dir = build_dir.join(module_docs.name.replace(".", "/").as_str());
fs::create_dir_all(&module_dir)
.expect("TODO gracefully handle not being able to create the module dir");
@ -103,14 +109,7 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
)
.replace(
"<!-- Module Docs -->",
render_main_content(
loaded_module.module_id,
exports,
&loaded_module.dep_idents,
&loaded_module.interns,
module,
)
.as_str(),
render_module_documentation(exports, module_docs, loaded_module).as_str(),
);
fs::write(module_dir.join("index.html"), rendered_module)
@ -121,20 +120,63 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
println!("🎉 Docs generated in {}", build_dir.display());
}
fn render_main_content(
home: ModuleId,
exposed_values: &[&str],
dep_idents: &MutMap<ModuleId, IdentIds>,
// converts plain-text code to highlighted html
pub fn syntax_highlight_expr<'a>(
arena: &'a Bump,
buf: &mut BumpString<'a>,
code_str: &'a str,
env_module_id: ModuleId,
env_module_ids: &'a ModuleIds,
interns: &Interns,
module: &mut ModuleDocumentation,
) -> Result<String, SyntaxError<'a>> {
let trimmed_code_str = code_str.trim_end().trim();
let state = State::new(trimmed_code_str.as_bytes());
match roc_parse::expr::test_parse_expr(0, arena, state) {
Ok(loc_expr) => {
expr_to_html(buf, loc_expr.value, env_module_id, env_module_ids, interns);
Ok(buf.to_string())
}
Err(fail) => Err(SyntaxError::Expr(fail)),
}
}
// converts plain-text code to highlighted html
pub fn syntax_highlight_top_level_defs<'a>(
arena: &'a Bump,
buf: &mut BumpString<'a>,
code_str: &'a str,
env_module_id: ModuleId,
env_module_ids: &'a ModuleIds,
interns: &Interns,
) -> Result<String, SyntaxError<'a>> {
let trimmed_code_str = code_str.trim_end().trim();
match roc_parse::test_helpers::parse_defs_with(arena, trimmed_code_str) {
Ok(vec_loc_def) => {
let vec_def = vec_loc_def.iter().map(|loc| loc.value).collect();
defs_to_html(buf, vec_def, env_module_id, env_module_ids, interns);
Ok(buf.to_string())
}
Err(err) => Err(err),
}
}
fn render_module_documentation(
exposed_values: &[&str],
module: &ModuleDocumentation,
loaded_module: &LoadedModule,
) -> String {
let mut buf = String::new();
buf.push_str(
html_node(
html_to_string(
"h2",
vec![("class", "module-name")],
html_node("a", vec![("href", "/#")], module.name.as_str()).as_str(),
html_to_string("a", vec![("href", "/#")], module.name.as_str()).as_str(),
)
.as_str(),
);
@ -158,7 +200,9 @@ fn render_main_content(
let mut content = String::new();
content.push_str(html_node("a", vec![("href", href.as_str())], name).as_str());
content.push_str(
html_to_string("a", vec![("href", href.as_str())], name).as_str(),
);
for type_var in &doc_def.type_vars {
content.push(' ');
@ -177,7 +221,7 @@ fn render_main_content(
type_annotation_to_html(0, &mut content, type_ann);
buf.push_str(
html_node(
html_to_string(
"h3",
vec![("id", name), ("class", "entry-name")],
content.as_str(),
@ -188,12 +232,10 @@ fn render_main_content(
if let Some(docs) = &doc_def.docs {
buf.push_str(
markdown_to_html(
home,
exposed_values,
dep_idents,
&mut module.scope,
interns,
&module.scope,
docs.to_string(),
loaded_module,
)
.as_str(),
);
@ -201,12 +243,10 @@ fn render_main_content(
}
DocEntry::DetachedDoc(docs) => {
let markdown = markdown_to_html(
home,
exposed_values,
dep_idents,
&mut module.scope,
interns,
&module.scope,
docs.to_string(),
loaded_module,
);
buf.push_str(markdown.as_str());
}
@ -217,7 +257,7 @@ fn render_main_content(
buf
}
fn html_node(tag_name: &str, attrs: Vec<(&str, &str)>, content: &str) -> String {
fn html_to_string(tag_name: &str, attrs: Vec<(&str, &str)>, content: &str) -> String {
let mut buf = String::new();
buf.push('<');
@ -246,62 +286,62 @@ fn html_node(tag_name: &str, attrs: Vec<(&str, &str)>, content: &str) -> String
buf
}
fn base_href() -> String {
fn base_url() -> String {
// e.g. "builtins/" in "https://roc-lang.org/builtins/Str"
//
// TODO make this a CLI flag to the `docs` subcommand instead of an env var
match std::env::var("ROC_DOCS_URL_ROOT") {
Ok(root_builtins_path) => {
let mut href = String::with_capacity(root_builtins_path.len() + 64);
let mut url_str = String::with_capacity(root_builtins_path.len() + 64);
if !root_builtins_path.starts_with('/') {
href.push('/');
url_str.push('/');
}
href.push_str(&root_builtins_path);
url_str.push_str(&root_builtins_path);
if !root_builtins_path.ends_with('/') {
href.push('/');
url_str.push('/');
}
href
url_str
}
_ => {
let mut href = String::with_capacity(64);
let mut url_str = String::with_capacity(64);
href.push('/');
url_str.push('/');
href
url_str
}
}
}
fn render_name_and_version(name: &str, version: &str) -> String {
let mut buf = String::new();
let mut href = base_href();
let mut url_str = base_url();
href.push_str(name);
url_str.push_str(name);
buf.push_str(
html_node(
html_to_string(
"h1",
vec![("class", "pkg-full-name")],
html_node("a", vec![("href", href.as_str())], name).as_str(),
html_to_string("a", vec![("href", url_str.as_str())], name).as_str(),
)
.as_str(),
);
let mut versions_href = base_href();
let mut versions_url_str = base_url();
versions_href.push('/');
versions_href.push_str(name);
versions_href.push('/');
versions_href.push_str(version);
versions_url_str.push('/');
versions_url_str.push_str(name);
versions_url_str.push('/');
versions_url_str.push_str(version);
buf.push_str(
html_node(
html_to_string(
"a",
vec![("class", "version"), ("href", versions_href.as_str())],
vec![("class", "version"), ("href", versions_url_str.as_str())],
version,
)
.as_str(),
@ -321,13 +361,13 @@ fn render_sidebar<'a, I: Iterator<Item = (Vec<String>, &'a ModuleDocumentation)>
let name = module.name.as_str();
let href = {
let mut href_buf = base_href();
let mut href_buf = base_url();
href_buf.push_str(name);
href_buf
};
sidebar_entry_content.push_str(
html_node(
html_to_string(
"a",
vec![("class", "sidebar-module-link"), ("href", href.as_str())],
name,
@ -348,7 +388,7 @@ fn render_sidebar<'a, I: Iterator<Item = (Vec<String>, &'a ModuleDocumentation)>
entry_href.push_str(doc_def.name.as_str());
entries_buf.push_str(
html_node(
html_to_string(
"a",
vec![("href", entry_href.as_str())],
doc_def.name.as_str(),
@ -363,7 +403,7 @@ fn render_sidebar<'a, I: Iterator<Item = (Vec<String>, &'a ModuleDocumentation)>
};
sidebar_entry_content.push_str(
html_node(
html_to_string(
"div",
vec![("class", "sidebar-sub-entries")],
entries.as_str(),
@ -372,7 +412,7 @@ fn render_sidebar<'a, I: Iterator<Item = (Vec<String>, &'a ModuleDocumentation)>
);
buf.push_str(
html_node(
html_to_string(
"div",
vec![("class", "sidebar-entry")],
sidebar_entry_content.as_str(),
@ -384,9 +424,9 @@ fn render_sidebar<'a, I: Iterator<Item = (Vec<String>, &'a ModuleDocumentation)>
buf
}
pub fn files_to_documentations(filenames: Vec<PathBuf>, std_lib: StdLib) -> Vec<LoadedModule> {
pub fn load_modules_for_files(filenames: Vec<PathBuf>, std_lib: StdLib) -> Vec<LoadedModule> {
let arena = Bump::new();
let mut files_docs = vec![];
let mut modules = vec![];
for filename in filenames {
let mut src_dir = filename.clone();
@ -401,7 +441,7 @@ pub fn files_to_documentations(filenames: Vec<PathBuf>, std_lib: StdLib) -> Vec<
std::mem::size_of::<usize>() as u32, // This is just type-checking for docs, so "target" doesn't matter
builtin_defs_map,
) {
Ok(loaded) => files_docs.push(loaded),
Ok(loaded) => modules.push(loaded),
Err(LoadingProblem::FormattedReport(report)) => {
println!("{}", report);
panic!();
@ -410,7 +450,7 @@ pub fn files_to_documentations(filenames: Vec<PathBuf>, std_lib: StdLib) -> Vec<
}
}
files_docs
modules
}
const INDENT: &str = " ";
@ -425,6 +465,7 @@ fn new_line(buf: &mut String) {
buf.push('\n');
}
// html is written to buf
fn type_annotation_to_html(indent_level: usize, buf: &mut String, type_ann: &TypeAnnotation) {
let is_multiline = should_be_multiline(type_ann);
match type_ann {
@ -686,7 +727,7 @@ fn doc_url<'a>(
home: ModuleId,
exposed_values: &[&str],
dep_idents: &MutMap<ModuleId, IdentIds>,
scope: &mut Scope,
scope: &Scope,
interns: &'a Interns,
mut module_name: &'a str,
ident: &str,
@ -753,7 +794,7 @@ fn doc_url<'a>(
}
}
let mut url = base_href();
let mut url = base_url();
// Example:
//
@ -769,12 +810,10 @@ fn doc_url<'a>(
}
fn markdown_to_html(
home: ModuleId,
exposed_values: &[&str],
dep_idents: &MutMap<ModuleId, IdentIds>,
scope: &mut Scope,
interns: &Interns,
scope: &Scope,
markdown: String,
loaded_module: &LoadedModule,
) -> String {
use pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Event, LinkType, Tag::*};
@ -801,11 +840,11 @@ fn markdown_to_html(
match iter.next() {
Some(symbol_name) if iter.next().is_none() => {
let DocUrl { url, title } = doc_url(
home,
loaded_module.module_id,
exposed_values,
dep_idents,
&loaded_module.dep_idents,
scope,
interns,
&loaded_module.interns,
module_name,
symbol_name,
);
@ -824,11 +863,11 @@ fn markdown_to_html(
// This looks like a global tag name, but it could
// be a type alias that's in scope, e.g. [I64]
let DocUrl { url, title } = doc_url(
home,
loaded_module.module_id,
exposed_values,
dep_idents,
&loaded_module.dep_idents,
scope,
interns,
&loaded_module.interns,
"",
type_name,
);
@ -843,6 +882,9 @@ fn markdown_to_html(
};
let markdown_options = pulldown_cmark::Options::empty();
let mut expecting_code_block = false;
let mut docs_parser = vec![];
let (_, _) = pulldown_cmark::Parser::new_with_broken_link_callback(
&markdown,
@ -850,6 +892,7 @@ fn markdown_to_html(
Some(&mut broken_link_callback),
)
.fold((0, 0), |(start_quote_count, end_quote_count), event| {
match &event {
// Replace this sequence (`>>>` syntax):
// Start(BlockQuote)
@ -915,6 +958,39 @@ fn markdown_to_html(
(start_quote_count, end_quote_count)
}
Event::Start(CodeBlock(CodeBlockKind::Fenced(_))) => {
expecting_code_block = true;
docs_parser.push(event);
(0, 0)
}
Event::End(CodeBlock(_)) => {
expecting_code_block = false;
docs_parser.push(event);
(0, 0)
}
Event::Text(CowStr::Borrowed(code_str)) if expecting_code_block => {
let code_block_arena = Bump::new();
let mut code_block_buf = BumpString::new_in(&code_block_arena);
match syntax_highlight_expr(
&code_block_arena,
&mut code_block_buf,
code_str,
loaded_module.module_id,
&loaded_module.interns.module_ids,
&loaded_module.interns
)
{
Ok(highlighted_code_str) => {
docs_parser.push(Event::Html(CowStr::from(highlighted_code_str)));
}
Err(syntax_error) => {
panic!("Unexpected parse failure when parsing this for rendering in docs:\n\n{}\n\nParse error was:\n\n{:?}\n\n", code_str, syntax_error)
}
};
(0, 0)
}
_ => {
docs_parser.push(event);
(0, 0)

View File

@ -41,7 +41,7 @@
</main>
<footer>
<p>Made by people who like to make nice things.</p>
<p>© 2020</p>
<p>© 2021</p>
</footer>
</body>

View File

@ -7,7 +7,6 @@
--body-bg-color: #fdfdfd;
--border-color: #e9e9e9;
--faded-color: #4c4c4c;
--monospace-font;
--font-sans: -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
--font-mono: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
--top-header-height: 67px;
@ -283,7 +282,6 @@ code {
font-family: var(--font-mono);
color: var(--code-color);
background-color: var(--code-bg-color);
padding: 2px 8px;
display: inline-block;
}
@ -306,15 +304,34 @@ pre {
overflow-x: auto;
}
pre code {
padding: 6px 8px;
}
.hidden {
/* Use !important to win all specificity fights. */
display: none !important;
}
.syntax-number {
color: #60B7BF;
}
.syntax-string {
color:#F7577C;
}
.syntax-bracket {
color:#FF335F;
}
.syntax-closure-dash,
.syntax-closure-arrow,
.syntax-operator
{
color: #ffffff;
}
.syntax-comma {
color: #9573E6;
}
.syntax-comment {
color: #ff0000;
}
#module-search:placeholder-shown {
padding: 0;
opacity: 0;

View File

@ -0,0 +1,158 @@
#[macro_use]
extern crate pretty_assertions;
#[cfg(test)]
mod insert_doc_syntax_highlighting {
use std::{fs::File, io::Write, path::PathBuf};
use bumpalo::{collections::String as BumpString, Bump};
use roc_ast::module::load_module;
use roc_docs::{syntax_highlight_expr, syntax_highlight_top_level_defs};
use roc_load::file::LoadedModule;
use tempfile::tempdir;
use uuid::Uuid;
fn expect_html(code_str: &str, want: &str, use_expr: bool) {
let loaded_module = make_mock_module();
let code_block_arena = Bump::new();
let mut code_block_buf = BumpString::new_in(&code_block_arena);
if use_expr {
match syntax_highlight_expr(
&code_block_arena,
&mut code_block_buf,
code_str,
loaded_module.module_id,
&loaded_module.interns.module_ids,
&loaded_module.interns,
) {
Ok(highlighted_code_str) => {
assert_eq!(highlighted_code_str, want);
}
Err(syntax_error) => {
panic!("Unexpected parse failure when parsing this for rendering in docs:\n\n{}\n\nParse error was:\n\n{:?}\n\n", code_str, syntax_error)
}
};
} else {
match syntax_highlight_top_level_defs(
&code_block_arena,
&mut code_block_buf,
code_str,
loaded_module.module_id,
&loaded_module.interns.module_ids,
&loaded_module.interns,
) {
Ok(highlighted_code_str) => {
assert_eq!(highlighted_code_str, want);
}
Err(syntax_error) => {
panic!("Unexpected parse failure when parsing this for rendering in docs:\n\n{}\n\nParse error was:\n\n{:?}\n\n", code_str, syntax_error)
}
};
}
}
pub const HELLO_WORLD: &str = r#"
app "test-app"
packages { base: "platform" }
imports []
provides [ main ] to base
main = "Hello, world!"
"#;
fn make_mock_module() -> LoadedModule {
let temp_dir = tempdir().expect("Failed to create temporary directory for test.");
let temp_file_path_buf =
PathBuf::from([Uuid::new_v4().to_string(), ".roc".to_string()].join(""));
let temp_file_full_path = temp_dir.path().join(temp_file_path_buf);
let mut file = File::create(temp_file_full_path.clone()).expect(&format!(
"Failed to create temporary file for path {:?}",
temp_file_full_path
));
writeln!(file, "{}", HELLO_WORLD).expect(&format!(
"Failed to write {:?} to file: {:?}",
HELLO_WORLD, file
));
load_module(&temp_file_full_path)
}
fn expect_html_expr(code_str: &str, want: &str) {
expect_html(code_str, want, true)
}
fn expect_html_def(code_str: &str, want: &str) {
expect_html(code_str, want, false)
}
#[test]
fn number_expr() {
expect_html_expr("2", r#"<span class="syntax-number">2</span>"#);
}
#[test]
fn string_expr() {
expect_html_expr(r#""abc""#, r#"<span class="syntax-string">"abc"</span>"#);
}
#[test]
fn empty_list_expr() {
expect_html_expr(
r#"[]"#,
r#"<span class="syntax-bracket">[ </span><span class="syntax-bracket"> ]</span>"#,
);
}
#[test]
fn single_elt_list_expr() {
expect_html_expr(
r#"[ 0 ]"#,
r#"<span class="syntax-bracket">[ </span><span class="syntax-number">0</span><span class="syntax-bracket"> ]</span>"#,
);
}
#[test]
fn multi_elt_list_expr() {
expect_html_expr(
r#"[ "hello", "WoRlD" ]"#,
r#"<span class="syntax-bracket">[ </span><span class="syntax-string">"hello"</span><span class="syntax-comma">, </span><span class="syntax-string">"WoRlD"</span><span class="syntax-bracket"> ]</span>"#,
);
}
#[test]
fn record_expr() {
expect_html_expr(
r#"{ a: "hello!" }"#,
"<span class=\"syntax-bracket\">{ </span><span class=\"syntax-recordfield\">a</span><span class=\"syntax-operator\">: </span><span class=\"syntax-string\">\"hello!\"</span><span class=\"syntax-bracket\"> }</span>",
);
}
#[test]
fn nested_record_expr() {
expect_html_expr(
r#"{ a: { bB: "WoRlD" } }"#,
"<span class=\"syntax-bracket\">{ </span><span class=\"syntax-recordfield\">a</span><span class=\"syntax-operator\">: </span><span class=\"syntax-bracket\">{ </span><span class=\"syntax-recordfield\">bB</span><span class=\"syntax-operator\">: </span><span class=\"syntax-string\">\"WoRlD\"</span><span class=\"syntax-bracket\"> }</span><span class=\"syntax-bracket\"> }</span>",
);
}
#[test]
fn top_level_def_value() {
expect_html_def(
r#"main = "Hello, World!""#,
"<span class=\"syntax-variable\">main</span><span class=\"syntax-operator\"> = </span><span class=\"syntax-string\">\"Hello, World!\"</span>\n\n",
);
}
#[test]
fn tld_list() {
expect_html_def(
r#"main = [ 1, 2, 3 ]"#,
"<span class=\"syntax-variable\">main</span><span class=\"syntax-operator\"> = </span><span class=\"syntax-bracket\">[ </span><span class=\"syntax-number\">1</span><span class=\"syntax-comma\">, </span><span class=\"syntax-number\">2</span><span class=\"syntax-comma\">, </span><span class=\"syntax-number\">3</span><span class=\"syntax-bracket\"> ]</span>\n\n",
);
}
}

View File

@ -55,6 +55,8 @@ nonempty = "0.6.0"
tempfile = "3.2.0"
uuid = { version = "0.8", features = ["v4"] }
fs_extra = "1.2.0"
rodio = "0.14.0"
threadpool = "1.8.1"
[dependencies.bytemuck]
version = "1.4"

View File

@ -43,11 +43,7 @@ pub fn handle_keydown(
}
}
A | S | R | Home | End => pass_keydown_to_focused(&modifiers, virtual_keycode, app_model)?,
F11 => pass_keydown_to_focused(&modifiers, virtual_keycode, app_model)?,
_ => (),
_ => pass_keydown_to_focused(&modifiers, virtual_keycode, app_model)?,
}
Ok(())

View File

@ -24,10 +24,7 @@ use fs_extra::dir::{copy, ls, CopyOptions, DirEntryAttr, DirEntryValue};
use pipelines::RectResources;
use roc_ast::lang::env::Env;
use roc_ast::mem_pool::pool::Pool;
use roc_can::builtins::builtin_defs_map;
use roc_collections::all::MutMap;
use roc_load;
use roc_load::file::LoadedModule;
use roc_ast::module::load_module;
use roc_module::symbol::IdentIds;
use roc_types::subs::VarStore;
use std::collections::HashSet;
@ -66,6 +63,7 @@ fn run_event_loop(project_dir_path_opt: Option<&Path>) -> Result<(), Box<dyn Err
let window = winit::window::WindowBuilder::new()
.with_inner_size(PhysicalSize::new(1900.0, 1000.0))
.with_title("The Roc Editor - very alpha")
.build(&event_loop)
.unwrap();
@ -561,40 +559,6 @@ fn copy_roc_platform_if_not_exists(
}
}
pub fn load_module(src_file: &Path) -> LoadedModule {
let subs_by_module = MutMap::default();
let arena = Bump::new();
let loaded = roc_load::file::load_and_typecheck(
&arena,
src_file.to_path_buf(),
arena.alloc(roc_builtins::std::standard_stdlib()),
src_file.parent().unwrap_or_else(|| {
panic!(
"src_file {:?} did not have a parent directory but I need to have one.",
src_file
)
}),
subs_by_module,
8,
builtin_defs_map,
);
match loaded {
Ok(x) => x,
Err(roc_load::file::LoadingProblem::FormattedReport(report)) => {
panic!(
"Failed to load module from src_file {:?}. Report: {:?}",
src_file, report
);
}
Err(e) => panic!(
"Failed to load module from src_file {:?}: {:?}",
src_file, e
),
}
}
fn queue_no_file_text(
size: &PhysicalSize<u32>,
text: &str,

View File

@ -8,5 +8,6 @@ mod mvc;
mod render_ast;
mod render_debug;
mod resources;
mod sound;
mod theme;
mod util;

View File

@ -8,11 +8,12 @@ use crate::editor::ed_error::{
};
use copypasta::{ClipboardContext, ClipboardProvider};
use std::fmt;
use threadpool::ThreadPool;
#[derive(Debug)]
pub struct AppModel<'a> {
pub ed_model_opt: Option<EdModel<'a>>,
pub clipboard_opt: Option<Clipboard>,
pub sound_thread_pool: ThreadPool, // thread is blocked while sound is played, hence the threadpool
}
impl<'a> AppModel<'a> {
@ -20,6 +21,7 @@ impl<'a> AppModel<'a> {
AppModel {
ed_model_opt,
clipboard_opt: AppModel::init_clipboard_opt(),
sound_thread_pool: ThreadPool::new(7), // can play up to 7 sounds simultaneously
}
}

View File

@ -41,7 +41,11 @@ pub fn pass_keydown_to_focused(
) -> EdResult<()> {
if let Some(ref mut ed_model) = app_model.ed_model_opt {
if ed_model.has_focus {
ed_model.ed_handle_key_down(modifiers, virtual_keycode)?;
ed_model.ed_handle_key_down(
modifiers,
virtual_keycode,
&mut app_model.sound_thread_pool,
)?;
}
}

View File

@ -63,7 +63,6 @@ pub fn init_model<'a>(
EmptyCodeString {}.fail()
} else {
Ok(ast_to_mark_nodes(
code_arena,
&mut module.env,
&module.ast,
&mut mark_node_pool,
@ -199,7 +198,6 @@ impl<'a> EdModule<'a> {
#[cfg(test)]
pub mod test_ed_model {
use crate::editor::ed_error::EdResult;
use crate::editor::main::load_module;
use crate::editor::mvc::ed_model;
use crate::editor::resources::strings::HELLO_WORLD;
use crate::ui::text::caret_w_select::test_caret_w_select::convert_dsl_to_selection;
@ -212,6 +210,7 @@ pub mod test_ed_model {
use ed_model::EdModel;
use roc_ast::lang::env::Env;
use roc_ast::mem_pool::pool::Pool;
use roc_ast::module::load_module;
use roc_load::file::LoadedModule;
use roc_module::symbol::IdentIds;
use roc_module::symbol::ModuleIds;

View File

@ -7,10 +7,6 @@ use crate::editor::code_lines::CodeLines;
use crate::editor::ed_error::EdResult;
use crate::editor::ed_error::MissingSelection;
use crate::editor::grid_node_map::GridNodeMap;
/*use crate::editor::markup::attribute::Attributes;
use crate::editor::markup::nodes;
use crate::editor::markup::nodes::MarkupNode;
use crate::editor::markup::nodes::EQUALS;*/
use crate::editor::mvc::app_update::InputOutcome;
use crate::editor::mvc::ed_model::EdModel;
use crate::editor::mvc::ed_model::SelectedBlock;
@ -26,18 +22,7 @@ use crate::editor::mvc::string_update::start_new_string;
use crate::editor::mvc::string_update::update_small_string;
use crate::editor::mvc::string_update::update_string;
use crate::editor::mvc::tld_value_update::{start_new_tld_value, update_tld_val_name};
/*use crate::editor::slow_pool::MarkNodeId;
use crate::editor::slow_pool::SlowPool;
use crate::editor::syntax_highlight::HighlightStyle;
use crate::lang::ast::Def2;
use crate::lang::ast::DefId;
use crate::lang::ast::{Expr2, ExprId};
use crate::lang::constrain::constrain_expr;
use crate::lang::parse::ASTNodeId;
use crate::lang::pool::Pool;
use crate::lang::pool::PoolStr;
use crate::lang::types::Type2;
use crate::lang::{constrain::Constraint, solve};*/
use crate::editor::sound::play_sound;
use crate::ui::text::caret_w_select::CaretWSelect;
use crate::ui::text::lines::MoveCaretFun;
use crate::ui::text::selection::validate_raw_sel;
@ -77,6 +62,7 @@ use roc_types::solved_types::Solved;
use roc_types::subs::{Subs, Variable};
use roc_types::{pretty_print::content_to_string, subs::VarStore};
use snafu::OptionExt;
use threadpool::ThreadPool;
use winit::event::VirtualKeyCode;
use VirtualKeyCode::*;
@ -537,6 +523,7 @@ impl<'a> EdModel<'a> {
&mut self,
modifiers: &Modifiers,
virtual_keycode: VirtualKeyCode,
sound_thread_pool: &mut ThreadPool,
) -> EdResult<()> {
match virtual_keycode {
Left => self.move_caret_left(modifiers)?,
@ -573,6 +560,11 @@ impl<'a> EdModel<'a> {
self.show_debug_view = !self.show_debug_view;
self.dirty = true;
}
F12 => {
sound_thread_pool.execute(move || {
play_sound("./editor/src/editor/resources/sounds/bell_sound.mp3");
});
}
_ => (),
}
@ -1254,6 +1246,7 @@ pub mod test_ed_update {
use crate::window::keyboard_input::Modifiers;
use bumpalo::Bump;
use roc_module::symbol::ModuleIds;
use threadpool::ThreadPool;
use winit::event::VirtualKeyCode::*;
fn ed_res_to_res<T>(ed_res: EdResult<T>) -> Result<T, String> {
@ -2663,7 +2656,7 @@ pub mod test_ed_update {
}
for _ in 0..repeats {
ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up)?;
ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up, &mut ThreadPool::new(1))?;
}
let mut post_lines = ui_res_to_res(ed_model_to_dsl(&ed_model))?;
@ -3240,7 +3233,7 @@ pub mod test_ed_update {
)?;
for _ in 0..repeats {
ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up)?;
ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up, &mut ThreadPool::new(1))?;
}
move_caret_fun(&mut ed_model, &no_mods())?;
@ -3404,7 +3397,7 @@ pub mod test_ed_update {
)?;
for _ in 0..repeats {
ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up)?;
ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up, &mut ThreadPool::new(1))?;
}
handle_new_char(&'\u{8}', &mut ed_model)?; // \u{8} is the char for backspace on linux

Binary file not shown.

View File

@ -0,0 +1,45 @@
use rodio::{Decoder, OutputStream, Sink};
use std::fs::File;
use std::io::BufReader;
pub(crate) fn play_sound(sound_path_str: &str) {
let out_stream_res = OutputStream::try_default();
match out_stream_res {
Ok((_, out_stream_handle)) => match Sink::try_new(&out_stream_handle) {
Ok(sink) => match File::open(sound_path_str) {
Ok(file) => {
let reader = BufReader::new(file);
match Decoder::new(reader) {
Ok(decoder) => {
sink.append(decoder);
sink.sleep_until_end();
}
Err(e) => {
println!("Failed to create Decoder from BufReader from sound file at {}. Error message: {:?}", sound_path_str, e);
}
}
}
Err(e) => {
println!(
"Failed to open sound file at {}. Error message: {}",
sound_path_str, e
);
}
},
Err(e) => {
println!(
"Failed to create Sink to play sound. Error message: {:?}",
e
);
}
},
Err(e) => {
println!(
"Failed to create OutputStream to play sound. Error message: {:?}",
e
);
}
}
}

View File

@ -282,7 +282,6 @@ code {
font-family: var(--font-mono);
color: var(--code-color);
background-color: var(--code-bg-color);
padding: 0 8px;
display: inline-block;
line-height: 28px;
}
@ -303,15 +302,15 @@ pre {
overflow-x: auto;
}
pre code {
padding: 6px 8px;
}
.hidden {
/* Use !important to win all specificity fights. */
display: none !important;
}
.syntax-comment {
color: #ff0000;
}
#module-search:placeholder-shown {
padding: 0;
opacity: 0;