UNPKG

6.48 kBTypeScriptView Raw
1import type * as atomIde from "atom-ide-base";
2import { LanguageClientConnection, DocumentFormattingParams, DocumentRangeFormattingParams, DocumentOnTypeFormattingParams, FormattingOptions, ServerCapabilities } from "../languageclient";
3import { TextEditor, Range, Point } from "atom";
4/** Public: Adapts the language server protocol "textDocument/completion" to the Atom IDE UI Code-format package. */
5export default class CodeFormatAdapter {
6 /**
7 * Public: Determine whether this adapter can be used to adapt a language server based on the serverCapabilities
8 * matrix containing either a documentFormattingProvider or a documentRangeFormattingProvider.
9 *
10 * @param serverCapabilities The {ServerCapabilities} of the language server to consider.
11 * @returns A {Boolean} indicating this adapter can adapt the server based on the given serverCapabilities.
12 */
13 static canAdapt(serverCapabilities: ServerCapabilities): boolean;
14 /**
15 * Public: Format text in the editor using the given language server connection and an optional range. If the server
16 * does not support range formatting then range will be ignored and the entire document formatted.
17 *
18 * @param connection A {LanguageClientConnection} to the language server that will format the text.
19 * @param serverCapabilities The {ServerCapabilities} of the language server that will be used.
20 * @param editor The Atom {TextEditor} containing the text that will be formatted.
21 * @param range The optional Atom {Range} containing the subset of the text to be formatted.
22 * @returns A {Promise} of an {Array} of {Object}s containing the AutoComplete+ suggestions to display.
23 */
24 static format(connection: LanguageClientConnection, serverCapabilities: ServerCapabilities, editor: TextEditor, range: Range): Promise<atomIde.TextEdit[]>;
25 /**
26 * Public: Format the entire document of an Atom {TextEditor} by using a given language server.
27 *
28 * @param connection A {LanguageClientConnection} to the language server that will format the text.
29 * @param editor The Atom {TextEditor} containing the document to be formatted.
30 * @returns A {Promise} of an {Array} of {TextEdit} objects that can be applied to the Atom TextEditor to format the document.
31 */
32 static formatDocument(connection: LanguageClientConnection, editor: TextEditor): Promise<atomIde.TextEdit[]>;
33 /**
34 * Public: Create {DocumentFormattingParams} to be sent to the language server when requesting an entire document is formatted.
35 *
36 * @param editor The Atom {TextEditor} containing the document to be formatted.
37 * @returns A {DocumentFormattingParams} containing the identity of the text document as well as options to be used in
38 * formatting the document such as tab size and tabs vs spaces.
39 */
40 static createDocumentFormattingParams(editor: TextEditor): DocumentFormattingParams;
41 /**
42 * Public: Format a range within an Atom {TextEditor} by using a given language server.
43 *
44 * @param connection A {LanguageClientConnection} to the language server that will format the text.
45 * @param range The Atom {Range} containing the range of text that should be formatted.
46 * @param editor The Atom {TextEditor} containing the document to be formatted.
47 * @returns A {Promise} of an {Array} of {TextEdit} objects that can be applied to the Atom TextEditor to format the document.
48 */
49 static formatRange(connection: LanguageClientConnection, editor: TextEditor, range: Range): Promise<atomIde.TextEdit[]>;
50 /**
51 * Public: Create {DocumentRangeFormattingParams} to be sent to the language server when requesting an entire document
52 * is formatted.
53 *
54 * @param editor The Atom {TextEditor} containing the document to be formatted.
55 * @param range The Atom {Range} containing the range of text that should be formatted.
56 * @returns A {DocumentRangeFormattingParams} containing the identity of the text document, the range of the text to
57 * be formatted as well as the options to be used in formatting the document such as tab size and tabs vs spaces.
58 */
59 static createDocumentRangeFormattingParams(editor: TextEditor, range: Range): DocumentRangeFormattingParams;
60 /**
61 * Public: Format on type within an Atom {TextEditor} by using a given language server.
62 *
63 * @param connection A {LanguageClientConnection} to the language server that will format the text.
64 * @param editor The Atom {TextEditor} containing the document to be formatted.
65 * @param point The {Point} at which the document to be formatted.
66 * @param character A character that triggered formatting request.
67 * @returns A {Promise} of an {Array} of {TextEdit} objects that can be applied to the Atom TextEditor to format the document.
68 */
69 static formatOnType(connection: LanguageClientConnection, editor: TextEditor, point: Point, character: string): Promise<atomIde.TextEdit[]>;
70 /**
71 * Public: Create {DocumentOnTypeFormattingParams} to be sent to the language server when requesting an entire
72 * document is formatted.
73 *
74 * @param editor The Atom {TextEditor} containing the document to be formatted.
75 * @param point The {Point} at which the document to be formatted.
76 * @param character A character that triggered formatting request.
77 * @returns A {DocumentOnTypeFormattingParams} containing the identity of the text document, the position of the text
78 * to be formatted, the character that triggered formatting request as well as the options to be used in formatting
79 * the document such as tab size and tabs vs spaces.
80 */
81 static createDocumentOnTypeFormattingParams(editor: TextEditor, point: Point, character: string): DocumentOnTypeFormattingParams;
82 /**
83 * Public: Create {DocumentRangeFormattingParams} to be sent to the language server when requesting an entire document
84 * is formatted.
85 *
86 * @param editor The Atom {TextEditor} containing the document to be formatted.
87 * @param range The Atom {Range} containing the range of document that should be formatted.
88 * @returns The {FormattingOptions} to be used containing the keys:
89 *
90 * - `tabSize` The number of spaces a tab represents.
91 * - `insertSpaces` {True} if spaces should be used, {False} for tab characters.
92 */
93 static getFormatOptions(editor: TextEditor): FormattingOptions;
94}