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 '.'
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.
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.
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)
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.
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.
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.
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.