Commit graph

81 commits

Author SHA1 Message Date
Olivier Goffart
b99ff1b766 Put filename in quote in import errors
So that the `debug_assert!` that fires when a error message ends with a
period does not crash the LSP when typing an incomplete filename that ends
with a '.'
2021-10-07 14:44:12 +02:00
Simon Hausmann
88ad176008 Improve diagnostics when images cannot be located for embedding
This is a two-stage change, that first centralizes the file I/O code
path for on-disk and builtin:/ files. Secondly the resource embedding
pass now produces diagnostics if a file cannot be located.
2021-10-05 23:16:46 +02:00
Simon Hausmann
4b267a8e9b Internal cleanup: Simplify string handling when accessing compiler-embedded files
For loading images that are included in the widget library that's included in turn
in the compiler binary, we need to create ImageInner::EmbeddedData
with &'static data and &'static file extension. The latter was
created using string interning, but we can also access the path of the
widget library data structure.
2021-10-05 23:16:46 +02:00
Simon Hausmann
4a26faef9a Add AboutSixtyFPS element 2021-10-05 23:16:46 +02:00
Simon Hausmann
b8ecbadea9 Embed files in the internal "library" in the compiler as binary
That way we can also embed PNG files or others in the future
2021-10-05 15:06:25 +02:00
Simon Hausmann
cd5385887b Internal cleanup: Replaces more uses of **foo with foo.as_str()
Same as commit 0b7dc17644, this makes it easier to see where the deref leads to.
2021-09-15 07:56:28 +02:00
Simon Hausmann
a855d868fc Add support for introspecting globals in the interpreter Rust API
Add three straight-forward functions:

    * pub fn globals(&self) -> impl Iterator<Item = String> + '_
    * pub fn global_properties( &self,
          global_name: &str,
      ) -> Option<impl Iterator<Item = (String, ValueType)> + '_>
    * pub fn global_callbacks(&self, global_name: &str
      ) -> Option<impl Iterator<Item = String> + '_>

Implementation wise this requires passing along a way to get the
non-normalized (original) export name, as globals() should return the
names as the developer/designer specified them, and
global_properties()/global_callbacks() normalizes.
2021-09-15 07:56:28 +02:00
Olivier Goffart
a28bc7c629 Refactor the way the builtin files are loaded
So that we can share some code accross styles
2021-09-03 22:31:54 +02:00
Tobias Hunger
d26707e41e Janitor: Fix clippy::bool_assert_comparison 2021-08-18 00:24:51 +02:00
Tobias Hunger
a387c0f60f Janitor: Fix clippy::needless_borrow 2021-08-18 00:24:51 +02:00
Tobias Hunger
c7d27d5ace Janitor: Fix clippy::redundant_clone 2021-08-18 00:24:51 +02:00
Simon Hausmann
144d1bed36 internal cleanup: replace use of imported function with qualified use 2021-08-12 18:07:58 +02:00
Simon Hausmann
e935e159ee Fix import of types with an underscore
In Exports::from_node() we use parser::identifier_text to extract the
names, which are normalized (with dashes). We need to do the same in

ImportedName::from_node() in order to allow something like

    export Main_Window := ...

and then

    import { Main-Window } from "foo.60";

or even just

    import { Main_Window } from "foo.60";

(that regressed)
2021-08-12 18:03:01 +02:00
Simon Hausmann
01c3347d19 Make fluent the new default style
It's not ugly :-)
2021-08-10 15:56:38 +02:00
Olivier Goffart
b6137ecbc4 Error when trying to use internal builtin items 2021-08-09 17:43:22 +02:00
Tobias Hunger
35dd3ed282 Janitor: Remove redundant clone() calls 2021-07-08 20:43:38 +02:00
Olivier Goffart
f73a369786 cargo fmt 2021-07-07 11:04:50 +02:00
Olivier Goffart
8f75aadc70 Move the passes module to its own file
The main reason is that i don't like to edit files named lib.rs
because there are so many files with the same name
2021-07-07 10:48:28 +02:00
Tobias Hunger
e5bdeaa804 Janitor: Remove unnecessary & 2021-07-07 08:42:28 +02:00
Olivier Goffart
13bd828b96 Update license date 2021-07-02 15:55:54 +02:00
Tobias Hunger
13d7f5e7bd Janitor: Fix typos in comments and user-facing strings
Also adapt tests for error messages containing the fixed strings.

No behavior change is intended!
2021-06-28 08:32:25 +02:00
Olivier Goffart
715d38903f Allow to omit the type of aliases 2021-06-07 10:48:09 +02:00
Olivier Goffart
8f94099a7e Fix reporting of uncalled "max" in imports 2021-05-20 18:11:58 +02:00
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