Skip to content

Commit 68386e3

Browse files
authored
Merge pull request #144 from atom-community/prettier
2 parents 1582000 + aabc1fb commit 68386e3

28 files changed

+2034
-2249
lines changed

.npmrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
public-hoist-pattern[]=*
22
package-lock=false
3-
lockfile=true
3+
lockfile=true
4+
prefer-frozen-lockfile=false

.prettierignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules
2-
package.json
32
package-lock.json
43
pnpm-lock.yaml
54
coverage

lib/adapters/apply-edit-adapter.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ export default class ApplyEditAdapter {
1010
connection.onApplyEdit((m) => ApplyEditAdapter.onApplyEdit(m))
1111
}
1212

13-
/**
14-
* Tries to apply edits and reverts if anything goes wrong.
15-
* Returns the checkpoint, so the caller can revert changes if needed.
16-
*/
13+
/** Tries to apply edits and reverts if anything goes wrong. Returns the checkpoint, so the caller can revert changes if needed. */
1714
public static applyEdits(buffer: TextBuffer, edits: atomIde.TextEdit[]): number {
1815
const checkpoint = buffer.createCheckpoint()
1916
try {

lib/adapters/autocomplete-adapter.ts

+48-58
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@ import * as ac from "atom/autocomplete-plus"
2222
import { Suggestion, TextSuggestion, SnippetSuggestion } from "../types/autocomplete-extended"
2323

2424
/**
25-
* Defines the behavior of suggestion acceptance.
26-
* Assume you have "cons|ole" in the editor (`|` is the cursor position)
25+
* Defines the behavior of suggestion acceptance. Assume you have "cons|ole" in the editor ( `|` is the cursor position)
2726
* and the autocomplete suggestion is `const`.
28-
* - if `false` -> the edits are inserted : const|ole
29-
* - if `true`` -> the edits are replaced: const|
27+
*
28+
* - If `false` -> the edits are inserted : const|ole
29+
* - If `true`` -> the edits are replaced: const|
3030
*/
3131
type ShouldReplace = boolean
3232

3333
/**
34-
* Holds a list of suggestions generated from the CompletionItem[]
35-
* list sent by the server, as well as metadata about the context
36-
* it was collected in
34+
* Holds a list of suggestions generated from the CompletionItem[] list sent by the server, as well as metadata about
35+
* the context it was collected in
3736
*/
3837
interface SuggestionCacheEntry {
3938
/** If `true`, the server will send a list of suggestions to replace this one */
@@ -57,10 +56,7 @@ class PossiblyResolvedCompletionItem {
5756
constructor(public completionItem: CompletionItem, public isResolved: boolean) {}
5857
}
5958

60-
/**
61-
* Public: Adapts the language server protocol "textDocument/completion" to the Atom
62-
* AutoComplete+ package.
63-
*/
59+
/** Public: Adapts the language server protocol "textDocument/completion" to the Atom AutoComplete+ package. */
6460
export default class AutocompleteAdapter {
6561
public static canAdapt(serverCapabilities: ServerCapabilities): boolean {
6662
return serverCapabilities.completionProvider != null
@@ -76,17 +72,14 @@ export default class AutocompleteAdapter {
7672
private _cancellationTokens: WeakMap<LanguageClientConnection, CancellationTokenSource> = new WeakMap()
7773

7874
/**
79-
* Public: Obtain suggestion list for AutoComplete+ by querying the language server using
80-
* the `textDocument/completion` request.
75+
* Public: Obtain suggestion list for AutoComplete+ by querying the language server using the `textDocument/completion` request.
8176
*
8277
* @param server An {ActiveServer} pointing to the language server to query.
8378
* @param request The {atom$AutocompleteRequest} to satisfy.
84-
* @param onDidConvertCompletionItem An optional function that takes a {CompletionItem},
85-
* an {atom$AutocompleteSuggestion} and a {atom$AutocompleteRequest}
86-
* allowing you to adjust converted items.
79+
* @param onDidConvertCompletionItem An optional function that takes a {CompletionItem}, an
80+
* {atom$AutocompleteSuggestion} and a {atom$AutocompleteRequest} allowing you to adjust converted items.
8781
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
88-
* @returns A {Promise} of an {Array} of {atom$AutocompleteSuggestion}s containing the
89-
* AutoComplete+ suggestions to display.
82+
* @returns A {Promise} of an {Array} of {atom$AutocompleteSuggestion}s containing the AutoComplete+ suggestions to display.
9083
*/
9184
public async getSuggestions(
9285
server: ActiveServer,
@@ -211,8 +204,8 @@ export default class AutocompleteAdapter {
211204
}
212205

213206
/**
214-
* Public: Obtain a complete version of a suggestion with additional information
215-
* the language server can provide by way of the `completionItem/resolve` request.
207+
* Public: Obtain a complete version of a suggestion with additional information the language server can provide by
208+
* way of the `completionItem/resolve` request.
216209
*
217210
* @param server An {ActiveServer} pointing to the language server to query.
218211
* @param suggestion An {atom$AutocompleteSuggestion} suggestion that should be resolved.
@@ -257,16 +250,15 @@ export default class AutocompleteAdapter {
257250
}
258251

259252
/**
260-
* Public: Get the trigger character that caused the autocomplete (if any). This is required because
261-
* AutoComplete-plus does not have trigger characters. Although the terminology is 'character' we treat
262-
* them as variable length strings as this will almost certainly change in the future to support '->' etc.
253+
* Public: Get the trigger character that caused the autocomplete (if any). This is required because AutoComplete-plus
254+
* does not have trigger characters. Although the terminology is 'character' we treat them as variable length strings
255+
* as this will almost certainly change in the future to support '->' etc.
263256
*
264257
* @param request An {Array} of {atom$AutocompleteSuggestion}s to locate the prefix, editor, bufferPosition etc.
265258
* @param triggerChars The {Array} of {string}s that can be trigger characters.
266-
* @returns A [{string}, boolean] where the string is the matching trigger character or an empty string
267-
* if one was not matched, and the boolean is true if the trigger character is in request.prefix, and false
268-
* if it is in the word before request.prefix. The boolean return value has no meaning if the string return
269-
* value is an empty string.
259+
* @returns A [{string}, boolean] where the string is the matching trigger character or an empty string if one was not
260+
* matched, and the boolean is true if the trigger character is in request.prefix, and false if it is in the word
261+
* before request.prefix. The boolean return value has no meaning if the string return value is an empty string.
270262
*/
271263
public static getTriggerCharacter(request: ac.SuggestionsRequestedEvent, triggerChars: string[]): [string, boolean] {
272264
// AutoComplete-Plus considers text after a symbol to be a new trigger. So we should look backward
@@ -294,8 +286,8 @@ export default class AutocompleteAdapter {
294286
}
295287

296288
/**
297-
* Public: Create TextDocumentPositionParams to be sent to the language server
298-
* based on the editor and position from the AutoCompleteRequest.
289+
* Public: Create TextDocumentPositionParams to be sent to the language server based on the editor and position from
290+
* the AutoCompleteRequest.
299291
*
300292
* @param request The {atom$AutocompleteRequest} to obtain the editor from.
301293
* @param triggerPoint The {atom$Point} where the trigger started.
@@ -306,16 +298,17 @@ export default class AutocompleteAdapter {
306298
}
307299

308300
/**
309-
* Public: Create {CompletionParams} to be sent to the language server
310-
* based on the editor and position from the Autocomplete request etc.
301+
* Public: Create {CompletionParams} to be sent to the language server based on the editor and position from the
302+
* Autocomplete request etc.
311303
*
312304
* @param request The {atom$AutocompleteRequest} containing the request details.
313305
* @param triggerCharacter The {string} containing the trigger character (empty if none).
314306
* @param triggerOnly A {boolean} representing whether this completion is triggered right after a trigger character.
315307
* @returns A {CompletionParams} with the keys:
316-
* * `textDocument` the language server protocol textDocument identification.
317-
* * `position` the position within the text document to display completion request for.
318-
* * `context` containing the trigger character and kind.
308+
*
309+
* - `textDocument` the language server protocol textDocument identification.
310+
* - `position` the position within the text document to display completion request for.
311+
* - `context` containing the trigger character and kind.
319312
*/
320313
public static createCompletionParams(
321314
request: ac.SuggestionsRequestedEvent,
@@ -330,13 +323,11 @@ export default class AutocompleteAdapter {
330323
}
331324

332325
/**
333-
* Public: Create {CompletionContext} to be sent to the language server
334-
* based on the trigger character.
326+
* Public: Create {CompletionContext} to be sent to the language server based on the trigger character.
335327
*
336328
* @param triggerCharacter The {string} containing the trigger character or '' if none.
337329
* @param triggerOnly A {boolean} representing whether this completion is triggered right after a trigger character.
338-
* @returns An {CompletionContext} that specifies the triggerKind and the triggerCharacter
339-
* if there is one.
330+
* @returns An {CompletionContext} that specifies the triggerKind and the triggerCharacter if there is one.
340331
*/
341332
public static createCompletionContext(triggerCharacter: string, triggerOnly: boolean): CompletionContext {
342333
if (triggerCharacter === "") {
@@ -349,15 +340,15 @@ export default class AutocompleteAdapter {
349340
}
350341

351342
/**
352-
* Public: Convert a language server protocol CompletionItem array or CompletionList to
353-
* an array of ordered AutoComplete+ suggestions.
343+
* Public: Convert a language server protocol CompletionItem array or CompletionList to an array of ordered
344+
* AutoComplete+ suggestions.
354345
*
355-
* @param completionItems An {Array} of {CompletionItem} objects or a {CompletionList} containing completion
356-
* items to be converted.
346+
* @param completionItems An {Array} of {CompletionItem} objects or a {CompletionList} containing completion items to
347+
* be converted.
357348
* @param request The {atom$AutocompleteRequest} to satisfy.
358349
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
359-
* @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion}
360-
* and a {atom$AutocompleteRequest} allowing you to adjust converted items.
350+
* @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion} and a
351+
* {atom$AutocompleteRequest} allowing you to adjust converted items.
361352
* @returns A {Map} of AutoComplete+ suggestions ordered by the CompletionItems sortText.
362353
*/
363354
public completionItemsToSuggestions(
@@ -394,8 +385,8 @@ export default class AutocompleteAdapter {
394385
* @param suggestion A {atom$AutocompleteSuggestion} to have the conversion applied to.
395386
* @param request The {atom$AutocompleteRequest} to satisfy.
396387
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
397-
* @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion}
398-
* and a {atom$AutocompleteRequest} allowing you to adjust converted items.
388+
* @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion} and a
389+
* {atom$AutocompleteRequest} allowing you to adjust converted items.
399390
* @returns The {atom$AutocompleteSuggestion} passed in as suggestion with the conversion applied.
400391
*/
401392
public static completionItemToSuggestion(
@@ -458,8 +449,8 @@ export default class AutocompleteAdapter {
458449
}
459450

460451
/**
461-
* Public: Applies the textEdit part of a language server protocol CompletionItem to an
462-
* AutoComplete+ Suggestion via the replacementPrefix and text properties.
452+
* Public: Applies the textEdit part of a language server protocol CompletionItem to an AutoComplete+ Suggestion via
453+
* the replacementPrefix and text properties.
463454
*
464455
* @param textEdit A {TextEdit} from a CompletionItem to apply.
465456
* @param editor An Atom {TextEditor} used to obtain the necessary text replacement.
@@ -494,8 +485,7 @@ export default class AutocompleteAdapter {
494485
}
495486

496487
/**
497-
* Public: Adds a snippet to the suggestion if the CompletionItem contains
498-
* snippet-formatted text
488+
* Public: Adds a snippet to the suggestion if the CompletionItem contains snippet-formatted text
499489
*
500490
* @param item An {CompletionItem} containing the completion items to be merged into.
501491
* @param suggestion The {atom$AutocompleteSuggestion} to merge the conversion into.
@@ -507,12 +497,11 @@ export default class AutocompleteAdapter {
507497
}
508498

509499
/**
510-
* Public: Obtain the textual suggestion type required by AutoComplete+ that
511-
* most closely maps to the numeric completion kind supplies by the language server.
500+
* Public: Obtain the textual suggestion type required by AutoComplete+ that most closely maps to the numeric
501+
* completion kind supplies by the language server.
512502
*
513503
* @param kind A {Number} that represents the suggestion kind to be converted.
514-
* @returns A {String} containing the AutoComplete+ suggestion type equivalent
515-
* to the given completion kind.
504+
* @returns A {String} containing the AutoComplete+ suggestion type equivalent to the given completion kind.
516505
*/
517506
public static completionKindToSuggestionType(kind: number | undefined): string {
518507
switch (kind) {
@@ -560,10 +549,11 @@ export default class AutocompleteAdapter {
560549
}
561550

562551
/**
563-
* Normalizes the given grammar scope for autoComplete package so it always starts with `.`
564-
* Based on https://github.com/atom/autocomplete-plus/wiki/Autocomplete-Providers
565-
* @param grammarScope such as 'source.python' or '.source.python'
566-
* @returns the normalized grammarScope such as `.source.python`
552+
* Normalizes the given grammar scope for autoComplete package so it always starts with `.` Based on
553+
* https://github.com/atom/autocomplete-plus/wiki/Autocomplete-Providers
554+
*
555+
* @param grammarScope Such as 'source.python' or '.source.python'
556+
* @returns The normalized grammarScope such as `.source.python`
567557
*/
568558
export function grammarScopeToAutoCompleteSelector(grammarScope: string): string {
569559
return grammarScope.includes(".") && grammarScope[0] !== "." ? `.${grammarScope}` : grammarScope

lib/adapters/code-action-adapter.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,21 @@ import { Range, TextEditor } from "atom"
1515
import CommandExecutionAdapter from "./command-execution-adapter"
1616

1717
export default class CodeActionAdapter {
18-
/**
19-
* @returns A {Boolean} indicating this adapter can adapt the server based on the
20-
* given serverCapabilities.
21-
*/
18+
/** @returns A {Boolean} indicating this adapter can adapt the server based on the given serverCapabilities. */
2219
public static canAdapt(serverCapabilities: ServerCapabilities): boolean {
2320
return serverCapabilities.codeActionProvider === true
2421
}
2522

2623
/**
27-
* Public: Retrieves code actions for a given editor, range, and context (diagnostics).
28-
* Throws an error if codeActionProvider is not a registered capability.
24+
* Public: Retrieves code actions for a given editor, range, and context (diagnostics). Throws an error if
25+
* codeActionProvider is not a registered capability.
2926
*
3027
* @param connection A {LanguageClientConnection} to the language server that provides highlights.
3128
* @param serverCapabilities The {ServerCapabilities} of the language server that will be used.
3229
* @param editor The Atom {TextEditor} containing the diagnostics.
3330
* @param range The Atom {Range} to fetch code actions for.
34-
* @param diagnostics An {Array<atomIde$Diagnostic>} to fetch code actions for.
35-
* This is typically a list of diagnostics intersecting `range`.
31+
* @param diagnostics An {Array<atomIde$Diagnostic>} to fetch code actions for. This is typically a list of
32+
* diagnostics intersecting `range`.
3633
* @returns A {Promise} of an {Array} of {atomIde$CodeAction}s to display.
3734
*/
3835
public static async getCodeActions(

0 commit comments

Comments
 (0)