Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
488dfe9
fix: 替换不安全的`new Function()`, 改为createRequire加载SDK中的`sysResource.js`
Groupguanfang Sep 15, 2025
9737adc
docs(changeset): fix: 替换不安全的`new Function()`, 改为createRequire加载SDK中的`…
Groupguanfang Sep 15, 2025
ca0f7f4
fix: 删除没有用到过的函数
Groupguanfang Sep 15, 2025
86ba304
fix: 修复类型问题,改为已有类型
Groupguanfang Sep 15, 2025
f257380
refactor: 替换正则匹配方案为AST方案 (#147)
Groupguanfang Sep 16, 2025
fe10810
refactor: 不使用ets.createSourceFile而使用volar中已有的SourceFiles
Groupguanfang Sep 16, 2025
a66256a
chore: 移除位于vscode插件内部的资源自动补全机制
Groupguanfang Sep 16, 2025
4b92a91
docs(changeset): chore: 移除位于vscode插件内部的资源自动补全机制
Groupguanfang Sep 16, 2025
73151c5
refactor: 删除旧版格式化逻辑,使用`language-service`替代并删除用于格式化的languageService,大幅…
Groupguanfang Sep 16, 2025
6f22ab2
docs(changeset): refactor: 删除旧版格式化逻辑,使用`language-service`替代并删除用于格式化的l…
Groupguanfang Sep 16, 2025
634a85b
fix: ci & prepare add new resource watcher
Groupguanfang Sep 16, 2025
387cf2e
docs(changeset): fix: prepare add new resource watcher
Groupguanfang Sep 16, 2025
6f15d62
fix: remove `vitest.config.ts`
Groupguanfang Sep 16, 2025
8ac5736
fix: rename the current services
Groupguanfang Sep 16, 2025
d5f73b0
docs(changeset): fix: rename the current services
Groupguanfang Sep 16, 2025
31673e8
test: fix
Groupguanfang Sep 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fine-emus-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@arkts/language-server": patch
---

fix: rename the current services
6 changes: 6 additions & 0 deletions .changeset/little-parents-wish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@arkts/language-server": patch
"vscode-naily-ets": patch
---

refactor: 删除旧版格式化逻辑,使用`language-service`替代并删除用于格式化的 languageService,大幅提高性能
5 changes: 5 additions & 0 deletions .changeset/loose-radios-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-naily-ets": patch
---

chore: 移除位于 vscode 插件内部的资源自动补全机制
5 changes: 5 additions & 0 deletions .changeset/proud-chicken-create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@arkts/language-server": patch
---

fix: prepare add new resource watcher
8 changes: 8 additions & 0 deletions .changeset/tame-cars-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@arkts/language-plugin": patch
"@arkts/language-server": patch
"@arkts/shared": patch
"vscode-naily-ets": patch
---

fix: 替换不安全的`new Function()`, 改为 createRequire 加载 SDK 中的`sysResource.js`
80 changes: 80 additions & 0 deletions packages/language-server/src/classes/base-resource-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import type { Position } from '@volar/language-server/node'
import type * as ets from 'ohos-typescript'
import type { TextDocument } from 'vscode-languageserver-textdocument'
import type { GlobalRCallInfo } from './global-call-expression-finder'
import { logger } from '../logger'
import { GlobalRCallFinder } from './global-call-expression-finder'

/**
* 资源服务基类
* 提供通用的 $r() 调用查找和分析功能
*/
export abstract class BaseResourceService {
protected finder?: GlobalRCallFinder
protected ets?: typeof import('ohos-typescript')

constructor() {
this.initializeEts()
}

/**
* 初始化 ohos-typescript
*/
private async initializeEts(): Promise<void> {
if (!this.ets) {
this.ets = await import('ohos-typescript')
this.finder = new GlobalRCallFinder(this.ets)
}
}

/**
* 确保 ETS 和查找器已初始化
*/
protected async ensureInitialized(): Promise<boolean> {
if (!this.ets || !this.finder) {
await this.initializeEts()
}
return !!(this.ets && this.finder)
}

/**
* 查找文档中所有的 $r() 调用
*/
protected async findAllResourceCalls(sourceFile: ets.SourceFile): Promise<GlobalRCallInfo[]> {
if (!(await this.ensureInitialized())) {
logger.getConsola().warn('Failed to initialize ETS for resource call finding')
return []
}

try {
return this.finder!.findGlobalRCallsSimple(sourceFile)
}
catch (error) {
logger.getConsola().warn('Failed to find resource calls:', error)
return []
}
}

/**
* 查找指定位置的 $r() 调用
*/
protected async findResourceCallAtPosition(document: TextDocument, position: Position, sourceFile: ets.SourceFile): Promise<GlobalRCallInfo | null> {
const calls = await this.findAllResourceCalls(sourceFile)
const offset = document.offsetAt(position)
return calls.find(call => offset >= call.resourceStart && offset <= call.resourceEnd) || null
}

/**
* 记录服务操作日志
*/
protected info(operation: string, details?: any): void {
logger.getConsola().info(`[${this.constructor.name}] ${operation}`, JSON.stringify(details))
}

/**
* 记录错误日志
*/
protected error(operation: string, error: any): void {
logger.getConsola().error(`[${this.constructor.name}] ${operation}:`, error)
}
}
Loading