import TS from 'typescript';
import { Options } from 'prettier';
import { Range, Position } from 'vscode-languageserver/node';
import { CompileResult as CompileResult$1, PositionFlagKeys, SlotInfo, ASTPositionWithFlag } from 'qingkuai/compiler';
import { SignatureHelp, Range as Range$1 } from 'vscode-languageserver-types';

type FixedArray<T, L extends number, R extends T[] = []> = R["length"] extends L ? R : FixedArray<T, L, [...R, T]>;

type NumNum = FixedArray<number, 2>;
type MaybePromise<T = any> = T | Promise<T>;
type GetRangeFunc = (start: number, end?: number) => Range;
type RealPath = string & {
    _: never;
};
interface CustomFS {
    read: (path: string) => string;
    exist: (path: string) => boolean;
}
interface CustomPath {
    ext: (path: string) => string;
    dir: (path: string) => string;
    base: (path: string) => string;
    resolve: (...segments: string[]) => string;
    relative: (from: string, to: string) => string;
}
interface ExtensionConfiguration {
    typescriptDiagnosticsExplain: boolean;
    insertSpaceAroundInterpolation: boolean;
    additionalCodeLens: ("component" | "slot")[];
    componentTagFormatPreference: "camel" | "kebab";
    htmlHoverTip: ("tag" | "entity" | "attribute")[];
    componentAttributeFormatPreference: "camel" | "kebab";
}
type QingkuaiConfiguration = Partial<{
    exposeDestructions: boolean;
    exposeDependencies: boolean;
    insertTipComments: boolean;
    resolveImportExtension: boolean;
    convenientDerivedDeclaration: boolean;
    reserveHtmlComments: "all" | "never" | "development" | "production";
}>;
interface TSClientConfiguration {
    preference: TSUserPreferences;
    formatCodeSettings: TSFormatCodeSettings;
}
type PrettierConfiguration = Options & {
    qingkuai: Partial<{
        spaceAroundInterpolation: boolean;
        componentTagFormatPreference: "camel" | "kebab";
        componentAttributeFormatPreference: "camel" | "kebab";
    }>;
};
type CompileResult = CompileResult$1 & {
    uri: string;
    version: number;
    filePath: RealPath;
    getRange: GetRangeFunc;
    isSynchronized: boolean;
    builtInTypeDeclarationEndIndex: number;
    componentInfos: ComponentIdentifierInfo[];
    scriptLanguageId: "typescript" | "javascript";
    config: Partial<GetClientLanguageConfigResult>;
    getOffset: (position: Position) => number;
    getPosition: (offset: number) => Position;
    getInterIndex: (sourceIndex: number) => number;
    getSourceIndex: (interIndex: number, isEnd?: boolean) => number;
    isPositionFlagSet: (index: number, key: PositionFlagKeys) => boolean;
};
type TSUserPreferences = TS.server.protocol.UserPreferences;
type TSFormatCodeSettings = TS.server.protocol.FormatCodeSettings;

interface TPICCommonRequestParams {
    fileName: RealPath;
    pos: number;
}
interface HoverTipResult {
    content: string;
    posRange: NumNum;
}
interface ComponentAttributeItem {
    kind: "Prop" | "Ref";
    name: string;
    type: string;
    isEvent: boolean;
    stringCandidates: string[];
}
interface RenameLocationItem {
    fileName: string;
    loc?: Range;
    range?: NumNum;
    prefix?: string;
    suffix?: string;
}
interface ComponentIdentifierInfo {
    name: string;
    imported: boolean;
    slotNams: string[];
    relativePath: string;
    attributes: ComponentAttributeItem[];
}
interface GetClientLanguageConfigResult {
    workspacePath: string;
    prettierConfig: PrettierConfiguration;
    typescriptConfig: TSClientConfiguration;
    extensionConfig: ExtensionConfiguration;
}
interface ResolveCompletionParams {
    pos: number;
    entryName: string;
    fileName: RealPath;
    source?: string;
    original?: TS.CompletionEntryData;
}
interface FindReferenceResultItem {
    fileName: string;
    range: Range;
}
interface FindDefinitionResultItem {
    fileName: string;
    targetRange: Range;
    targetSelectionRange: Range;
}
interface FindDefinitionResult {
    range: Range;
    definitions: FindDefinitionResultItem[];
}
interface TSDiagnosticRelatedInformation {
    range: Range;
    message: string;
    filePath: RealPath;
}
interface GetDiagnosticResultItem {
    kind: number;
    code: number;
    range: Range;
    source: string;
    message: string;
    deprecated: boolean;
    unnecessary: boolean;
    relatedInformations: TSDiagnosticRelatedInformation[];
}
type SignatureHelpParams = TPICCommonRequestParams & {
    isRetrigger: boolean;
    triggerCharacter?: "," | "(" | "<";
};
type GetCompletionsResultEntry = TS.CompletionEntry & {
    label: string;
    isColor: boolean;
    isDeprecated: boolean;
    detail: string | undefined;
};
type GetCompletionsResult = Omit<TS.CompletionInfo, "entries"> & {
    entries: GetCompletionsResultEntry[];
};

interface TextEditWithPosRange {
    range: NumNum;
    newText: string;
}
interface AdapterCompileInfo {
    itos: number[];
    content: string;
    slotInfo: SlotInfo;
    scriptKind: TS.ScriptKind;
    positions: ASTPositionWithFlag[];
}
type ScriptCompletionDetail = Omit<TS.CompletionEntryDetails, "documentation" | "codeActions" | "displayParts"> & {
    detail: string;
    documentation?: string;
    codeActions?: (Omit<TS.CodeAction, "changes"> & {
        effects: TS.FileTextChanges[];
        currentFileChanges: TextEditWithPosRange[];
    })[];
};
interface CreateLsAdaptersOptions {
    ts: typeof TS;
    fs: CustomFS;
    path: CustomPath;
    typeDeclarationFilePath: string;
    getConfig: GetQingkuaiConfigFunc;
    getFullFileNames: GetFullFileNamesFunc;
    getUserPreferences: GetUserPreferencesFunc;
    getCompileInfo: GetAdapterCompileResultFunc;
    getLineAndCharacter: GetLineAndCharacterFunc;
    getFormattingOptions: GetFormattingOptionsFunc;
    getTsLanguageService: GetTsLanguageServiceFunc;
    getInterIndexByLineAndCharacter: GetInterIndexByLineAndCharacterFunc;
}
type GetLineAndCharacterFunc = (fileName: string, pos: number) => TS.LineAndCharacter | undefined;
type GetInterIndexByLineAndCharacterFunc = (fileName: string, lineAndCharacter: TS.LineAndCharacter) => number;
type GetFullFileNamesFunc = () => string[];
type GetUserPreferencesFunc = (fileName: string) => TS.UserPreferences;
type GetCompileResultFunc = (path: string) => MaybePromise<CompileResult>;
type GetFormattingOptionsFunc = (fileName: string) => TS.FormatCodeSettings;
type GetAdapterCompileResultFunc = (fileName: string) => AdapterCompileInfo;
type GetTsLanguageServiceFunc = (fileName: string) => TS.LanguageService | undefined;
type GetQingkuaiConfigFunc = (fileName: RealPath) => QingkuaiConfiguration | undefined;

declare function getKindName(node: TS.Node): string;
declare function getLength(nodeOrText: TS.Node | string): number;
declare function isInTopScope(node: TS.Node): boolean;
declare function findAncestorUntil(node: TS.Node, kind: TS.SyntaxKind): TS.Node | undefined;
declare function isEventType(type: TS.Type): boolean;
declare function findVariableDeclarationOfReactFunc(node: TS.Node): TS.VariableDeclaration | null;
declare function isDeclarationOfGlobalType(symbol: TS.Symbol | undefined): boolean;
declare function walk(node: TS.Node | undefined, callback: (node: TS.Node) => void): void;
declare function getNodeAt(node: TS.Node, pos: number): TS.Node | undefined;
declare function isBuiltInGlobalDeclaration(node: TS.Identifier, typeChecker: TS.TypeChecker): boolean | undefined;
declare function findNodeAtPosition(sourceFile: TS.SourceFile, position: number): TS.Node | undefined;

declare const tsAst_d_findAncestorUntil: typeof findAncestorUntil;
declare const tsAst_d_findNodeAtPosition: typeof findNodeAtPosition;
declare const tsAst_d_findVariableDeclarationOfReactFunc: typeof findVariableDeclarationOfReactFunc;
declare const tsAst_d_getKindName: typeof getKindName;
declare const tsAst_d_getLength: typeof getLength;
declare const tsAst_d_getNodeAt: typeof getNodeAt;
declare const tsAst_d_isBuiltInGlobalDeclaration: typeof isBuiltInGlobalDeclaration;
declare const tsAst_d_isDeclarationOfGlobalType: typeof isDeclarationOfGlobalType;
declare const tsAst_d_isEventType: typeof isEventType;
declare const tsAst_d_isInTopScope: typeof isInTopScope;
declare const tsAst_d_walk: typeof walk;
declare namespace tsAst_d {
  export {
    tsAst_d_findAncestorUntil as findAncestorUntil,
    tsAst_d_findNodeAtPosition as findNodeAtPosition,
    tsAst_d_findVariableDeclarationOfReactFunc as findVariableDeclarationOfReactFunc,
    tsAst_d_getKindName as getKindName,
    tsAst_d_getLength as getLength,
    tsAst_d_getNodeAt as getNodeAt,
    tsAst_d_isBuiltInGlobalDeclaration as isBuiltInGlobalDeclaration,
    tsAst_d_isDeclarationOfGlobalType as isDeclarationOfGlobalType,
    tsAst_d_isEventType as isEventType,
    tsAst_d_isInTopScope as isInTopScope,
    tsAst_d_walk as walk,
  };
}

declare function proxyGetCompletionsAtPosition(languageService: TS.LanguageService): void;
declare function proxyResolveModuleNameLiterals(languageServiceHost: TS.LanguageServiceHost, couldBeImpoted: (modulePath: string) => boolean): void;

declare const proxies_d_proxyGetCompletionsAtPosition: typeof proxyGetCompletionsAtPosition;
declare const proxies_d_proxyResolveModuleNameLiterals: typeof proxyResolveModuleNameLiterals;
declare namespace proxies_d {
  export {
    proxies_d_proxyGetCompletionsAtPosition as proxyGetCompletionsAtPosition,
    proxies_d_proxyResolveModuleNameLiterals as proxyResolveModuleNameLiterals,
  };
}

declare function ensureExport(languageService: TS.LanguageService, fileName: RealPath, content: string, typeDeclarationLen: number): {
    content: string;
    componentIdentifierInfos: ComponentIdentifierInfo[];
};

declare function getAndConvertHoverTip(languageService: TS.LanguageService, { fileName, pos }: TPICCommonRequestParams): HoverTipResult | null;

declare function findAndConvertReferences(languageService: TS.LanguageService, getCompileRes: GetCompileResultFunc, { fileName, pos }: TPICCommonRequestParams): Promise<FindReferenceResultItem[] | null>;

declare function getAndConvertDiagnostics(languageService: TS.LanguageService, fileName: RealPath, isSemanticProject: boolean): GetDiagnosticResultItem[];

declare function getAndConvertSignatureHelp(languageService: TS.LanguageService, lsParams: SignatureHelpParams): SignatureHelp | null;

declare function findAndConvertImplementations(languageService: TS.LanguageService, { fileName, pos }: TPICCommonRequestParams): FindReferenceResultItem[] | null;

declare function renameAndConvert(languageService: TS.LanguageService, { fileName, pos }: TPICCommonRequestParams): RenameLocationItem[] | null;
declare function prepareRenameAndConvert(languageService: TS.LanguageService, { fileName, pos }: TPICCommonRequestParams): NumNum | null;

declare const lineAndCharacter: {
    toSource(fileName: string, lineAndCharacter: TS.LineAndCharacter, isEnd?: boolean): TS.LineAndCharacter | undefined;
    toProtocolLocation(lineAndCharacter: TS.LineAndCharacter): TS.server.protocol.Location;
};
declare const lsRange: {
    fromProtocolTextSpan(fileName: string, span: TS.server.protocol.TextSpan): Range$1 | undefined;
    fromTextSpan(fileName: string, span: TS.TextSpan): Range$1 | undefined;
    fromSourceStartAndEnd(fileName: string, sourceStart: number, sourceEnd: number): Range$1;
};
declare const protocolLocation: {
    toSource(fileName: string, location: TS.server.protocol.Location, isEnd?: boolean): TS.server.protocol.Location | undefined;
    toLineAndCharacter(location: TS.server.protocol.Location): TS.LineAndCharacter;
    toSourceIndex(fileName: string, location: TS.server.protocol.Location): number;
};

declare function getAndConvertDefinitions(languageService: TS.LanguageService, { fileName, pos }: TPICCommonRequestParams): FindDefinitionResult | null;
declare function getAndConvertTypeDefinitions(languageService: TS.LanguageService, { fileName, pos }: TPICCommonRequestParams): FindDefinitionResultItem[] | null;

declare function getAndConvertCompletionInfo(languageService: TS.LanguageService, params: TPICCommonRequestParams): GetCompletionsResult | null;
declare function getAndConvertCompletionDetail(languageService: TS.LanguageService, lsParams: ResolveCompletionParams): ScriptCompletionDetail | null;

declare const index_d_ensureExport: typeof ensureExport;
declare const index_d_findAndConvertImplementations: typeof findAndConvertImplementations;
declare const index_d_findAndConvertReferences: typeof findAndConvertReferences;
declare const index_d_getAndConvertCompletionDetail: typeof getAndConvertCompletionDetail;
declare const index_d_getAndConvertCompletionInfo: typeof getAndConvertCompletionInfo;
declare const index_d_getAndConvertDefinitions: typeof getAndConvertDefinitions;
declare const index_d_getAndConvertDiagnostics: typeof getAndConvertDiagnostics;
declare const index_d_getAndConvertHoverTip: typeof getAndConvertHoverTip;
declare const index_d_getAndConvertSignatureHelp: typeof getAndConvertSignatureHelp;
declare const index_d_getAndConvertTypeDefinitions: typeof getAndConvertTypeDefinitions;
declare const index_d_lineAndCharacter: typeof lineAndCharacter;
declare const index_d_lsRange: typeof lsRange;
declare const index_d_prepareRenameAndConvert: typeof prepareRenameAndConvert;
declare const index_d_protocolLocation: typeof protocolLocation;
declare const index_d_renameAndConvert: typeof renameAndConvert;
declare namespace index_d {
  export {
    index_d_ensureExport as ensureExport,
    index_d_findAndConvertImplementations as findAndConvertImplementations,
    index_d_findAndConvertReferences as findAndConvertReferences,
    index_d_getAndConvertCompletionDetail as getAndConvertCompletionDetail,
    index_d_getAndConvertCompletionInfo as getAndConvertCompletionInfo,
    index_d_getAndConvertDefinitions as getAndConvertDefinitions,
    index_d_getAndConvertDiagnostics as getAndConvertDiagnostics,
    index_d_getAndConvertHoverTip as getAndConvertHoverTip,
    index_d_getAndConvertSignatureHelp as getAndConvertSignatureHelp,
    index_d_getAndConvertTypeDefinitions as getAndConvertTypeDefinitions,
    index_d_lineAndCharacter as lineAndCharacter,
    index_d_lsRange as lsRange,
    index_d_prepareRenameAndConvert as prepareRenameAndConvert,
    index_d_protocolLocation as protocolLocation,
    index_d_renameAndConvert as renameAndConvert,
  };
}

declare function getRealPath(fileName: string): RealPath;
declare function isPositionFlagSetBySourceIndex(fileName: string, sourceIndex: number, key: PositionFlagKeys): boolean;
declare function isPositionFlagSetByInterIndex(fileName: string, interIndex: number, key: PositionFlagKeys, isEnd?: boolean): boolean;
declare function isComponentIdentifier(fileName: RealPath, identifier: TS.Identifier, typeChecker: TS.TypeChecker): boolean;
declare function recordRealPath(realFileName: string): void;
declare function getSourceIndex(fileName: string, interIndex: number, isEnd?: boolean): number;

declare const qingkuai_d_getRealPath: typeof getRealPath;
declare const qingkuai_d_getSourceIndex: typeof getSourceIndex;
declare const qingkuai_d_isComponentIdentifier: typeof isComponentIdentifier;
declare const qingkuai_d_isPositionFlagSetByInterIndex: typeof isPositionFlagSetByInterIndex;
declare const qingkuai_d_isPositionFlagSetBySourceIndex: typeof isPositionFlagSetBySourceIndex;
declare const qingkuai_d_recordRealPath: typeof recordRealPath;
declare namespace qingkuai_d {
  export {
    qingkuai_d_getRealPath as getRealPath,
    qingkuai_d_getSourceIndex as getSourceIndex,
    qingkuai_d_isComponentIdentifier as isComponentIdentifier,
    qingkuai_d_isPositionFlagSetByInterIndex as isPositionFlagSetByInterIndex,
    qingkuai_d_isPositionFlagSetBySourceIndex as isPositionFlagSetBySourceIndex,
    qingkuai_d_recordRealPath as recordRealPath,
  };
}

declare let typeRefStatement: string;
declare let typeDeclarationFilePath: string;
declare let getCompileInfo: GetAdapterCompileResultFunc;
declare const resolvedQingkuaiModule: Map<RealPath, Set<string>>;
declare const qingkuaiDiagnostics: Map<RealPath, TS.Diagnostic[]>;

declare const init: (options: CreateLsAdaptersOptions) => void;

export { tsAst_d as astUtil, index_d as convertor, getCompileInfo, init, proxies_d as proxies, qingkuaiDiagnostics, qingkuai_d as qkContext, resolvedQingkuaiModule, typeDeclarationFilePath, typeRefStatement };
