1 | import { LanguageClientConnection, TextDocumentSyncKind, TextDocumentSyncOptions, TextDocumentContentChangeEvent, VersionedTextDocumentIdentifier, ServerCapabilities } from "../languageclient";
|
2 | import { Disposable, TextEditor, BufferStoppedChangingEvent, TextChange } from "atom";
|
3 | import * as Utils from "../utils";
|
4 | /**
|
5 | * Public: Synchronizes the documents between Atom and the language server by notifying each end of changes, opening,
|
6 | * closing and other events as well as sending and applying changes either in whole or in part depending on what the
|
7 | * language server supports.
|
8 | */
|
9 | export default class DocumentSyncAdapter {
|
10 | private _connection;
|
11 | private _editorSelector;
|
12 | private _reportBusyWhile;
|
13 | private _getLanguageIdFromEditor;
|
14 | private _disposable;
|
15 | _documentSync: TextDocumentSyncOptions;
|
16 | private _editors;
|
17 | private _versions;
|
18 | /**
|
19 | * Public: Determine whether this adapter can be used to adapt a language server based on the serverCapabilities
|
20 | * matrix textDocumentSync capability either being Full or Incremental.
|
21 | *
|
22 | * @param serverCapabilities The {ServerCapabilities} of the language server to consider.
|
23 | * @returns A {Boolean} indicating adapter can adapt the server based on the given serverCapabilities.
|
24 | */
|
25 | static canAdapt(serverCapabilities: ServerCapabilities): boolean;
|
26 | private static canAdaptV2;
|
27 | private static canAdaptV3;
|
28 | /**
|
29 | * Public: Create a new {DocumentSyncAdapter} for the given language server.
|
30 | *
|
31 | * @param _connection A {LanguageClientConnection} to the language server to be kept in sync.
|
32 | * @param documentSync The document syncing options.
|
33 | * @param _editorSelector A predicate function that takes a {TextEditor} and returns a {boolean} indicating whether
|
34 | * this adapter should care about the contents of the editor.
|
35 | * @param _getLanguageIdFromEditor A function that returns a {string} of `languageId` used for `textDocument/didOpen`
|
36 | * notification.
|
37 | */
|
38 | constructor(_connection: LanguageClientConnection, _editorSelector: (editor: TextEditor) => boolean, documentSync: TextDocumentSyncOptions | TextDocumentSyncKind | undefined, _reportBusyWhile: Utils.ReportBusyWhile, _getLanguageIdFromEditor: (editor: TextEditor) => string);
|
39 | /** Dispose this adapter ensuring any resources are freed and events unhooked. */
|
40 | dispose(): void;
|
41 | /**
|
42 | * Examine a {TextEditor} and decide if we wish to observe it. If so ensure that we stop observing it when it is
|
43 | * closed or otherwise destroyed.
|
44 | *
|
45 | * for observation.
editor A {TextEditor} to consider |
46 | */
|
47 | observeTextEditor(editor: TextEditor): void;
|
48 | private _handleGrammarChange;
|
49 | private _handleNewEditor;
|
50 | getEditorSyncAdapter(editor: TextEditor): TextEditorSyncAdapter | undefined;
|
51 | }
|
52 | /** Public: Keep a single {TextEditor} in sync with a given language server. */
|
53 | export declare class TextEditorSyncAdapter {
|
54 | private _editor;
|
55 | private _connection;
|
56 | private _documentSync;
|
57 | private _versions;
|
58 | private _reportBusyWhile;
|
59 | private _getLanguageIdFromEditor;
|
60 | private _disposable;
|
61 | private _currentUri;
|
62 | private _fakeDidChangeWatchedFiles;
|
63 | /**
|
64 | * Public: Create a {TextEditorSyncAdapter} in sync with a given language server.
|
65 | *
|
66 | * @param _editor A {TextEditor} to keep in sync.
|
67 | * @param _connection A {LanguageClientConnection} to a language server to keep in sync.
|
68 | * @param _documentSync The document syncing options.
|
69 | */
|
70 | constructor(_editor: TextEditor, _connection: LanguageClientConnection, _documentSync: TextDocumentSyncOptions, _versions: Map<string, number>, _reportBusyWhile: Utils.ReportBusyWhile, _getLanguageIdFromEditor: (editor: TextEditor) => string);
|
71 | /** The change tracking disposable listener that will ensure that changes are sent to the language server as appropriate. */
|
72 | setupChangeTracking(documentSync: TextDocumentSyncOptions): Disposable | null;
|
73 | /** Dispose this adapter ensuring any resources are freed and events unhooked. */
|
74 | dispose(): void;
|
75 | /** Get the languageId field that will be sent to the language server by simply using the `_getLanguageIdFromEditor`. */
|
76 | getLanguageId(): string;
|
77 | /**
|
78 | * Public: Create a {VersionedTextDocumentIdentifier} for the document observed by this adapter including both the Uri
|
79 | * and the current Version.
|
80 | */
|
81 | getVersionedTextDocumentIdentifier(): VersionedTextDocumentIdentifier;
|
82 | /** Public: Send the entire document to the language server. This is used when operating in Full (1) sync mode. */
|
83 | sendFullChanges(): void;
|
84 | /**
|
85 | * Public: Send the incremental text changes to the language server. This is used when operating in Incremental (2) sync mode.
|
86 | *
|
87 | * @param event The event fired by Atom to indicate the document has stopped changing including a list of changes
|
88 | * since the last time this event fired for this text editor. NOTE: The order of changes in the event is guaranteed
|
89 | * top to bottom. Language server expects this in reverse.
|
90 | */
|
91 | sendIncrementalChanges(event: BufferStoppedChangingEvent): void;
|
92 | /**
|
93 | * Public: Convert an Atom {TextEditEvent} to a language server {TextDocumentContentChangeEvent} object.
|
94 | *
|
95 | * @param change The Atom {TextEditEvent} to convert.
|
96 | * @returns A {TextDocumentContentChangeEvent} that represents the converted {TextEditEvent}.
|
97 | */
|
98 | static textEditToContentChange(change: TextChange): TextDocumentContentChangeEvent;
|
99 | private _isPrimaryAdapter;
|
100 | private _bumpVersion;
|
101 | /**
|
102 | * Ensure when the document is opened we send notification to the language server so it can load it in and keep track
|
103 | * of diagnostics etc.
|
104 | */
|
105 | private didOpen;
|
106 | private _getVersion;
|
107 | /** Called when the {TextEditor} is closed and sends the 'didCloseTextDocument' notification to the connected language server. */
|
108 | didClose(): void;
|
109 | /** Called just before the {TextEditor} saves and sends the 'willSaveTextDocument' notification to the connected language server. */
|
110 | willSave(): void;
|
111 | /**
|
112 | * Called just before the {TextEditor} saves, sends the 'willSaveWaitUntilTextDocument' request to the connected
|
113 | * language server and waits for the response before saving the buffer.
|
114 | */
|
115 | willSaveWaitUntil(): Promise<void>;
|
116 | /**
|
117 | * Called when the {TextEditor} saves and sends the 'didSaveTextDocument' notification to the connected language
|
118 | * server. Note: Right now this also sends the `didChangeWatchedFiles` notification as well but that will be sent from
|
119 | * elsewhere soon.
|
120 | */
|
121 | didSave(): void;
|
122 | didRename(): void;
|
123 | /** Public: Obtain the current {TextEditor} path and convert it to a Uri. */
|
124 | getEditorUri(): string;
|
125 | }
|