feat(language-service): support cross-module resource references - #308
Open
chinokoyuki wants to merge 2 commits into
Open
feat(language-service): support cross-module resource references#308chinokoyuki wants to merge 2 commits into
chinokoyuki wants to merge 2 commits into
Conversation
|
chinokoyuki
marked this pull request as ready for review
July 9, 2026 04:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
总结
鸿蒙具有多模块特性。当开发者在
oh-package.json5中声明模块依赖后,可以通过[moduleName].type.name的语法引用其他模块中的资源(如$r('[basic].color.xxx'))。当前插件仅支持
app.xxx.xxx和sys.xxx.xxx两种引用方式,对跨模块引用格式会报错Invalid resource scope,且无法提供补全、跳转和悬停预览。此PR为issue #265 服务
改动内容
在
packages/language-service/src/classes/resource-provider.ts中新增跨模块资源引用支持,覆盖以下 4 个语言服务能力:1. 诊断(Diagnostics)
[module].type.name格式,不再误报Invalid resource scopeModule "xxx" not found,并列出可用模块名Resource [module].type.name not found in module "xxx"2. 跳转定义(Go-to-Definition)
$r('[basic].color.xxx')跳转到目标模块中对应资源的定义位置3. 自动补全(Completion)
[时自动列出项目中所有模块及其资源[basic].时自动列出basic模块中的所有资源4. 悬停预览(Hover)
[module].media.name格式的媒体资源悬停预览新增辅助方法
parseCrossModuleReference(value)[module].type.name格式findModuleByName(product, name)findReferencesInModule(module)改动文件
packages/language-service/src/classes/resource-provider.ts(+182 / -13)测试方式
basic模块 +phone模块)phone模块的oh-package.json5中声明"basic": "file:../basic"phone模块中使用$r('[basic].string.xxx')引用basic模块的资源