import { CompileResult as CompileResult$1, PositionFlagKeys, ASTPosition, ASTPositionWithFlag, SlotInfo } from 'qingkuai/compiler';
import TS from 'typescript';
import Prettier, { Options } from 'prettier';
import { Range, Position } from 'vscode-languageserver/node';
import { HoverSettings } from 'vscode-css-languageservice';
import * as vscode_languageserver_types from 'vscode-languageserver-types';
import { SignatureHelp, CompletionItem, Hover, Diagnostic, Location, Range as Range$1, WorkspaceEdit, CompletionList, CodeLens, ColorInformation, Color, LocationLink } from 'vscode-languageserver-types';
import { SignatureHelpContext } from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';

type GeneralFunc = (...args: any[]) => any;
type FixedArray<T, L extends number, R extends T[] = []> = R["length"] extends L ? R : FixedArray<T, L, [...R, T]>;

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 FindReferenceResultItem {
    fileName: string;
    range: Range;
}
interface FindDefinitionResultItem {
    fileName: string;
    targetRange: Range;
    targetSelectionRange: Range;
}
interface FindDefinitionResult {
    range: Range;
    definitions: FindDefinitionResultItem[];
}
interface InsertSnippetParam {
    text: string;
    command?: string;
}
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 GetCompletionsResultEntry = TS.CompletionEntry & {
    label: string;
    isColor: boolean;
    isDeprecated: boolean;
    detail: string | undefined;
};
type GetCompletionsResult = Omit<TS.CompletionInfo, "entries"> & {
    entries: GetCompletionsResultEntry[];
};

type NumNum = FixedArray<number, 2>;
type MaybePromise<T = any> = T | Promise<T>;
type GetRangeFunc = (start: number, end?: number) => Range;
type RealPath = string & {
    _: never;
};
type PromiseWithState<T = any> = Promise<T> & {
    state: "fullfilled" | "pending";
};
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;

declare function getInterIndexGen(stoi: number[]): (sourceIndex: number) => number;
declare function getSourceIndexGen(itos: number[]): (interIndex: number, isEnd?: boolean) => number;
declare function isPositionFlagSetGen(positions: ASTPositionWithFlag[]): (index: number, key: PositionFlagKeys) => boolean;
declare function getPositionGen(positions: ASTPosition[]): (offset: number) => Position;
declare function getRangeGen(getPosition: ReturnType<typeof getPositionGen>): (start: number, end?: number) => Range;
declare function filePathToComponentName(path: CustomPath, filePath: string): string;
declare function isIndexesInvalid(...items: (number | undefined)[]): boolean;

declare function generatePromiseAndResolver(): readonly [PromiseWithState, GeneralFunc];
declare function debounce<T extends GeneralFunc>(fn: T, delay: number, getId?: (...args: Parameters<T>) => any): (this: any, ...args: Parameters<T>) => void;

declare enum ProjectKind {
    TS = "ts",
    JS = "js"
}
declare const COMPLETION_TRIGGER_CHARS: string[];

interface CodeLensConfig {
    referencesCodeLens: {
        enabled: boolean;
        showOnAllFunctions: boolean;
    };
    implementationsCodeLens?: {
        enabled: boolean;
        showOnInterfaceMethods: boolean;
    };
}
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[];
    })[];
};
type GetCodeLensConfigFunc = (uri: string, languageId: string) => MaybePromise<CodeLensConfig>;
type GetScriptHoverFunc = (fileName: RealPath, pos: number) => MaybePromise<HoverTipResult | null>;
type GetScriptBlockSignatureFunc = (fileName: RealPath, pos: number, isRetrigger: boolean, triggerCharacter?: string) => MaybePromise<SignatureHelp | null>;
type PrepareRenameInScriptBlockFunc = (cr: CompileResult, pos: number) => MaybePromise<NumNum | null>;
type GetScriptDiagnosticsFunc = (fileName: RealPath) => MaybePromise<GetDiagnosticResultItem[]>;
type FindScriptDefinitionsFunc = (cr: CompileResult, pos: number) => MaybePromise<FindDefinitionResult | null>;
type GetScriptCompletionsFunc = (fileName: RealPath, pos: number) => MaybePromise<GetCompletionsResult | null>;
type RenameInScriptBlockFunc = (fileName: RealPath, pos: number) => MaybePromise<RenameLocationItem[] | null>;
type GetScriptCompletionDetailFunc = (item: CompletionItem) => MaybePromise<ScriptCompletionDetail | null>;
type FindScriptReferencesFunc = (fileName: RealPath, offset: number) => MaybePromise<FindReferenceResultItem[] | null>;
type GetScriptImplementationsFunc = (fileName: RealPath, pos: number) => MaybePromise<FindReferenceResultItem[] | null>;
type resolveScriptCodeLensFunc = (fileName: RealPath, pos: number, type: "reference" | "implementation") => MaybePromise<FindReferenceResultItem[] | null>;
type FindScriptTypeDefinitionsFunc = (fileName: RealPath, pos: number) => MaybePromise<FindDefinitionResultItem[] | null>;
type InsertSnippetFunc = (item: string | InsertSnippetParam) => void;
type GetCompileResultFunc = (path: string) => MaybePromise<CompileResult>;
type PrettierAndPlugins = [typeof Prettier, ...Array<string | Prettier.Plugin>];
type GetCssConfigFunc = (uri: string) => MaybePromise<HoverSettings | undefined>;
type GetScriptNavTreeFunc = (fileName: RealPath) => MaybePromise<TS.NavigationTree | null>;

declare function doHover(cr: CompileResult, offset: number, isTestingEnv: boolean, getCssConfig: GetCssConfigFunc, getScriptHover: GetScriptHoverFunc): Promise<Hover | null>;

declare function format(formater: PrettierAndPlugins, cr: CompileResult, error: (msg: string) => void): Promise<{
    range: {
        start: vscode_languageserver_types.Position;
        end: vscode_languageserver_types.Position;
    };
    newText: string;
}[] | undefined>;

declare function getDiagnostic(cr: CompileResult, getScriptDiagnostics: GetScriptDiagnosticsFunc): Promise<Diagnostic[]>;

declare function findReferences(cr: CompileResult, offset: number, path: CustomPath, getCompileRes: GetCompileResultFunc, findScriptReferences: FindScriptReferencesFunc): Promise<Location[] | null>;

declare function getSignatureHelp(cr: CompileResult, offset: number, context: SignatureHelpContext | undefined, getScriptSignature: GetScriptBlockSignatureFunc): Promise<SignatureHelp | null>;

declare function findComponentTagRanges(fileName: RealPath, componentTag: string, getCompileRes: GetCompileResultFunc): Promise<Range$1[]>;

declare function rename(cr: CompileResult, offset: number, newName: string, getCompileRes: GetCompileResultFunc, renameInScriptBlock: RenameInScriptBlockFunc): Promise<WorkspaceEdit | null>;
declare function prepareRename(cr: CompileResult, offset: number, prepareRenameInScriptBlock: PrepareRenameInScriptBlockFunc): Promise<Range$1 | null>;

declare function doComplete(cr: CompileResult, offset: number, trigger: string, document: TextDocument, isTestingEnv: boolean, projectKind: ProjectKind, insertSnippet: InsertSnippetFunc, getScriptCompletions: GetScriptCompletionsFunc): Promise<CompletionList | CompletionItem[] | null>;

declare function findImplementations(cr: CompileResult, offset: number, getImplementations: GetScriptImplementationsFunc): Promise<Location[] | null>;

declare function codeLens(cr: CompileResult, path: CustomPath, getScriptNavTree: GetScriptNavTreeFunc, getCodeLensConfig: GetCodeLensConfigFunc): Promise<CodeLens[] | null>;
declare function resolveCodeLens(codeLens: CodeLens, getCompileRes: GetCompileResultFunc, findCodeLens: resolveScriptCodeLensFunc): Promise<CodeLens>;

declare function getDocumentColors(cr: CompileResult): ColorInformation[];
declare function getColorPresentations(cr: CompileResult, range: Range$1, color: Color): vscode_languageserver_types.ColorPresentation[];

declare function findDefinitions(cr: CompileResult, offset: number, path: CustomPath, getCompileRes: GetCompileResultFunc, findScriptDefinitions: FindScriptDefinitionsFunc): Promise<vscode_languageserver_types.Location[] | LocationLink[] | null | undefined>;
declare function findTypeDefinitions(cr: CompileResult, offset: number, findTypeDefinitions: FindScriptTypeDefinitionsFunc): Promise<{
    targetRange: Range$1;
    targetUri: string;
    targetSelectionRange: Range$1;
}[] | null>;

declare function resolveEmmetCompletion(item: CompletionItem): CompletionItem;
declare function resolveScriptBlockCompletion(item: CompletionItem, getCompileRes: GetCompileResultFunc, getScriptCompletionDetail: GetScriptCompletionDetailFunc): Promise<CompletionItem>;

declare const util: {
    debounce: typeof debounce;
    filePathToComponentName: typeof filePathToComponentName;
    generatePromiseAndResolver: typeof generatePromiseAndResolver;
    getRangeGen: typeof getRangeGen;
    getPositionGen: typeof getPositionGen;
    isIndexesInvalid: typeof isIndexesInvalid;
    getInterIndexGen: typeof getInterIndexGen;
    getSourceIndexGen: typeof getSourceIndexGen;
    isPositionFlagSetGen: typeof isPositionFlagSetGen;
};

export { COMPLETION_TRIGGER_CHARS, ProjectKind, codeLens, doComplete, doHover, findComponentTagRanges, findDefinitions, findImplementations, findReferences, findTypeDefinitions, format, getColorPresentations, getDiagnostic, getDocumentColors, getSignatureHelp, prepareRename, rename, resolveCodeLens, resolveEmmetCompletion, resolveScriptBlockCompletion, util };
export type { AdapterCompileInfo, CompileResult, ComponentIdentifierInfo, CustomFS, CustomPath, InsertSnippetParam, PrettierAndPlugins, PromiseWithState, QingkuaiConfiguration, RealPath, ScriptCompletionDetail };
