Skip to content

Commit ceef560

Browse files
committed
Merge branch 'master' into update-eslint
2 parents 2b5e4bd + 33e7d4d commit ceef560

19 files changed

+2641
-1822
lines changed

.github/workflows/CI.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,14 @@ jobs:
4141
- name: Commit lint ✨
4242
uses: wagoid/commitlint-github-action@v2
4343

44-
- uses: UziTech/action-setup-atom@v1
45-
- name: Setup PNPM
46-
uses: pnpm/[email protected]
47-
with:
48-
version: latest
49-
5044
- name: Install dependencies
51-
run: pnpm install
45+
run: npm install
5246

5347
- name: Format ✨
54-
run: pnpm test.format
48+
run: npm run test.format
5549

5650
- name: Lint ✨
57-
run: pnpm test.lint
51+
run: npm run test.lint
5852

5953
Release:
6054
needs: [Test, Lint]

.github/workflows/bump_deps.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
with:
1414
node-version: "12"
1515
- name: Setup PNPM
16-
uses: pnpm/action-setup@v1.2.1
16+
uses: pnpm/action-setup@master
1717
with:
1818
version: latest
1919

@@ -32,8 +32,8 @@ jobs:
3232
- uses: peter-evans/create-pull-request@v3
3333
with:
3434
token: ${{ steps.generate-token.outputs.token }}
35-
commit-message: "chore: Update Dependencies"
36-
title: "fix: Update Dependencies"
35+
commit-message: "fix: update Dependencies"
36+
title: "fix: update Dependencies"
3737
labels: Dependencies
3838
branch: "Bump_Dependencies"
3939

@@ -45,7 +45,7 @@ jobs:
4545
with:
4646
node-version: "12"
4747
- name: Setup PNPM
48-
uses: pnpm/action-setup@v1.2.1
48+
uses: pnpm/action-setup@master
4949
with:
5050
version: latest
5151

@@ -64,7 +64,7 @@ jobs:
6464
- uses: peter-evans/create-pull-request@v3
6565
with:
6666
token: ${{ steps.generate-token.outputs.token }}
67-
commit-message: "chore: Update devDependencies"
68-
title: "chore: Update devDependencies"
67+
commit-message: "chore: update devDependencies"
68+
title: "chore: update devDependencies"
6969
labels: Dependencies
7070
branch: "Bump_devDependencies"

CHANGELOG.md

+53
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
# [1.6.0](https://github.com/atom-ide-community/atom-languageclient/compare/v1.5.0...v1.6.0) (2021-03-21)
2+
3+
4+
### Bug Fixes
5+
6+
* consider showing the document in external programs a sucess ([fabf882](https://github.com/atom-ide-community/atom-languageclient/commit/fabf88299c6e221743d3da0d14fcf07861182bc6))
7+
* fix the doc for onShowDocument ([03b9b20](https://github.com/atom-ide-community/atom-languageclient/commit/03b9b202e9ac1215f064f6de64ad45420faa95ca))
8+
* params.selection can be undefined ([921613b](https://github.com/atom-ide-community/atom-languageclient/commit/921613b491dc820ad9e0234954d42fd9d4092294))
9+
* rename onShowDocument function to showDocument ([f9549c6](https://github.com/atom-ide-community/atom-languageclient/commit/f9549c6f27e762f7e122d731f17bf827b8117fb1))
10+
* return success false if view is undefined ([7bede25](https://github.com/atom-ide-community/atom-languageclient/commit/7bede25205135bdbf716c55a695b307eb8ee9142))
11+
* try-catch showDocument ([6e8770c](https://github.com/atom-ide-community/atom-languageclient/commit/6e8770ced9d4e77d056db6386d0584b351adbd65))
12+
* use free functions instead of static methods ([38441c9](https://github.com/atom-ide-community/atom-languageclient/commit/38441c9d24c6336b87b17686d63ed062437ef112))
13+
14+
15+
### Features
16+
17+
* implement window/showDocument ([ff1aa7a](https://github.com/atom-ide-community/atom-languageclient/commit/ff1aa7ab0993c6de1c8e76c87e76c10387694935))
18+
19+
# [1.5.0](https://github.com/atom-ide-community/atom-languageclient/compare/v1.4.0...v1.5.0) (2021-03-19)
20+
21+
22+
### Bug Fixes
23+
24+
* add and use normalizeGrammarScope ([889f1da](https://github.com/atom-ide-community/atom-languageclient/commit/889f1da34bc0edb2ee2565e96db93e5f8d042df5)), closes [/github.com/atom-community/atom-languageclient/pull/136#discussion_r597451879](https://github.com//github.com/atom-community/atom-languageclient/pull/136/issues/discussion_r597451879)
25+
* add filterSuggestion: true to provideAutocomplete ([d143451](https://github.com/atom-ide-community/atom-languageclient/commit/d143451d0213d0b2f802c6f7ebe983efbf24d891))
26+
* add locale to getInitializeParams ([dfce15a](https://github.com/atom-ide-community/atom-languageclient/commit/dfce15a97352b5c0403c50f131d1cbcdcae50299))
27+
* simplify provideAutocomplete.selector ([1f10d7b](https://github.com/atom-ide-community/atom-languageclient/commit/1f10d7b546e75355d07df3f61d585cf4db141138))
28+
29+
30+
### Features
31+
32+
* add more compeletion properties in AutoLanguageClient ([45d7d19](https://github.com/atom-ide-community/atom-languageclient/commit/45d7d1931c9e8104e309b8b660c9331e4262f57e))
33+
* allow disabling autocomplete for some scopes ([a6e3244](https://github.com/atom-ide-community/atom-languageclient/commit/a6e324458ce2fe601f95e4532a522acc3224e4f8))
34+
35+
# [1.4.0](https://github.com/atom-ide-community/atom-languageclient/compare/v1.3.0...v1.4.0) (2021-03-17)
36+
37+
38+
### Features
39+
40+
* handling custom requests ([543cd6e](https://github.com/atom-ide-community/atom-languageclient/commit/543cd6e74936f078f389f34166bdf947d4c4bee0))
41+
42+
# [1.3.0](https://github.com/atom-ide-community/atom-languageclient/compare/v1.2.2...v1.3.0) (2021-03-16)
43+
44+
45+
### Bug Fixes
46+
47+
* use ShouldReplace ([6601427](https://github.com/atom-ide-community/atom-languageclient/commit/66014277fd95007cb6ab500a7727c7475e7fcae1))
48+
49+
50+
### Features
51+
52+
* upgrade to LSP 3.16 and fix compiler errors ([db07b3c](https://github.com/atom-ide-community/atom-languageclient/commit/db07b3c4972842f3f5b8a4e221c8e406aed52e96))
53+
154
## [1.2.2](https://github.com/atom-ide-community/atom-languageclient/compare/v1.2.1...v1.2.2) (2021-02-23)
255

356

lib/adapters/autocomplete-adapter.ts

+50-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,25 @@ import {
1111
CompletionParams,
1212
CompletionTriggerKind,
1313
InsertTextFormat,
14+
InsertReplaceEdit,
1415
LanguageClientConnection,
16+
Range,
1517
ServerCapabilities,
1618
TextEdit,
1719
} from "../languageclient"
1820
import { Point, TextEditor } from "atom"
1921
import * as ac from "atom/autocomplete-plus"
2022
import { Suggestion, TextSuggestion, SnippetSuggestion } from "../types/autocomplete-extended"
2123

24+
/**
25+
* Defines the behavior of suggestion acceptance.
26+
* Assume you have "cons|ole" in the editor (`|` is the cursor position)
27+
* and the autocomplete suggestion is `const`.
28+
* - if `false` -> the edits are inserted : const|ole
29+
* - if `true`` -> the edits are replaced: const|
30+
*/
31+
type ShouldReplace = boolean
32+
2233
/**
2334
* Holds a list of suggestions generated from the CompletionItem[]
2435
* list sent by the server, as well as metadata about the context
@@ -73,14 +84,16 @@ export default class AutocompleteAdapter {
7384
* @param onDidConvertCompletionItem An optional function that takes a {CompletionItem},
7485
* an {atom$AutocompleteSuggestion} and a {atom$AutocompleteRequest}
7586
* allowing you to adjust converted items.
87+
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
7688
* @returns A {Promise} of an {Array} of {atom$AutocompleteSuggestion}s containing the
7789
* AutoComplete+ suggestions to display.
7890
*/
7991
public async getSuggestions(
8092
server: ActiveServer,
8193
request: ac.SuggestionsRequestedEvent,
8294
onDidConvertCompletionItem?: CompletionItemAdjuster,
83-
minimumWordLength?: number
95+
minimumWordLength?: number,
96+
shouldReplace: ShouldReplace = false
8497
): Promise<ac.AnySuggestion[]> {
8598
const triggerChars =
8699
server.capabilities.completionProvider != null
@@ -101,6 +114,7 @@ export default class AutocompleteAdapter {
101114
request,
102115
triggerChar,
103116
triggerOnly,
117+
shouldReplace,
104118
onDidConvertCompletionItem
105119
)
106120

@@ -140,6 +154,7 @@ export default class AutocompleteAdapter {
140154
request: ac.SuggestionsRequestedEvent,
141155
triggerChar: string,
142156
triggerOnly: boolean,
157+
shouldReplace: ShouldReplace,
143158
onDidConvertCompletionItem?: CompletionItemAdjuster
144159
): Promise<Suggestion[]> {
145160
const cache = this._suggestionCache.get(server)
@@ -181,6 +196,7 @@ export default class AutocompleteAdapter {
181196
completions,
182197
request,
183198
triggerColumns,
199+
shouldReplace,
184200
onDidConvertCompletionItem
185201
)
186202
this._suggestionCache.set(server, {
@@ -339,6 +355,7 @@ export default class AutocompleteAdapter {
339355
* @param completionItems An {Array} of {CompletionItem} objects or a {CompletionList} containing completion
340356
* items to be converted.
341357
* @param request The {atom$AutocompleteRequest} to satisfy.
358+
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
342359
* @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion}
343360
* and a {atom$AutocompleteRequest} allowing you to adjust converted items.
344361
* @returns A {Map} of AutoComplete+ suggestions ordered by the CompletionItems sortText.
@@ -347,6 +364,7 @@ export default class AutocompleteAdapter {
347364
completionItems: CompletionItem[] | CompletionList | null,
348365
request: ac.SuggestionsRequestedEvent,
349366
triggerColumns: [number, number],
367+
shouldReplace: ShouldReplace,
350368
onDidConvertCompletionItem?: CompletionItemAdjuster
351369
): Map<Suggestion, PossiblyResolvedCompletionItem> {
352370
const completionsArray = Array.isArray(completionItems)
@@ -361,6 +379,7 @@ export default class AutocompleteAdapter {
361379
{} as Suggestion,
362380
request,
363381
triggerColumns,
382+
shouldReplace,
364383
onDidConvertCompletionItem
365384
),
366385
new PossiblyResolvedCompletionItem(s, false),
@@ -374,6 +393,7 @@ export default class AutocompleteAdapter {
374393
* @param item An {CompletionItem} containing a completion item to be converted.
375394
* @param suggestion A {atom$AutocompleteSuggestion} to have the conversion applied to.
376395
* @param request The {atom$AutocompleteRequest} to satisfy.
396+
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
377397
* @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion}
378398
* and a {atom$AutocompleteRequest} allowing you to adjust converted items.
379399
* @returns The {atom$AutocompleteSuggestion} passed in as suggestion with the conversion applied.
@@ -383,6 +403,7 @@ export default class AutocompleteAdapter {
383403
suggestion: Suggestion,
384404
request: ac.SuggestionsRequestedEvent,
385405
triggerColumns: [number, number],
406+
shouldReplace: ShouldReplace,
386407
onDidConvertCompletionItem?: CompletionItemAdjuster
387408
): Suggestion {
388409
AutocompleteAdapter.applyCompletionItemToSuggestion(item, suggestion as TextSuggestion)
@@ -391,7 +412,8 @@ export default class AutocompleteAdapter {
391412
request.editor,
392413
triggerColumns,
393414
request.bufferPosition,
394-
suggestion as TextSuggestion
415+
suggestion as TextSuggestion,
416+
shouldReplace
395417
)
396418
AutocompleteAdapter.applySnippetToSuggestion(item, suggestion as SnippetSuggestion)
397419
if (onDidConvertCompletionItem != null) {
@@ -442,20 +464,31 @@ export default class AutocompleteAdapter {
442464
* @param textEdit A {TextEdit} from a CompletionItem to apply.
443465
* @param editor An Atom {TextEditor} used to obtain the necessary text replacement.
444466
* @param suggestion An {atom$AutocompleteSuggestion} to set the replacementPrefix and text properties of.
467+
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
445468
*/
446469
public static applyTextEditToSuggestion(
447-
textEdit: TextEdit | undefined,
470+
textEdit: TextEdit | InsertReplaceEdit | undefined,
448471
editor: TextEditor,
449472
triggerColumns: [number, number],
450473
originalBufferPosition: Point,
451-
suggestion: TextSuggestion
474+
suggestion: TextSuggestion,
475+
shouldReplace: ShouldReplace
452476
): void {
453477
if (!textEdit) {
454478
return
455479
}
456-
if (textEdit.range.start.character !== triggerColumns[0]) {
457-
const range = Convert.lsRangeToAtomRange(textEdit.range)
458-
suggestion.customReplacmentPrefix = editor.getTextInBufferRange([range.start, originalBufferPosition])
480+
let range: Range
481+
if ("range" in textEdit) {
482+
range = textEdit.range
483+
} else if (shouldReplace) {
484+
range = textEdit.replace
485+
} else {
486+
range = textEdit.insert
487+
}
488+
489+
if (range.start.character !== triggerColumns[0]) {
490+
const atomRange = Convert.lsRangeToAtomRange(range)
491+
suggestion.customReplacmentPrefix = editor.getTextInBufferRange([atomRange.start, originalBufferPosition])
459492
}
460493
suggestion.text = textEdit.newText
461494
}
@@ -525,3 +558,13 @@ export default class AutocompleteAdapter {
525558
}
526559
}
527560
}
561+
562+
/**
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`
567+
*/
568+
export function grammarScopeToAutoCompleteSelector(grammarScope: string): string {
569+
return grammarScope.includes(".") && grammarScope[0] !== "." ? `.${grammarScope}` : grammarScope
570+
}

lib/adapters/document-sync-adapter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export class TextEditorSyncAdapter {
412412
const didSaveNotification = {
413413
textDocument: { uri, version: this._getVersion(uri) },
414414
} as DidSaveTextDocumentParams
415-
if (this._documentSync.save && this._documentSync.save.includeText) {
415+
if (typeof this._documentSync.save === "object" && this._documentSync.save.includeText) {
416416
didSaveNotification.text = this._editor.getText()
417417
}
418418
this._connection.didSaveTextDocument(didSaveNotification)

lib/adapters/notifications-adapter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ShowMessageParams,
66
ShowMessageRequestParams,
77
} from "../languageclient"
8-
import { Notification, NotificationOptions, NotificationExt } from "atom"
8+
import { Notification, NotificationOptions } from "atom"
99

1010
export interface NotificationButton {
1111
text: string
@@ -109,7 +109,7 @@ function addNotificationForMessage(
109109
message: string,
110110
options: NotificationOptions
111111
): Notification | null {
112-
function isDuplicate(note: NotificationExt): boolean {
112+
function isDuplicate(note: Notification): boolean {
113113
const noteDismissed = note.isDismissed && note.isDismissed()
114114
const noteOptions = (note.getOptions && note.getOptions()) || {}
115115
return (

lib/adapters/show-document-adapter.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { shell } from "electron"
2+
import { LanguageClientConnection, ShowDocumentParams, ShowDocumentResult } from "../languageclient"
3+
import { TextEditor } from "atom"
4+
import Convert from "../convert"
5+
6+
/** Public: Adapts the window/showDocument command to Atom's text editors or external programs. */
7+
const ShowDocumentAdapter = {
8+
/** {@inheritDoc attach} */
9+
attach,
10+
/** {@inheritDoc showDocument} */
11+
showDocument,
12+
}
13+
// for consistency with other adapters
14+
export default ShowDocumentAdapter
15+
16+
/**
17+
* Public: Attach to a {LanguageClientConnection} to recieve requests to show documents.
18+
*/
19+
export function attach(connection: LanguageClientConnection): void {
20+
connection.onShowDocument(showDocument)
21+
}
22+
23+
/**
24+
* Public: show documents inside Atom text editor or in external programs
25+
*
26+
* @param params The {ShowDocumentParams} received from the language server
27+
* indicating the document to be displayed as well as other metadata.
28+
* @returns {Promise<ShowDocumentResult>} with a `success: boolean` property specifying if the operation was sucessful
29+
* {@inheritDoc ShowDocumentParams}
30+
*/
31+
export async function showDocument(params: ShowDocumentParams): Promise<ShowDocumentResult> {
32+
try {
33+
if (!params.external) {
34+
// open using atom.workspace
35+
const view = await atom.workspace.open(Convert.uriToPath(params.uri), {
36+
activateItem: params.takeFocus,
37+
activatePane: params.takeFocus,
38+
pending: true,
39+
initialLine: params.selection?.start.line ?? 0,
40+
initialColumn: params.selection?.start.character ?? 0,
41+
})
42+
if (!view) {
43+
return { success: false }
44+
}
45+
if (view instanceof TextEditor && params.selection !== undefined) {
46+
view.selectToBufferPosition(Convert.positionToPoint(params.selection.end))
47+
}
48+
} else {
49+
// open using Electron
50+
shell.openExternal(params.uri, { activate: params.takeFocus })
51+
}
52+
return { success: true }
53+
} catch (e) {
54+
atom.notifications.addError(e)
55+
return { success: false }
56+
}
57+
}

0 commit comments

Comments
 (0)