UNPKG

@arkts/shared

Version:
230 lines (229 loc) 6.78 kB
import { n as LanguageServerLoggerOptions, t as LanguageServerLogger } from "./lsp-logger-Mrbs36v9.js"; import * as ohos_typescript0 from "ohos-typescript"; import * as vscode_languageserver_textdocument0 from "vscode-languageserver-textdocument"; import { Range } from "vscode-languageserver-textdocument"; //#region src/client-options.d.ts interface VolarClientOptions { /** The currently tsdk path. */ tsdk: string; } interface OhosClientOptions { /** The currently ohos sdk path. If not exists the lsp will not work. */ sdkPath: string | undefined; /** The currently hms sdk path. */ hmsSdkPath: string | undefined; /** The `ets/component` folder of the SDK. If not exists the lsp will not work. */ etsComponentPath: string | undefined; /** The `ets/build-tools/ets-loader/tsconfig.json` path. If not exists the lsp will not work. */ etsLoaderConfigPath: string | undefined; /** The `ets/build-tools/ets-loader` path. If not exists the lsp will not work. */ etsLoaderPath: string | undefined; /** The libs of the SDK, and typescript compiler options. */ lib: string[]; /** typeRoots for the typescript compiler. */ typeRoots: string[]; /** The base url for the typescript compiler. */ baseUrl: string; /** The paths for the typescript compiler, will be original pass to typescript. */ paths: ohos_typescript0.MapLike<string[]>; /** The paths for the typescript compiler, will be converted to relative paths with detected tsconfig file. */ relativeWithConfigFilePaths?: ohos_typescript0.MapLike<string[]>; } interface EtsServerClientOptions { /** Volar client options. */ typescript: VolarClientOptions; /** ETS server options. */ ohos: OhosClientOptions; /** Debug mode. */ debug?: boolean; /** ETS specific options. */ ets?: { /** Resource reference diagnostic level. */ resourceReferenceDiagnostic?: "error" | "warning" | "none"; }; } //#endregion //#region src/sys-resource.d.ts interface SysResource { sys: SysResource.System; } declare namespace SysResource { interface System { color: Record<string, number>; float: Record<string, number>; string: Record<string, number>; media: Record<string, number>; symbol: Record<string, number>; plural: Record<string, number>; } function is(value: unknown): value is SysResource; function toEtsFormat(sysResource: SysResource): string[]; } //#endregion //#region src/language-server-config.d.ts interface LanguageServerConfigurator { getSdkPath(): string; getSysResource(force?: boolean): SysResource | null; getSysResourcePath(): string; getLocale(): string; } //#endregion //#region src/resource-resolver.d.ts /** * 资源类型枚举 */ declare enum ResourceType { Color = "color", String = "string", Float = "float", Boolean = "boolean", Integer = "integer", Media = "media", Profile = "profile", Symbol = "symbol", Plural = "plural", } /** * 资源引用解析结果 */ interface ResourceReference { /** 资源类型 (app 或 sys) */ scope: "app" | "sys"; /** 资源类型 */ type: ResourceType; /** 资源名称 */ name: string; /** 原始引用字符串 */ raw: string; } /** * 资源位置信息 */ interface ResourceLocation { /** 文件URI */ uri: string; /** 在文件中的位置(对于JSON资源) */ range?: Range; /** 资源值 */ value?: string; } /** * 资源索引项 */ interface ResourceIndexItem { /** 资源引用 */ reference: ResourceReference; /** 资源位置 */ location: ResourceLocation; } /** * 解析 $r() 资源引用字符串 * @param resourceRef 资源引用字符串,如 'app.color.bg_color' 或 'sys.string.title' * @returns 解析结果 */ declare function parseResourceReference(resourceRef: string): ResourceReference | null; /** * 构建资源文件路径 * @param projectRoot 项目根路径 * @param moduleName 模块名(如 'entry', 'sampleLibrary') * @param resourceType 资源类型 * @returns 资源文件路径 */ declare function buildResourceFilePath(projectRoot: string, moduleName: string, resourceType: ResourceType): string; /** * 资源解析器类 */ declare class ResourceResolver { private readonly logger; private projectRoot; private resourceIndex; private sdkPath?; getSdkPath(): string | undefined; getProjectRoot(): string; constructor(logger: LanguageServerLogger, projectRoot: string, sdkPath?: string); /** * 查找项目中的所有模块 */ private findModules; /** * 递归查找模块 */ private findModulesRecursive; /** * 判断是否应该跳过某个目录 */ private shouldSkipDirectory; /** * 构建资源索引 */ buildIndex(): Promise<void>; /** * 为特定模块构建索引 */ private indexModule; /** * 索引元素资源(JSON文件) */ private indexElementResources; /** * 索引JSON资源文件 */ private indexJsonResource; /** * 索引系统资源(sys 资源) */ private indexSystemResources; /** * 索引系统资源对象 */ private indexSysResourceObject; /** * 在系统资源文件中查找指定资源的位置 */ private findSysResourceItemRange; /** * 索引媒体资源 */ private indexMediaResources; /** * 在JSON文件中查找指定名称的项的位置 */ private findJsonItemRange; /** * 解析资源引用并返回位置 */ resolveResourceReference(resourceRef: string): Promise<ResourceLocation | null>; /** * 获取所有已索引的资源 */ getAllResources(): ResourceIndexItem[]; /** * 清除索引 */ clearIndex(): void; } //#endregion //#region src/text-document.d.ts type SerializableTextDocument = Omit<vscode_languageserver_textdocument0.TextDocument, "getText" | "positionAt" | "offsetAt" | "lineCount"> & { text: string; }; //#endregion //#region src/ts-plugin-options.d.ts type GetAPI = (version: 0) => { configurePlugin<PluginName extends keyof PluginOptions>(pluginName: PluginName, options: PluginOptions[PluginName]): void; }; interface TypescriptLanguageFeatures { getAPI?: GetAPI; } interface ETSPluginOptions { workspaceFolder: string | undefined; lspOptions: EtsServerClientOptions; } interface PluginOptions { "ets-typescript-plugin": ETSPluginOptions; } //#endregion //#region src/index.d.ts declare function typeAssert<T>(_value: unknown): asserts _value is T; //#endregion export { ETSPluginOptions, EtsServerClientOptions, LanguageServerConfigurator, LanguageServerLogger, LanguageServerLoggerOptions, OhosClientOptions, PluginOptions, ResourceIndexItem, ResourceLocation, ResourceReference, ResourceResolver, ResourceType, SerializableTextDocument, SysResource, TypescriptLanguageFeatures, VolarClientOptions, buildResourceFilePath, parseResourceReference, typeAssert };