UNPKG

langium

Version:

A language engineering tool for the Language Server Protocol

181 lines 8.07 kB
/****************************************************************************** * Copyright 2024 TypeFox GmbH * This program and the accompanying materials are made available under the * terms of the MIT License, which is available in the project root. ******************************************************************************/ import type { Connection, TextDocumentsConfiguration, TextDocumentChangeEvent, TextDocumentWillSaveEvent, RequestHandler, TextEdit, Event, NotebookCell, NotebookDocument, DocumentUri } from 'vscode-languageserver'; import { Disposable } from 'vscode-languageserver'; import type { URI } from '../utils/uri-utils.js'; import type { NotebookDocumentChangeEvent } from 'vscode-languageserver/lib/common/notebook.js'; export type TextDocumentConnection = Pick<Connection, 'onDidOpenTextDocument' | 'onDidChangeTextDocument' | 'onDidCloseTextDocument' | 'onWillSaveTextDocument' | 'onWillSaveTextDocumentWaitUntil' | 'onDidSaveTextDocument'>; /** * A manager service that keeps track of all currently opened text documents. * * Designed to be compatible with the `TextDocuments` class in the `vscode-languageserver` package. */ export interface TextDocuments<T extends { uri: string; }> { /** * An event that fires when a text document managed by this manager * has been opened. */ readonly onDidOpen: Event<TextDocumentChangeEvent<T>>; /** * An event that fires when a text document managed by this manager * has been opened or the content changes. */ readonly onDidChangeContent: Event<TextDocumentChangeEvent<T>>; /** * An event that fires when a text document managed by this manager * will be saved. */ readonly onWillSave: Event<TextDocumentWillSaveEvent<T>>; /** * Sets a handler that will be called if a participant wants to provide * edits during a text document save. */ onWillSaveWaitUntil(handler: RequestHandler<TextDocumentWillSaveEvent<T>, TextEdit[], void>): void; /** * An event that fires when a text document managed by this manager * has been saved. */ readonly onDidSave: Event<TextDocumentChangeEvent<T>>; /** * An event that fires when a text document managed by this manager * has been closed. */ readonly onDidClose: Event<TextDocumentChangeEvent<T>>; /** * Returns the document for the given URI. Returns undefined if * the document is not managed by this instance. * * @param uri The text document's URI to retrieve. * @return the text document or `undefined`. */ get(uri: string | URI): T | undefined; /** * Sets the text document managed by this instance. * @param document The text document to add. * @returns `true` if the document didn't exist yet, `false` if it was already present. */ set(document: T): boolean; /** * Deletes a text document managed by this instance. */ delete(uri: string | URI | T): void; /** * Returns all text documents managed by this instance. * * @return all text documents. */ all(): T[]; /** * Returns the URIs of all text documents managed by this instance. * * @return the URI's of all text documents. */ keys(): string[]; /** * Listens for `low level` notification on the given connection to * update the text documents managed by this instance. * * Please note that the connection only provides handlers not an event model. Therefore * listening on a connection will overwrite the following handlers on a connection: * `onDidOpenTextDocument`, `onDidChangeTextDocument`, `onDidCloseTextDocument`, * `onWillSaveTextDocument`, `onWillSaveTextDocumentWaitUntil` and `onDidSaveTextDocument`. * * Use the corresponding events on the TextDocuments instance instead. * * @param connection The connection to listen on. */ listen(connection: TextDocumentConnection): Disposable; } /** * Normalizing text document manager. Normalizes all incoming URIs to the same format used by VS Code. */ export declare class NormalizedTextDocuments<T extends { uri: string; }> implements TextDocuments<T> { private readonly _configuration; private readonly _syncedDocuments; private readonly _onDidChangeContent; private readonly _onDidOpen; private readonly _onDidClose; private readonly _onDidSave; private readonly _onWillSave; private _willSaveWaitUntil; constructor(configuration: TextDocumentsConfiguration<T>); get onDidOpen(): Event<TextDocumentChangeEvent<T>>; get onDidChangeContent(): Event<TextDocumentChangeEvent<T>>; get onWillSave(): Event<TextDocumentWillSaveEvent<T>>; onWillSaveWaitUntil(handler: RequestHandler<TextDocumentWillSaveEvent<T>, TextEdit[], void>): void; get onDidSave(): Event<TextDocumentChangeEvent<T>>; get onDidClose(): Event<TextDocumentChangeEvent<T>>; get(uri: string | URI): T | undefined; set(document: T): boolean; delete(uri: string | T | URI): void; all(): T[]; keys(): string[]; listen(connection: Connection): Disposable; } export interface NotebookDocuments<T extends { uri: string; }> { get cellTextDocuments(): TextDocuments<T>; getCellTextDocument(cell: NotebookCell): T | undefined; getNotebookDocument(uri: string | URI): NotebookDocument | undefined; getNotebookCell(uri: string | URI): NotebookCell | undefined; findNotebookDocumentForCell(cell: string | URI | NotebookCell): NotebookDocument | undefined; get onDidOpen(): Event<NotebookDocument>; get onDidSave(): Event<NotebookDocument>; get onDidChange(): Event<NotebookDocumentChangeEvent>; get onDidClose(): Event<NotebookDocument>; /** * Listens for `low level` notification on the given connection to * update the notebook documents managed by this instance. * * Please note that the connection only provides handlers not an event model. Therefore * listening on a connection will overwrite the following handlers on a connection: * `onDidOpenNotebookDocument`, `onDidChangeNotebookDocument`, `onDidSaveNotebookDocument`, * and `onDidCloseNotebookDocument`. * * @param connection The connection to listen on. */ listen(connection: Connection): Disposable; } export declare class NormalizedNotebookDocuments<T extends { uri: DocumentUri; }> implements NotebookDocuments<T> { private readonly notebookDocuments; private readonly notebookCellMap; private readonly _onDidOpen; private readonly _onDidSave; private readonly _onDidChange; private readonly _onDidClose; private readonly _cellTextDocuments; constructor(configurationOrTextDocuments: TextDocumentsConfiguration<T> | TextDocuments<T>); get cellTextDocuments(): TextDocuments<T>; getCellTextDocument(cell: NotebookCell): T | undefined; getNotebookDocument(uri: string | URI): NotebookDocument | undefined; getNotebookCell(uri: string | URI): NotebookCell | undefined; findNotebookDocumentForCell(cell: string | URI | NotebookCell): NotebookDocument | undefined; get onDidOpen(): Event<NotebookDocument>; get onDidSave(): Event<NotebookDocument>; get onDidChange(): Event<NotebookDocumentChangeEvent>; get onDidClose(): Event<NotebookDocument>; /** * Listens for `low level` notification on the given connection to * update the notebook documents managed by this instance. * * Please note that the connection only provides handlers not an event model. Therefore * listening on a connection will overwrite the following handlers on a connection: * `onDidOpenNotebookDocument`, `onDidChangeNotebookDocument`, `onDidSaveNotebookDocument`, * and `onDidCloseNotebookDocument`. * * @param connection The connection to listen on. */ listen(connection: Connection): Disposable; private updateCellMap; } //# sourceMappingURL=normalized-text-documents.d.ts.map