diff --git a/ets2panda/bindings/src/common/types.ts b/ets2panda/bindings/src/common/types.ts index c8bc63bb52f1c5d0818dce52e2f8b8cc90d89b64..4cfa5e7b12bae48ed41be89a8f085b868e8d5e28 100644 --- a/ets2panda/bindings/src/common/types.ts +++ b/ets2panda/bindings/src/common/types.ts @@ -151,6 +151,7 @@ export interface PathConfig { declgenOutDir: string; cacheDir?: string; externalApiPath?: string; + aceModuleJsonPath?: string; } export interface DeclgenConfig { diff --git a/ets2panda/bindings/src/common/ui_plugins_driver.ts b/ets2panda/bindings/src/common/ui_plugins_driver.ts index 1d30fb980313a62dfab333d979f6b776ca207725..464cd6b396dc8ef61bd9036fdb0dd07084331c12 100644 --- a/ets2panda/bindings/src/common/ui_plugins_driver.ts +++ b/ets2panda/bindings/src/common/ui_plugins_driver.ts @@ -65,12 +65,14 @@ class PluginContext { private program: object | undefined; private projectConfig: object | undefined; private contextPtr: KNativePointer | undefined; + private codingFilePath: string | undefined; constructor() { this.ast = undefined; this.program = undefined; this.projectConfig = undefined; this.contextPtr = undefined; + this.codingFilePath = undefined; } public setArkTSAst(ast: object): void { @@ -104,6 +106,18 @@ class PluginContext { public getContextPtr(): KNativePointer | undefined { return this.contextPtr; } + + public setCodingFilePath(codingFilePath: string): void { + this.codingFilePath = codingFilePath; + } + + public getCodingFilePath(): string | undefined { + return this.codingFilePath; + } + + public isCoding(): boolean { + return this.codingFilePath !== undefined; + } } export class PluginDriver { diff --git a/ets2panda/bindings/src/lsp/generateBuildConfig.ts b/ets2panda/bindings/src/lsp/generateBuildConfig.ts index 88206a3e5ffb1b254894443e9fcb7495bac34fe7..7eace71cb11d0a6bd3f9445e2a25b66f473516e2 100644 --- a/ets2panda/bindings/src/lsp/generateBuildConfig.ts +++ b/ets2panda/bindings/src/lsp/generateBuildConfig.ts @@ -24,6 +24,7 @@ export interface ModuleDescriptor { name: string; moduleType: string; srcPath: string; + aceModuleJsonPath?: string; } interface Json5Object { @@ -167,6 +168,10 @@ function createPluginMap(buildSdkPath: string): Record { return pluginMap; } +function addPluginPathConfigs(buildConfig: BuildConfig, module: ModuleDescriptor): void { + buildConfig.aceModuleJsonPath = module.aceModuleJsonPath; +} + export function generateBuildConfigs( pathConfig: PathConfig, modules?: ModuleDescriptor[] @@ -222,6 +227,7 @@ export function generateBuildConfigs( return depModule!.name; }) }; + addPluginPathConfigs(allBuildConfigs[module.name], module); } Object.entries(allBuildConfigs).forEach(([key, config]) => { if (enableDeclgen.get(key) === true) { diff --git a/ets2panda/bindings/src/lsp/lsp_helper.ts b/ets2panda/bindings/src/lsp/lsp_helper.ts index 4e2fc5e6f049f49a9fa30feaa0a9aa32d500e90f..a797b21ca44ad5fe39fa31f576f452fd44f29b6c 100644 --- a/ets2panda/bindings/src/lsp/lsp_helper.ts +++ b/ets2panda/bindings/src/lsp/lsp_helper.ts @@ -318,6 +318,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -337,6 +341,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -356,6 +364,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -375,6 +387,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -394,6 +410,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, searchFilePath, this.pandaLibPath); const source = this.getFileSource(searchFilePath); let localCtx = lspDriverHelper.createCtx(source, searchFilePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[searchFilePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(searchFilePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -411,6 +431,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -437,6 +461,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, searchFilePath, this.pandaLibPath); const source = this.getFileSource(searchFilePath); let localCtx = lspDriverHelper.createCtx(source, searchFilePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[searchFilePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(searchFilePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -454,6 +482,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -476,6 +508,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -497,6 +533,10 @@ export class Lsp { let searchCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let searchCtx = lspDriverHelper.createCtx(source, filePath, searchCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(searchCtx); lspDriverHelper.proceedToState(searchCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -539,6 +579,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -558,6 +602,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -578,6 +626,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, localFilePath, this.pandaLibPath); const source = this.getFileSource(localFilePath); let localCtx = lspDriverHelper.createCtx(source, localFilePath, localCfg); + const packageName = this.moduleInfos[localFilePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(localFilePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -595,6 +647,10 @@ export class Lsp { let searchCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let searchCtx = lspDriverHelper.createCtx(source, filePath, searchCfg); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(searchCtx); lspDriverHelper.proceedToState(searchCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -623,6 +679,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -642,6 +702,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -661,6 +725,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -678,6 +746,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -700,6 +772,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -719,6 +795,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -741,6 +821,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -762,6 +846,7 @@ export class Lsp { let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); const packageName = this.moduleInfos[filePath].packageName; const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); @@ -782,6 +867,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -801,6 +890,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -820,6 +913,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -849,6 +946,10 @@ export class Lsp { offset += wildcard.length; } let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -868,6 +969,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -887,6 +992,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -906,6 +1015,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -920,6 +1033,10 @@ export class Lsp { let compileFileCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let compileFileCtx = lspDriverHelper.createCtx(source, filePath, compileFileCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(compileFileCtx); lspDriverHelper.proceedToState(compileFileCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -955,6 +1072,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -981,6 +1102,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -1000,6 +1125,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -1028,6 +1157,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); @@ -1051,6 +1184,10 @@ export class Lsp { let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath); const source = this.getFileSource(filePath); let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg, this.globalContextPtr); + const packageName = this.moduleInfos[filePath].packageName; + const buildConfig = this.buildConfigs[packageName]; + PluginDriver.getInstance().getPluginContext().setCodingFilePath(filePath); + PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig); PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx); lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); diff --git a/ets2panda/bindings/test/cases.ts b/ets2panda/bindings/test/cases.ts index 316424244ca6f00288d8b4d375fe66440e5fced6..8943725e3b6151affa892ae633edf555f7a464a8 100644 --- a/ets2panda/bindings/test/cases.ts +++ b/ets2panda/bindings/test/cases.ts @@ -133,6 +133,10 @@ export const testCases: TestCases = { { start: 712, length: 11 } as TextSpan ] }, + getCodeFixesAtPosition: { + expectedFilePath: resolveTestPath('test/expected/getCodeFixesAtPosition.json'), + '1': [resolveTestPath('test/testcases/getCodeFixesAtPosition/getCodeFixesAtPosition1.ets'), 994, 995, [4000]] + }, getSignatureHelpItems: { expectedFilePath: resolveTestPath('test/expected/getSignatureHelpItems.json'), '1': [resolveTestPath('test/testcases/getSignatureHelpItems/getSignatureHelpItems1.ets'), 613], diff --git a/ets2panda/bindings/test/expected/getCodeFixesAtPosition.json b/ets2panda/bindings/test/expected/getCodeFixesAtPosition.json new file mode 100644 index 0000000000000000000000000000000000000000..25c2eb7e13218222427922320ac403ee47fcf2ea --- /dev/null +++ b/ets2panda/bindings/test/expected/getCodeFixesAtPosition.json @@ -0,0 +1,28 @@ +{ + "1": [ + { + "changes": [ + { + "fileName": "getCodeFixesAtPosition1.ets", + "textChanges": [ + { + "span": { + "start": 991, + "length": 5 + }, + "newText": "" + } + ] + }, + { + "fileName": "getCodeFixesAtPosition1.ets", + "textChanges": [] + } + ], + "description": "Fix Description", + "fixName": "Fix", + "fixId_": "UI_PLUGIN_SUGGEST", + "fixAllDescription_": "Fix All Description" + } +] + } \ No newline at end of file diff --git a/ets2panda/bindings/test/testcases/getCodeFixesAtPosition/getCodeFixesAtPosition1.ets b/ets2panda/bindings/test/testcases/getCodeFixesAtPosition/getCodeFixesAtPosition1.ets new file mode 100644 index 0000000000000000000000000000000000000000..8ac051ca62dbfb06be443f68172bf3ed900b0101 --- /dev/null +++ b/ets2panda/bindings/test/testcases/getCodeFixesAtPosition/getCodeFixesAtPosition1.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { memo, __memo_context_type, __memo_id_type } from '@ohos.arkui.stateManagement' +import { + Entry + Text, + TextAttributes, + Column, + Component, + Button, + ButtonAttribute, + ClickEvent, + UserView +} from '@ohos.arkui.component' +import { State, MutableSate, stateOf, observableProxy } from '@ohos.arkui.stateManagement' +import hilog from '@ohos.hilog' + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .onClick(() => { + console.info("hello, :") + console.log(result.toString()) + }) + .width('100%') + } + .height('100%') + } +} + +@Entry +@Component +struct Index { + build() {} +} \ No newline at end of file