diff --git a/ui2abc/libarkts/src/arkts-api/index.ts b/ui2abc/libarkts/src/arkts-api/index.ts index e2e1c3c20479c89593895ec1ad5735d9d4093820..874d5f2443723a069c89c0f6f4e62b6ceaa67abc 100644 --- a/ui2abc/libarkts/src/arkts-api/index.ts +++ b/ui2abc/libarkts/src/arkts-api/index.ts @@ -32,6 +32,7 @@ export * from "./peers/Context" export { GlobalContext } from "./peers/Context" export * from "./peers/ExternalSource" export * from "./peers/Options" +export * from "./peers/DiagnosticKind" export * from "./node-utilities/ArkTsConfig" export * from "./node-utilities/Program" export * from "./peers/ImportPathManager" diff --git a/ui2abc/libarkts/src/arkts-api/peers/DiagnosticKind.ts b/ui2abc/libarkts/src/arkts-api/peers/DiagnosticKind.ts new file mode 100644 index 0000000000000000000000000000000000000000..5f93fb139719b7f5487967f1f89cfc7830af9311 --- /dev/null +++ b/ui2abc/libarkts/src/arkts-api/peers/DiagnosticKind.ts @@ -0,0 +1,24 @@ +/* + * 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 { KNativePointer } from "@koalaui/interop"; +import { ArktsObject } from "./ArktsObject" + + +export class DiagnosticKind extends ArktsObject { + constructor(peer: KNativePointer) { + super(peer); + } +} diff --git a/ui2abc/libarkts/src/arkts-api/utilities/public.ts b/ui2abc/libarkts/src/arkts-api/utilities/public.ts index 7e7ea363900297fae9dcf442fb9f4fe9355a1a84..8df45985574c2fb7d277dd50f09d1bd0fc860f60 100644 --- a/ui2abc/libarkts/src/arkts-api/utilities/public.ts +++ b/ui2abc/libarkts/src/arkts-api/utilities/public.ts @@ -16,10 +16,10 @@ import { global } from "../static/global" import { isNumber, throwError, withWarning } from "../../utils" import { KNativePointer, nullptr, KInt, KUInt} from "@koalaui/interop" -import { passNode, unpackNodeArray, unpackNonNullableNode, passString, unpackString } from "./private" -import { Es2pandaContextState, Es2pandaModifierFlags, Es2pandaMethodDefinitionKind, Es2pandaAstNodeType } from "../../generated/Es2pandaEnums" +import { passNode, unpackNodeArray, unpackNonNullableNode, passString, unpackString, passStringArray } from "./private" +import { Es2pandaContextState, Es2pandaModifierFlags, Es2pandaMethodDefinitionKind, Es2pandaAstNodeType, Es2pandaPluginDiagnosticType } from "../../generated/Es2pandaEnums" import type { AstNode } from "../peers/AstNode" -import { SourcePosition } from "../../generated" +import { DiagnosticInfo, SourcePosition, SourceRange, SuggestionInfo } from "../../generated" import { type AnnotationUsage, ClassDefinition, @@ -47,6 +47,7 @@ import { Context } from "../peers/Context" import { NodeCache } from "../node-cache" import { factory } from "../factory/nodeFactory" import { traceGlobal } from "../../tracer" +import { DiagnosticKind } from "../peers/DiagnosticKind" /** * Improve: Replace or remove with better naming @@ -404,3 +405,27 @@ export function createTypeNodeFromTsType(node: AstNode): AstNode | undefined { export function createSourcePosition(index: KUInt, line: KUInt): SourcePosition { return new SourcePosition(global.generatedEs2panda._CreateSourcePosition(global.context, index, line)) } + +export function createSourceRange(start: SourcePosition, end: SourcePosition): SourceRange { + return new SourceRange(global.generatedEs2panda._CreateSourceRange(global.context, start.peer, end.peer)) +} + +export function createDiagnosticInfo(kind: DiagnosticKind, position: SourcePosition, ...args: string[]): DiagnosticInfo { + return new DiagnosticInfo(global.es2panda._CreateDiagnosticInfo(global.context, kind.peer, passStringArray(args), args.length, position.peer)) +} + +export function createSuggestionInfo(kind: DiagnosticKind, substitutionCode: string, title: string, range: SourceRange, ...args: string[]): SuggestionInfo { + return new SuggestionInfo(global.es2panda._CreateSuggestionInfo(global.context, kind.peer, passStringArray(args), args.length, substitutionCode, title, range.peer)) +} + +export function createDiagnosticKind(message: string, type: Es2pandaPluginDiagnosticType): DiagnosticKind { + return new DiagnosticKind(global.es2panda._CreateDiagnosticKind(global.context, message, type)); +} + +export function logDiagnostic(kind: DiagnosticKind, pos: SourcePosition, ...args: string[]): void { + global.es2panda._LogDiagnostic(global.context, kind.peer, passStringArray(args), args.length, pos.peer); +} + +export function logDiagnosticWithSuggestion(diagnosticInfo: DiagnosticInfo, suggestionInfo: SuggestionInfo): void { + global.generatedEs2panda._LogDiagnosticWithSuggestion(global.context, diagnosticInfo.peer, suggestionInfo.peer); +} diff --git a/ui2abc/libarkts/src/index.ts b/ui2abc/libarkts/src/index.ts index 2c45b5cac94b57d91e3490da5095aa2b4ec89721..4c264e21b0e8bafef776a06d090e1dccd4af1522 100644 --- a/ui2abc/libarkts/src/index.ts +++ b/ui2abc/libarkts/src/index.ts @@ -38,6 +38,7 @@ export { GlobalContext } from "./arkts-api/peers/Context" export * from "./arkts-api/peers/ExternalSource" export * from "./arkts-api/peers/ImportPathManager" export * from "./arkts-api/peers/Options" +export * from "./arkts-api/peers/DiagnosticKind" export { global as arktsGlobal } from "./arkts-api/static/global" export * from "./arkts-api/static/globalUtils" export * as arkts from "./arkts-api"