Skip to content

chore: add prettier-config-atomic #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
public-hoist-pattern[]=*
package-lock=false
lockfile=true
lockfile=true
prefer-frozen-lockfile=false
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
package.json
package-lock.json
pnpm-lock.yaml
coverage
Expand Down
5 changes: 1 addition & 4 deletions lib/adapters/apply-edit-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export default class ApplyEditAdapter {
connection.onApplyEdit((m) => ApplyEditAdapter.onApplyEdit(m))
}

/**
* Tries to apply edits and reverts if anything goes wrong.
* Returns the checkpoint, so the caller can revert changes if needed.
*/
/** Tries to apply edits and reverts if anything goes wrong. Returns the checkpoint, so the caller can revert changes if needed. */
public static applyEdits(buffer: TextBuffer, edits: atomIde.TextEdit[]): number {
const checkpoint = buffer.createCheckpoint()
try {
Expand Down
106 changes: 48 additions & 58 deletions lib/adapters/autocomplete-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ import * as ac from "atom/autocomplete-plus"
import { Suggestion, TextSuggestion, SnippetSuggestion } from "../types/autocomplete-extended"

/**
* Defines the behavior of suggestion acceptance.
* Assume you have "cons|ole" in the editor (`|` is the cursor position)
* Defines the behavior of suggestion acceptance. Assume you have "cons|ole" in the editor ( `|` is the cursor position)
* and the autocomplete suggestion is `const`.
* - if `false` -> the edits are inserted : const|ole
* - if `true`` -> the edits are replaced: const|
*
* - If `false` -> the edits are inserted : const|ole
* - If `true`` -> the edits are replaced: const|
*/
type ShouldReplace = boolean

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

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

/**
* Public: Obtain suggestion list for AutoComplete+ by querying the language server using
* the `textDocument/completion` request.
* Public: Obtain suggestion list for AutoComplete+ by querying the language server using the `textDocument/completion` request.
*
* @param server An {ActiveServer} pointing to the language server to query.
* @param request The {atom$AutocompleteRequest} to satisfy.
* @param onDidConvertCompletionItem An optional function that takes a {CompletionItem},
* an {atom$AutocompleteSuggestion} and a {atom$AutocompleteRequest}
* allowing you to adjust converted items.
* @param onDidConvertCompletionItem An optional function that takes a {CompletionItem}, an
* {atom$AutocompleteSuggestion} and a {atom$AutocompleteRequest} allowing you to adjust converted items.
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
* @returns A {Promise} of an {Array} of {atom$AutocompleteSuggestion}s containing the
* AutoComplete+ suggestions to display.
* @returns A {Promise} of an {Array} of {atom$AutocompleteSuggestion}s containing the AutoComplete+ suggestions to display.
*/
public async getSuggestions(
server: ActiveServer,
Expand Down Expand Up @@ -211,8 +204,8 @@ export default class AutocompleteAdapter {
}

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

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

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

/**
* Public: Create {CompletionParams} to be sent to the language server
* based on the editor and position from the Autocomplete request etc.
* Public: Create {CompletionParams} to be sent to the language server based on the editor and position from the
* Autocomplete request etc.
*
* @param request The {atom$AutocompleteRequest} containing the request details.
* @param triggerCharacter The {string} containing the trigger character (empty if none).
* @param triggerOnly A {boolean} representing whether this completion is triggered right after a trigger character.
* @returns A {CompletionParams} with the keys:
* * `textDocument` the language server protocol textDocument identification.
* * `position` the position within the text document to display completion request for.
* * `context` containing the trigger character and kind.
*
* - `textDocument` the language server protocol textDocument identification.
* - `position` the position within the text document to display completion request for.
* - `context` containing the trigger character and kind.
*/
public static createCompletionParams(
request: ac.SuggestionsRequestedEvent,
Expand All @@ -330,13 +323,11 @@ export default class AutocompleteAdapter {
}

/**
* Public: Create {CompletionContext} to be sent to the language server
* based on the trigger character.
* Public: Create {CompletionContext} to be sent to the language server based on the trigger character.
*
* @param triggerCharacter The {string} containing the trigger character or '' if none.
* @param triggerOnly A {boolean} representing whether this completion is triggered right after a trigger character.
* @returns An {CompletionContext} that specifies the triggerKind and the triggerCharacter
* if there is one.
* @returns An {CompletionContext} that specifies the triggerKind and the triggerCharacter if there is one.
*/
public static createCompletionContext(triggerCharacter: string, triggerOnly: boolean): CompletionContext {
if (triggerCharacter === "") {
Expand All @@ -349,15 +340,15 @@ export default class AutocompleteAdapter {
}

/**
* Public: Convert a language server protocol CompletionItem array or CompletionList to
* an array of ordered AutoComplete+ suggestions.
* Public: Convert a language server protocol CompletionItem array or CompletionList to an array of ordered
* AutoComplete+ suggestions.
*
* @param completionItems An {Array} of {CompletionItem} objects or a {CompletionList} containing completion
* items to be converted.
* @param completionItems An {Array} of {CompletionItem} objects or a {CompletionList} containing completion items to
* be converted.
* @param request The {atom$AutocompleteRequest} to satisfy.
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
* @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion}
* and a {atom$AutocompleteRequest} allowing you to adjust converted items.
* @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion} and a
* {atom$AutocompleteRequest} allowing you to adjust converted items.
* @returns A {Map} of AutoComplete+ suggestions ordered by the CompletionItems sortText.
*/
public completionItemsToSuggestions(
Expand Down Expand Up @@ -394,8 +385,8 @@ export default class AutocompleteAdapter {
* @param suggestion A {atom$AutocompleteSuggestion} to have the conversion applied to.
* @param request The {atom$AutocompleteRequest} to satisfy.
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
* @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion}
* and a {atom$AutocompleteRequest} allowing you to adjust converted items.
* @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion} and a
* {atom$AutocompleteRequest} allowing you to adjust converted items.
* @returns The {atom$AutocompleteSuggestion} passed in as suggestion with the conversion applied.
*/
public static completionItemToSuggestion(
Expand Down Expand Up @@ -458,8 +449,8 @@ export default class AutocompleteAdapter {
}

/**
* Public: Applies the textEdit part of a language server protocol CompletionItem to an
* AutoComplete+ Suggestion via the replacementPrefix and text properties.
* Public: Applies the textEdit part of a language server protocol CompletionItem to an AutoComplete+ Suggestion via
* the replacementPrefix and text properties.
*
* @param textEdit A {TextEdit} from a CompletionItem to apply.
* @param editor An Atom {TextEditor} used to obtain the necessary text replacement.
Expand Down Expand Up @@ -494,8 +485,7 @@ export default class AutocompleteAdapter {
}

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

/**
* Public: Obtain the textual suggestion type required by AutoComplete+ that
* most closely maps to the numeric completion kind supplies by the language server.
* Public: Obtain the textual suggestion type required by AutoComplete+ that most closely maps to the numeric
* completion kind supplies by the language server.
*
* @param kind A {Number} that represents the suggestion kind to be converted.
* @returns A {String} containing the AutoComplete+ suggestion type equivalent
* to the given completion kind.
* @returns A {String} containing the AutoComplete+ suggestion type equivalent to the given completion kind.
*/
public static completionKindToSuggestionType(kind: number | undefined): string {
switch (kind) {
Expand Down Expand Up @@ -560,10 +549,11 @@ export default class AutocompleteAdapter {
}

/**
* Normalizes the given grammar scope for autoComplete package so it always starts with `.`
* Based on https://github.com/atom/autocomplete-plus/wiki/Autocomplete-Providers
* @param grammarScope such as 'source.python' or '.source.python'
* @returns the normalized grammarScope such as `.source.python`
* Normalizes the given grammar scope for autoComplete package so it always starts with `.` Based on
* https://github.com/atom/autocomplete-plus/wiki/Autocomplete-Providers
*
* @param grammarScope Such as 'source.python' or '.source.python'
* @returns The normalized grammarScope such as `.source.python`
*/
export function grammarScopeToAutoCompleteSelector(grammarScope: string): string {
return grammarScope.includes(".") && grammarScope[0] !== "." ? `.${grammarScope}` : grammarScope
Expand Down
13 changes: 5 additions & 8 deletions lib/adapters/code-action-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,21 @@ import { Range, TextEditor } from "atom"
import CommandExecutionAdapter from "./command-execution-adapter"

export default class CodeActionAdapter {
/**
* @returns A {Boolean} indicating this adapter can adapt the server based on the
* given serverCapabilities.
*/
/** @returns A {Boolean} indicating this adapter can adapt the server based on the given serverCapabilities. */
public static canAdapt(serverCapabilities: ServerCapabilities): boolean {
return serverCapabilities.codeActionProvider === true
}

/**
* Public: Retrieves code actions for a given editor, range, and context (diagnostics).
* Throws an error if codeActionProvider is not a registered capability.
* Public: Retrieves code actions for a given editor, range, and context (diagnostics). Throws an error if
* codeActionProvider is not a registered capability.
*
* @param connection A {LanguageClientConnection} to the language server that provides highlights.
* @param serverCapabilities The {ServerCapabilities} of the language server that will be used.
* @param editor The Atom {TextEditor} containing the diagnostics.
* @param range The Atom {Range} to fetch code actions for.
* @param diagnostics An {Array<atomIde$Diagnostic>} to fetch code actions for.
* This is typically a list of diagnostics intersecting `range`.
* @param diagnostics An {Array<atomIde$Diagnostic>} to fetch code actions for. This is typically a list of
* diagnostics intersecting `range`.
* @returns A {Promise} of an {Array} of {atomIde$CodeAction}s to display.
*/
public static async getCodeActions(
Expand Down
Loading