mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-27 02:16:26 +00:00
slint macro: Use Span::local_file when Rust is 1.88
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.85) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.85) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
So we can locate the files relative to the .rs file instead of relative to the Cargo.toml file. For compatibility with previous version and older rust, still try to locate files relative to the Cargo.toml for rust files. The LSP will always auto-complete relative to the .rs file The live-preview for Rust need to make the file absolute because it isn't in the case of a macro
This commit is contained in:
parent
e6f7aaffba
commit
54c378c40b
5 changed files with 31 additions and 19 deletions
|
|
@ -1520,8 +1520,9 @@ impl TypeLoader {
|
|||
) -> Option<(PathBuf, Option<&'static [u8]>)> {
|
||||
// The directory of the current file is the first in the list of include directories.
|
||||
referencing_file
|
||||
.map(base_directory)
|
||||
.and_then(|x| x.parent().map(|x| x.to_path_buf()))
|
||||
.into_iter()
|
||||
.chain(referencing_file.and_then(maybe_base_directory))
|
||||
.chain(self.compiler_config.include_paths.iter().map(PathBuf::as_path).map(
|
||||
|include_path| {
|
||||
let base = referencing_file.map(Path::to_path_buf).unwrap_or_default();
|
||||
|
|
@ -1671,15 +1672,12 @@ fn get_native_style(all_loaded_files: &mut std::collections::BTreeSet<PathBuf>)
|
|||
i_slint_common::get_native_style(false, &std::env::var("TARGET").unwrap_or_default()).into()
|
||||
}
|
||||
|
||||
/// return the base directory from which imports are loaded
|
||||
/// For a .rs file, return the manifest directory
|
||||
///
|
||||
/// For a .slint file, this is the parent directory.
|
||||
/// For a .rs file, this is relative to the CARGO_MANIFEST_DIR
|
||||
///
|
||||
/// Note: this function is only called for .rs path as part of the LSP or viewer.
|
||||
/// Because from a proc_macro, we don't actually know the path of the current file, and this
|
||||
/// is why we must be relative to CARGO_MANIFEST_DIR.
|
||||
pub fn base_directory(referencing_file: &Path) -> PathBuf {
|
||||
/// This is for compatibility with `slint!` macro as before rust 1.88,
|
||||
/// it was not possible for the macro to know the current path and
|
||||
/// the Cargo.toml file was used instead
|
||||
fn maybe_base_directory(referencing_file: &Path) -> Option<PathBuf> {
|
||||
if referencing_file.extension().is_some_and(|e| e == "rs") {
|
||||
// For .rs file, this is a rust macro, and rust macro locates the file relative to the CARGO_MANIFEST_DIR which is the directory that has a Cargo.toml file.
|
||||
let mut candidate = referencing_file;
|
||||
|
|
@ -1691,10 +1689,10 @@ pub fn base_directory(referencing_file: &Path) -> PathBuf {
|
|||
break Some(candidate);
|
||||
}
|
||||
}
|
||||
.map(|x| x.to_path_buf())
|
||||
} else {
|
||||
referencing_file.parent()
|
||||
None
|
||||
}
|
||||
.map_or_else(Default::default, |p| p.to_path_buf())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue