import { SchemaRegistry } from '@mcschema/core'; import { CompletionItem, LanguageService as JsonLanguageService } from 'vscode-json-languageservice'; import { TextDocument } from 'vscode-languageserver-textdocument'; import * as lsp from 'vscode-languageserver/node'; import { plugins } from '..'; import { VanillaData } from '../data/VanillaData'; import { IdentityNode } from '../nodes'; import { CacheFile, ClientCapabilities, CommandTree, Config, CreateWorkDoneProgressServerReporterFunction, DatapackDocument, FetchConfigFunction, FileType, ParsingContext, PathAccessibleFunction, PublishDiagnosticsFunction, ReadFileFunction, Uri, VersionInformation } from '../types'; declare type ShowMessage = (message: string) => void; declare type DatapackLanguageServiceOptions = { applyEdit?: (edit: lsp.ApplyWorkspaceEditParams | lsp.WorkspaceEdit) => Promise; cacheFile?: CacheFile; capabilities?: ClientCapabilities; createWorkDoneProgress?: CreateWorkDoneProgressServerReporterFunction; defaultLocaleCode?: string; fetchConfig?: FetchConfigFunction; globalStoragePath?: string; jsonService?: JsonLanguageService; pathAccessible?: PathAccessibleFunction; plugins?: Map; publishDiagnostics?: PublishDiagnosticsFunction; readFile?: ReadFileFunction; roots?: Uri[]; showInformationMessage?: ShowMessage; versionInformation?: VersionInformation; }; export declare class DatapackLanguageService { readonly applyEdit: ((edit: lsp.ApplyWorkspaceEditParams | lsp.WorkspaceEdit) => Promise) | undefined; cacheFile: CacheFile; readonly capabilities: Readonly; readonly createWorkDoneProgress: CreateWorkDoneProgressServerReporterFunction | undefined; readonly defaultLocaleCode: string; readonly globalStoragePath: string | undefined; readonly jsonService: JsonLanguageService; readonly pathAccessible: PathAccessibleFunction; readonly rawFetchConfig: FetchConfigFunction; readonly rawPublishDiagnostics: PublishDiagnosticsFunction | undefined; readonly readFile: ReadFileFunction; /** * Sorted by priority. If you want to read something in the same order as Minecraft does, * iterate from the last element of this array to the first element. */ readonly roots: Uri[]; readonly showInformationMessage: ShowMessage | undefined; readonly versionInformation: VersionInformation | undefined; private readonly builders; /** * Key: `${type}|${ID}` */ private readonly caches; private readonly configs; private readonly textDocs; private readonly docs; private readonly urisOfIds; private readonly plugins; private languageConfigs; private contributions; private static readonly ConfigCacheSize; private static readonly OnDidUpdateCacheEventDelay; private onDidUpdateCacheTimeout; static readonly GeneralTriggerCharacters: string[]; static readonly McfunctionTriggerCharacters: string[]; static readonly AllTriggerCharacters: string[]; static readonly AllCommitCharacters: string[]; static readonly FullRange: lsp.Range; constructor(options?: DatapackLanguageServiceOptions); init(): Promise; /** * Fetches the configuration for the specific URI and stores it in the cache. * * If the `configuration` request isn't supported by the client, the built-in fallback config is used. * @param uri A file URI. */ fetchConfig(uri: Uri): Promise; /** * Gets the cached configuration for the specific URI. If no config has been cached for this * URI, the function `fetchConfig` is called. * * It's the developer's responsibility to call the `refetchConfigs` function after received the * `didChangeConfiguration` notification to refresh all the cached configs. * * If the `didChangeConfiguration` notification can't be dynamically registered on the client, * the function `fetchConfig` is called everytime internally. * @param uri A file URI. */ getConfig(uri: Uri): Promise; /** * Get the cache that can be accessed for the specified ID. */ getCache(type: FileType, id: IdentityNode, config: Config): Partial>; private rawGetCache; /** * Updates all cached configs with the latest config by calling `fetchConfig` internally. */ refetchConfigs(): Promise; /** * Returns the command syntax tree for the specific config. * @param config A config object. */ getCommandTree(config?: Config): Promise; /** * Returns the JSON schemas for the specific config. * @param config A config object. */ getJsonSchemas(config: Config | undefined, data: VanillaData): Promise; /** * Returns the vanilla data. * @param config A config object. */ getVanillaData(config?: Config): Promise; /** * Parses a stringified URI to a `vscode-uri`'s `URI` object. * URIs parsed by the same language service instance with the same string will * be always the same reference to the same object. * @param uri */ parseUri(uri: string): import("vscode-uri").URI; /** * Parses a stringified URI to a `vscode-uri`'s `URI` object. A slash (`/`) will * be appended at the end of the `URI` object's paths if no slashes exist there yet. * URIs parsed by the same language service instance with the same string will * be always the same reference to the same object. * @param uri */ parseRootUri(uri: string): import("vscode-uri").URI; /** * Returns the relative file path of a URI from the corresponding data pack root folder. * @param uri A URI object. */ getRel(uri: Uri): string | undefined; /** * Returns the identity of a URI. * @param uri A URI object. */ getId(uri: Uri): { id: IdentityNode; category: "function" | "advancement" | "damage_type" | "dimension" | "dimension_type" | "item_modifier" | "loot_table" | "predicate" | "recipe" | "structure" | "tag/block" | "tag/damage_type" | "tag/entity_type" | "tag/fluid" | "tag/function" | "tag/game_event" | "tag/item" | "tag/worldgen/biome" | "tag/worldgen/configured_carver" | "tag/worldgen/configured_decorator" | "tag/worldgen/configured_feature" | "tag/worldgen/configured_structure_feature" | "tag/worldgen/configured_surface_builder" | "tag/worldgen/density_function" | "tag/worldgen/noise" | "tag/worldgen/noise_settings" | "tag/worldgen/placed_feature" | "tag/worldgen/processor_list" | "tag/worldgen/structure" | "tag/worldgen/structure_set" | "tag/worldgen/template_pool" | "worldgen/biome" | "worldgen/configured_carver" | "worldgen/configured_decorator" | "worldgen/configured_feature" | "worldgen/configured_structure_feature" | "worldgen/configured_surface_builder" | "worldgen/density_function" | "worldgen/flat_level_generator_preset" | "worldgen/noise" | "worldgen/noise_settings" | "worldgen/placed_feature" | "worldgen/processor_list" | "worldgen/structure" | "worldgen/structure_set" | "worldgen/template_pool" | "worldgen/world_preset"; side: "data" | "assets"; } | undefined; /** * Gets the URI of a file from an identity. * @param id A IdentityNode object. * @param type A cache file type. * @param preferredRoot A URI object if the ID should be resolved in this specific data pack root. * @returns If `preferredRoot` is not specified, the function trys to resolve the ID to an existing file path: * if all data pack root folders have been tried and none of them contain, `null` is returned. Otherwise the * ID will be resolved as a file path in the `preferredRoot` no matter if that file actually exists. */ getUriFromId(id: IdentityNode, type: FileType, preferredRoot: Uri): Uri; getUriFromId(id: IdentityNode, type: FileType, preferredRoot?: undefined): Promise; /** * Returns all the diagnostics within a certain file. * @param uri A URI object. */ getDiagnostics(uri: Uri): Promise; /** * Returns if the documents for the specific URI are cached, i.e. have been parsed by * the `parseDocument` function and have not received any close notification. * @param uri A URI object. */ isOpen(uri: Uri): boolean; /** * Publishes all the diagnostics within a certain file to the language client. * @param uri A URI object. */ publishDiagnostics(uri: Uri): Promise; /** * Returns a `DatapackDocument` from the specific `TextDocument`. * @param isReal The text content is the real one as shown in the editor, which is not outdated * and could be updated by relevant notifications. If set to `true`, the result of this function will * be cached for use in the `getDocuments` function. */ parseDocument(textDoc: TextDocument, isReal?: boolean): Promise; /** * Re-parse an open document. Have no effects if the specified document isn't open. */ reparseOpenDocument(uri: Uri): Promise; /** * Re-parse all open documents. */ reparseAllOpenDocuments(): Promise; /** * Get the documents for the specific URI. Will read the text document from the file system when * no parsed document has been cached. The one read from the file system will never be cached as * it is possible for it to be changed without any notifications from the client and therefore * leads to de-sync. * @param uri A URI object. */ getDocuments(uri: Uri): Promise<{ doc: DatapackDocument | undefined; textDoc: TextDocument | undefined; }>; private getLangID; /** * Set the documents for the specific URI. * @param uri A URI object. * @param doc A datapack document. * @param textDoc A text document. */ setDocuments(uri: Uri, doc: DatapackDocument | Promise, textDoc: TextDocument): void; private rawParseDocument; private parseJsonDocument; private parseMcfunctionDocument; getParsingContextSync({ cursor, uri, textDoc, config, commandTree, jsonSchemas, vanillaData }: { cursor?: number; uri: Uri; textDoc: TextDocument; config: Config; vanillaData: VanillaData | undefined; commandTree: CommandTree | undefined; jsonSchemas: SchemaRegistry | undefined; }): ParsingContext; getParsingContext({ cursor, uri, textDoc }: { cursor?: number; uri: Uri; textDoc: TextDocument; }): Promise; onDidChangeTextDocument(uri: Uri, contentChanges: lsp.TextDocumentContentChangeEvent[], version: number | null): Promise; onDidCloseTextDocument(uri: Uri): void; onDidChangeWorkspaceFolders(): void; onCompletion(uri: Uri, position: lsp.Position, context?: lsp.CompletionContext): Promise; onSignatureHelp(uri: Uri, position: lsp.Position): Promise<{ signatures: lsp.SignatureInformation[]; activeParameter: number; activeSignature: number; } | null>; onFoldingRanges(uri: Uri): Promise; onHover(uri: Uri, position: lsp.Position): Promise; onDocumentFormatting(uri: Uri): Promise; private onNavigation; onDeclaration(uri: Uri, position: lsp.Position): Promise; onDefinition(uri: Uri, position: lsp.Position): Promise; onReferences(uri: Uri, position: lsp.Position): Promise; onDocumentHighlight(uri: Uri, position: lsp.Position): Promise; onSelectionRanges(uri: Uri, positions: lsp.Position[]): Promise<{ range: lsp.Range; }[] | null>; onCodeAction(uri: Uri, range: lsp.Range, diagnostics: lsp.Diagnostic[]): Promise; onCallHierarchyPrepare(uri: Uri, position: lsp.Position): Promise; onCallHierarchyIncomingCalls({ kind, name: id }: lsp.CallHierarchyItem): Promise; onCallHierarchyOutgoingCalls({ name: id }: lsp.CallHierarchyItem): Promise; onPrepareRename(uri: Uri, position: lsp.Position): Promise<{ start: import("vscode-languageserver-textdocument").Position; end: import("vscode-languageserver-textdocument").Position; } | null>; onRename(uri: Uri, position: lsp.Position, newName: string): Promise; onDocumentLinks(uri: Uri): Promise; onDocumentColor(uri: Uri): Promise; onColorPresentation(uri: Uri, range: lsp.Range, { red: r, green: g, blue: b, alpha: a }: lsp.Color): Promise; onSemanticTokens(uri: Uri): Promise; onSemanticTokensDelta(uri: Uri, previousResultId: string): Promise; /** * @deprecated Use `onSemanticTokensDelta` instead. */ onSemanticTokensEdits(uri: Uri, previousResultId: string): Promise; onAutoFixingFile(uri: Uri): Promise; onJSEvaluation(uri: Uri, range: lsp.Range): Promise; onClearVanillaData(): Promise; createFile(root: Uri, type: FileType, id: IdentityNode): Promise; private onDidUpdateCache; private onDidIDUpdate; private removeCachePositionsWith; private combineCacheOfNodes; /** * Notifies a file addition in the file system. The ID of this file will be added to the * cache for completion usage, and the content of this file will also be analysed to * accelerate the process of renaming, etc. * * Nothing will happen if the URI can't be resolved to an identity. * @param uri A URI object. */ onAddedFile(uri: Uri): Promise; /** * Notifies a file modification in the file system. The content of this file will be * re-analysed to accelerate the process of renaming, etc. * * Nothing will happen if the URI can't be resolved to an identity. * @param uri A URI object. */ onModifiedFile(uri: Uri): Promise; private mergeFileCacheIntoGlobalCache; /** * Notifies a file removal from the file system. The ID of this file will be removed from the cache * for completions, and all the references of this URI will also be deleted. * * Nothing will happen if the URI can't be resolved to an identity. * @param uri A URI object. */ onDeletedFile(uri: Uri): void; private createBuilder; private getBuilder; } export {};