UNPKG

javascript-typescript-langserver

Version:

Implementation of the Language Server Protocol for JavaScript and TypeScript

113 lines (112 loc) 4.45 kB
import { Span } from 'opentracing'; import { Observable } from 'rxjs'; import { LanguageClient } from './lang-handler'; import { InMemoryFileSystem } from './memfs'; export interface FileSystem { /** * Returns all files in the workspace under base * * @param base A URI under which to search, resolved relative to the rootUri * @return An Observable that emits URIs */ getWorkspaceFiles(base?: string, childOf?: Span): Observable<string>; /** * Returns the content of a text document * * @param uri The URI of the text document, resolved relative to the rootUri * @return An Observable that emits the text document content */ getTextDocumentContent(uri: string, childOf?: Span): Observable<string>; } export declare class RemoteFileSystem implements FileSystem { private client; constructor(client: LanguageClient); /** * The files request is sent from the server to the client to request a list of all files in the workspace or inside the directory of the base parameter, if given. * A language server can use the result to index files by filtering and doing a content request for each text document of interest. */ getWorkspaceFiles(base?: string, childOf?: Span): Observable<string>; /** * The content request is sent from the server to the client to request the current content of * any text document. This allows language servers to operate without accessing the file system * directly. */ getTextDocumentContent(uri: string, childOf?: Span): Observable<string>; } export declare class LocalFileSystem implements FileSystem { private rootUri; /** * @param rootUri The root URI that is used if `base` is not specified */ constructor(rootUri: string); /** * Converts the URI to an absolute path on the local disk */ protected resolveUriToPath(uri: string): string; getWorkspaceFiles(base?: string): Observable<string>; getTextDocumentContent(uri: string): Observable<string>; } /** * Synchronizes a remote file system to an in-memory file system * * TODO: Implement Disposable with Disposer */ export declare class FileSystemUpdater { private remoteFs; private inMemoryFs; /** * Observable for a pending or completed structure fetch */ private structureFetch?; /** * Map from URI to Observable of pending or completed content fetch */ private fetches; /** * Limits concurrent fetches to not fetch thousands of files in parallel */ private concurrencyLimit; constructor(remoteFs: FileSystem, inMemoryFs: InMemoryFileSystem); /** * Fetches the file content for the given URI and adds the content to the in-memory file system * * @param uri URI of the file to fetch * @param childOf A parent span for tracing * @return Observable that completes when the fetch is finished */ fetch(uri: string, childOf?: Span): Observable<never>; /** * Returns a promise that is resolved when the given URI has been fetched (at least once) to the in-memory file system. * This function cannot be cancelled because multiple callers get the result of the same operation. * * @param uri URI of the file to ensure * @param childOf An OpenTracing span for tracing * @return Observable that completes when the file was fetched */ ensure(uri: string, childOf?: Span): Observable<never>; /** * Fetches the file/directory structure for the given directory from the remote file system and saves it in the in-memory file system * * @param childOf A parent span for tracing */ fetchStructure(childOf?: Span): Observable<never>; /** * Returns a promise that is resolved as soon as the file/directory structure for the given directory has been synced * from the remote file system to the in-memory file system (at least once) * * @param span An OpenTracing span for tracing */ ensureStructure(childOf?: Span): Observable<never>; /** * Invalidates the content fetch cache of a file. * The next call to `ensure` will do a refetch. * * @param uri URI of the file that changed */ invalidate(uri: string): void; /** * Invalidates the structure fetch cache. * The next call to `ensureStructure` will do a refetch. */ invalidateStructure(): void; }