UNPKG

greybel-languageserver-core

Version:
142 lines (141 loc) 5.15 kB
/// <reference types="node" /> import type { EventEmitter } from "stream"; import type { createConnection, SemanticTokensBuilder } from 'vscode-languageserver'; import type { TextDocument } from 'vscode-languageserver-textdocument'; import type { URI } from 'vscode-uri'; import type { LRUCache as LRU } from 'lru-cache'; import type { ASTBaseBlockWithScope } from 'miniscript-core'; import { Document as TypeDocument } from 'greybel-type-analyzer'; export type LanguageId = 'greyscript'; export declare const LanguageId: LanguageId; export type ConfigurationNamespace = 'greybel'; export declare const ConfigurationNamespace: ConfigurationNamespace; export declare const DefaultFileExtensions: string[]; export declare enum IndentationType { Tab = "Tab", Whitespace = "Whitespace" } export declare enum TypeAnalyzerStrategy { Dependency = "Dependency", Workspace = "Workspace" } export interface IConfigurationRequest { fileExtensions: string; formatter: boolean; autocomplete: boolean; hoverdocs: boolean; diagnostic: boolean; transpiler: { beautify: { keepParentheses: boolean; indentation: IndentationType; indentationSpaces: number; }; }; typeAnalyzer: { strategy: TypeAnalyzerStrategy; exclude: string; }; } export interface IConfiguration { fileExtensions: string[]; formatter: boolean; autocomplete: boolean; hoverdocs: boolean; diagnostic: boolean; transpiler: { beautify: { keepParentheses: boolean; indentation: IndentationType; indentationSpaces: number; }; }; typeAnalyzer: { strategy: TypeAnalyzerStrategy; exclude: string; }; } export declare enum DependencyType { Root = "root", Include = "include", Import = "import", NativeImport = "native-import" } /** * Pattern: import:myVariable!./path/to/file.gs */ export type DependencyRawLocation = string; export interface IDependencyLocation { type: DependencyType; location: string; args?: string[]; } export declare function parseDependencyLocation(location: IDependencyLocation): DependencyRawLocation; export declare function parseDependencyRawLocation(rawLocation: DependencyRawLocation): IDependencyLocation; export declare function getAllDependencyLocationsFromGraph(node: IActiveDocumentImportGraphNode, visited?: Set<string>): IActiveDocument[]; export interface IActiveDocument { context: IContext; version: number; textDocument: TextDocument; typeDocument: TypeDocument; parsedPayload: ASTBaseBlockWithScope | null; errors: Error[]; getDirectory(): URI; getDependencies(): Promise<IDependencyLocation[]>; getIncludeUris(): Promise<DependencyRawLocation[]>; getImportUris(): Promise<DependencyRawLocation[]>; getNativeImportUris(): Promise<DependencyRawLocation[]>; } export interface IActiveDocumentImport { document: IActiveDocument; location: IDependencyLocation; } export interface IActiveDocumentImportGraphNode { item: IActiveDocumentImport; children: IActiveDocumentImportGraphNode[]; } export interface IDocumentManager extends EventEmitter { readonly documents: LRU<string, IActiveDocument>; readonly context: IContext; setContext(context: IContext): any; schedule(document: TextDocument): boolean; getOrOpen(target: string): Promise<IActiveDocument | null>; get(document: TextDocument): IActiveDocument; getLatest(document: TextDocument, timeout?: number): Promise<IActiveDocument>; clear(document: TextDocument): void; } export interface IDocumentMergerCache { createCacheKey(source: IActiveDocument, documents: IActiveDocument[]): number; registerCacheKey(key: number, documentUri: string): void; flushCacheKey(documentUri: string): void; flushCache(): void; } export interface IDocumentMerger { readonly cache: IDocumentMergerCache; build(document: IActiveDocument, context: IContext): Promise<TypeDocument>; } export interface IContext extends EventEmitter { readonly connection: ReturnType<typeof createConnection>; readonly fs: IFileSystem; readonly documentManager: IDocumentManager; readonly documentMerger: IDocumentMerger; features: IContextFeatures; createSemanticTokensBuilder(): SemanticTokensBuilder; getConfiguration(): IConfiguration; listen(): Promise<void>; } export interface IFileSystem extends EventEmitter { getWorkspaceFolderUris(): Promise<URI[]>; getWorkspaceFolderUri(source: URI): Promise<URI | null>; getWorkspaceRelatedFiles(): Promise<URI[]>; getAllTextDocuments(): TextDocument[]; findExistingPath(targetUri: string, ...altUris: string[]): Promise<string | null>; fetchTextDocument(targetUri: string): Promise<TextDocument | null>; getTextDocument(targetUri: string): Promise<TextDocument | null>; readFile(targetUri: string): Promise<string>; listen(connection: ReturnType<typeof createConnection>): any; } export interface IContextFeatures { configuration: boolean; workspaceFolder: boolean; }