Commit graph

58 commits

Author SHA1 Message Date
Simon Hausmann
7240f5c5e9 Fix loading of relative paths on Windows
We use std::fs::canonicalize() and that may produce paths like

    `\\\\?\\C:\\foobar\\baz.60`

where the leading `\?` disables all parsing.

When `baz.60` imports another `.60` file using a relative path `../fob.60`,
we call `Path::join()`, which really just appends strings, producing

    ``\\\\?\\C:\\foobar\\../fob.60`

When calling `canonicalize()` again on this path, the function fails,
because any parsing was disabled,
so neither the forward slash nor the .. are resolved.

So while the forward slash handling could be solved with `components()` we
still run into

    https://users.rust-lang.org/t/unable-to-parse-relative-directories-in-windows-unc-paths/8164

To circumvent all this, use the dunce crate to canonicalize in a way on Windows
that avoids UNC paths.
2021-04-27 11:02:23 +02:00
Olivier Goffart
702b3fc67a Jump to definition of a property 2021-04-16 08:59:33 +02:00
Olivier Goffart
a3d29c6ba0 LSP: Jump to definition when the cursor is in a import statement 2021-04-14 18:50:12 +02:00
Olivier Goffart
1e730eb845 Fix panic when parsing wrong import statement
Have to be several tests because the parser bails out at the first error.
The error message is not optimal but better than a panic
2021-04-14 12:47:26 +02:00
Olivier Goffart
49868a8dae Try our best to generate a document node, even when there are errors 2021-04-14 12:06:02 +02:00
Simon Hausmann
c301cc22b5 Collect foreign imports and filter out true type fonts/collections
Resolve them early enough to produce good diagnostics. Permit true type
fonts & collections.
2021-04-14 09:17:23 +02:00
Simon Hausmann
a92c9196eb Typeloader cleanup
There are currently two places where we resolve relative file names,
once in the import handling and once when processing @image-url.

Both places called first `loader.find_file_in_include_path` and then `resolve_import_path`,
which this patch combines into one function.

That will make it easier (and less error-prone) for future call sites.
2021-04-14 09:01:52 +02:00
Simon Hausmann
cbf2b51670 Allow empty imports
Allow import "blah.60" or, more likely in the future, import "foo.ttf".
2021-04-14 09:01:49 +02:00
Olivier Goffart
7a65f31cc1 the source_file is not optional 2021-04-13 17:26:24 +02:00
Olivier Goffart
84501e630a Rename SyntaxNodeWithSourceFile to SyntaxNode
Same for SyntaxToken
2021-04-13 17:10:56 +02:00
Olivier Goffart
161a35ef5c Fix completion when there are parse errors
The type registery still need to be set on the document
2021-04-08 09:05:48 +02:00
Olivier Goffart
c3ab89dd3e Refactor import opening and its hook
This way the hook is called regardless if the file exist in the import path or not
2021-04-06 12:27:59 +02:00
Simon Hausmann
4a9cd954b8 Rework the Rust entry point API for the interpreter
Switch to the stateful `ComponentCompiler` concept that we discussed for the C++ API.
2021-03-18 18:20:50 +01:00
Simon Hausmann
3391aa0312 Remove the import resolve callback from the compiler configuration
Re-apply commit 2dcbc45cd6 but now do the
resolution from a relative import path to either an absolute path or url
in the compiler itself.
2021-03-16 14:21:33 +01:00
Simon Hausmann
e3a33dffe0 Revert "Remove the import resolve callback from the compiler configuration"
This reverts commit 2dcbc45cd6.

It breaks loading of the printer demo in the editor because in
import_file we fail to return the absolute path and thus end up
importing common.60 too many times.
2021-03-16 11:43:33 +01:00
Simon Hausmann
2dcbc45cd6 Remove the import resolve callback from the compiler configuration
It turns out that this isn't really needed with the current
implementation.
2021-03-15 20:02:46 +01:00
Simon Hausmann
70ff7baa85 Fix compilation after diagnostics API changes 2021-03-15 10:43:26 +01:00
Olivier Goffart
014e13b05f Make Diagnostic field private 2021-03-15 10:37:24 +01:00
Olivier Goffart
730b1ccff2 Refactor diagnostic: Merge BuildDiagnostic and FileDiagnostic 2021-03-12 19:32:50 +01:00
Olivier Goffart
fc35d101d9 Rename diagnostics::level to DiagnosticLevel 2021-03-11 16:27:40 +01:00
Olivier Goffart
968dfaae87 Put what is the FileDiagnostics into the SourceFile so the SourceFile has the content 2021-03-11 16:23:46 +01:00
Simon Hausmann
3e90a3c827 Improve relative image path resolution
Don't just try to resolve relative paths against the current path,
resolve them against all directories in the include search path.

Together with the include search path directive for tests in tests/cases
this will allow working around the fact that the base directory for the
rust tests is different than for the C++/NodeJS tests.
2021-01-15 16:28:17 +01:00
Olivier Goffart
57804b64a3 Don't use the canonical path for diagnostics 2020-12-28 15:07:49 +01:00
Olivier Goffart
36ea03ecff fix test compile 2020-12-28 14:39:42 +01:00
Olivier Goffart
9aca0b0a7e LSP: Allow to access to the type loader documents
So that we can go to the definition of un-open documents
2020-12-28 12:48:32 +01:00
Olivier Goffart
8267590282 Refactor: move a bunch of code in TypeLoader::new
So it will be shared
2020-12-28 12:48:32 +01:00
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