Commit graph

32 commits

Author SHA1 Message Date
Simon Hausmann
5f9f1ce047 Fix the build
Fix the remaining CompilerConfiguration uses that I missed :(
2020-12-10 16:13:17 +01:00
Olivier Goffart
7f78bea8b5 Fix a bunch of cargo clippy warnings in the compiler 2020-12-07 12:54:38 +01:00
Olivier Goffart
dec29e6d98 Allow to export structs 2020-11-17 12:22:10 +01:00
Simon Hausmann
2282697b0c Fix relative file imports from relative sources with the CLI viewer
Calling

    viewer ./examples/printerdemo/ui/printerdemo.60

would fail trying to resolve the relative path import "common.60" from
printerdemo.60, because we would apply the logic for resolving relative
include paths to be relative to the input file *also* for the initial
include path, derived from the main input file. That would result in a
search path

    ./examples/printerdemo/ui/./examples/printerdemo/ui

and that doesn't work :-)

So apply the resolution of relative include paths to be relative to the
input file only to those in the compiler configuration.
2020-11-12 15:47:50 +01:00
Simon Hausmann
9df18a3747 Apply default layout spacing and padding from the style
Extract the StyleMetrics from the style and pass it to the layout
lowering pass for application.

The tests were adjusted to explicitly specify the padding/spacing to
override the ugly style default.
2020-11-04 15:20:43 +01:00
Simon Hausmann
e3c4e06ae9 Add an import_type helper function to TypeLoader
To be used soon.
2020-11-04 14:20:43 +01:00
Simon Hausmann
ef18e89e4f Typeloader cleanup
Split the document loading related part of load_dependency into a
separate ensure_document helper function.
2020-11-04 14:16:58 +01:00
Simon Hausmann
01be063299 Typeloader cleanup
The all_documents member does not have to be externally provided, as
long as we keep the typeloader in scope instead. Since we'll later pass
it down to the layout lowering pass, that's fine.
2020-11-04 14:16:34 +01:00
Olivier Goffart
c1380875a9 Small code simplifications 2020-11-03 19:20:39 +01:00
Simon Hausmann
3d7b69ecad Type loader cleanup
Move the entire file import handling into a separte helper function. That makes collect_dependencies() easier to read.
2020-11-03 14:49:54 +01:00
Simon Hausmann
43052dec42 Another typeloader cleanup
Use the same future interface with an std::io::Result in the
CompilerConfiguration for the fallback loading.
2020-11-03 13:54:09 +01:00
Simon Hausmann
2c7b44c08b Minor type loader cleanup
Begin unifying the interface between the file loading and the fallback
through the compiler config by also using a future in the file loading.
2020-11-03 13:50:36 +01:00
Simon Hausmann
cb8e1f54cd Avoid fetching a multiply-imported document in the online editor
Instead of storing a Box<dyn Read> to lazily read the source if needed,
store a future instead that produces the string. That way we can delay
awaiting on the future that calls fetch() and skip it if possible.
2020-11-02 17:25:28 +01:00
Olivier Goffart
decbe0ade5 Fix panic when exporting invalid types
And also still allow to export builtin component
2020-11-02 17:18:42 +01:00
Simon Hausmann
f28d6f88c2 Don't read a file multiple times when importing it multiple times
Delay the reading bit from the file system until we have a cache miss in
all_documents.
2020-11-02 16:47:15 +01:00
Simon Hausmann
94265cb9e6 Clean up typeloader a bit
Move the many duplicated parameters into a shared TypeLoader structure
2020-11-02 15:58:53 +01:00
Simon Hausmann
6890e6a45f Fix failing callback load test
If there's no path resolution callback specified, use the given path.
2020-11-02 15:13:40 +01:00
Simon Hausmann
d435a7c8b8 Fix loading of images from imported files in the online editor
We need to separate the url resolution step from the document fetching,
as we need to keep the loaded url in Rust for further
resolution.
2020-11-02 14:57:49 +01:00
Olivier Goffart
ea5e140d00 Add a callback to load the import files if they are not on the file system 2020-10-30 15:09:24 +01:00
Olivier Goffart
2d55b2a51a Don't load document twice if they are imported twice
Also protect against cyclic imports
2020-10-30 10:14:27 +01:00
Simon Hausmann
9c3cfae105 Remove indexmap again in favor of BTreeMap for import processing 2020-10-29 13:28:57 +01:00
Simon Hausmann
ed714bd332 Fix type leak across imports
Given the test case

    import { SomeType } from "somewhere.60";
    import { Blah } from "foo.60";

and foo.60 trying to use "SomeType":

    export Blah := SomeType {}

then the lookup for "SomeType" in foo.60 should fail. Instead it leaked
through the populated type registry when processing the dependencies for
the outer file.

This is fixed by ensuring that the type registry for a file only has the
global type registry as parent. To ensure that the test reliably covers
this, the import dependencies are now processed in declaration order
(hence the switch to IndexMap that preserves insertion order).
2020-10-29 12:55:00 +01:00
Olivier Goffart
6d440eb7e3 Fix using global in imported files
This required doing the type resolving for the export with all
component in the export
2020-10-29 11:01:04 +01:00
Simon Hausmann
c805f9fca4 Add test coverage for errors generated during import processing
This covers all errors except for the one where File::read_to_string() fails.
2020-10-29 10:46:40 +01:00
Olivier Goffart
58cdaeb8dd Update license header to mention that commertial option are available 2020-08-26 13:23:42 +02:00
Simon Hausmann
2823f32692 Apply license headers to all non-binary/non-json sources 2020-08-17 17:55:20 +02:00
Simon Hausmann
7aa7bd8492 Add support for exporting imports
This will allow us to break up the styles, so that one can have for example

    button.60
    checkbox.60

and finally widgets.60:

    import { Button } from "button.60";
    import { CheckBox } from "checkbox.60";
    export { Button, CheckBox };

and then the users have to only import "widgets.60";
2020-07-24 18:33:01 +02:00
Simon Hausmann
c1c2f63f29 Fix error propagation from imported files
Don't forget to collect the build diagnostics.
2020-07-23 15:32:08 +02:00
Simon Hausmann
2f8e6a8774 Use import statements for what we want to be default widget sets 2020-07-23 15:14:54 +02:00
Simon Hausmann
6ca062181e Rework the file import logic
This is more readable (one can argue) and the file system operations are
to just open, instead of stat and open.
2020-07-23 15:14:54 +02:00
Simon Hausmann
84406cc70b Add support for renaming imports
This is very useful to avoid name clashes.
2020-07-23 10:12:45 +02:00
Simon Hausmann
c38fa4cf90 Add support for import statements when loading types
This is the counter part of the export statement and right now it's
implemented as a dumb recursive file loader. This can be extended in
thefuture to support cycles between files (but not types), if
theresolution of types is done lazily.
2020-07-23 09:44:26 +02:00