使用Sailfish TemplateOnce时rust-analyzer报‘failed to load file’宏错误
解决Rust Sailfish模板引擎rust-analyzer提示无法加载模板文件的问题
你的代码运行正常,但VSCode中rust-analyzer对#[derive(TemplateOnce)]报路径错误,可尝试以下方案:
显式配置模板目录:在项目根目录的
Cargo.toml中添加模板目录配置,帮助rust-analyzer准确定位文件:[sailfish] template_dir = "templates" # 替换为你实际的模板文件所在目录,默认值为templates/重新加载rust-analyzer工作区:在VSCode中按下
Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(Mac),执行Rust Analyzer: Reload Workspace命令,强制工具重新解析项目结构。开启proc宏支持:打开VSCode设置,搜索
rust-analyzer.procMacro.enable,确保该选项设为true——rust-analyzer需要此配置才能正确处理Sailfish的派生宏。触发宏缓存更新:修改模板文件(比如添加一个空行再保存),或修改包含
#[derive(TemplateOnce)]的Rust文件并保存,让rust-analyzer重新处理宏展开逻辑。确认工作区根目录:确保VSCode打开的是包含
Cargo.toml的项目根目录,而非子目录,否则rust-analyzer可能无法识别模板文件的相对路径。
内容的提问来源于stack exchange,提问作者sudoExclamationExclamation
相关产品推荐
相关产品推荐

