|
1 | 1 | import AutoCompleteAdapter, { grammarScopeToAutoCompleteSelector } from "../../lib/adapters/autocomplete-adapter"
|
2 | 2 | import { ActiveServer } from "../../lib/server-manager.js"
|
3 | 3 | import * as ls from "../../lib/languageclient"
|
4 |
| -import { CompositeDisposable, Point } from "atom" |
| 4 | +import { CompositeDisposable, Point, TextEditor } from "atom" |
5 | 5 | import * as ac from "atom/autocomplete-plus"
|
| 6 | + |
6 | 7 | import { createSpyConnection, createFakeEditor } from "../helpers.js"
|
7 | 8 | import { TextSuggestion, SnippetSuggestion } from "../../lib/types/autocomplete-extended"
|
8 | 9 | import { CompletionItem, Range } from "../../lib/languageclient"
|
| 10 | +import { dirname, join } from "path" |
| 11 | +import { Convert } from "../../lib/main" |
9 | 12 |
|
10 | 13 | function createRequest({
|
11 | 14 | prefix = "",
|
@@ -596,6 +599,48 @@ describe("AutoCompleteAdapter", () => {
|
596 | 599 | })
|
597 | 600 | })
|
598 | 601 |
|
| 602 | + describe("applyAdditionalTextEdits", () => { |
| 603 | + it("1", async () => { |
| 604 | + const newText = "hello world" |
| 605 | + const range = Range.create({ line: 1, character: 0 }, { line: 1, character: 0 + newText.length }) |
| 606 | + const additionalTextEdits = [ |
| 607 | + { |
| 608 | + range, |
| 609 | + newText, |
| 610 | + }, |
| 611 | + ] |
| 612 | + const results = await getSuggestionsMock( |
| 613 | + [ |
| 614 | + { |
| 615 | + label: "align", |
| 616 | + sortText: "a", |
| 617 | + additionalTextEdits, |
| 618 | + }, |
| 619 | + ], |
| 620 | + customRequest, |
| 621 | + undefined, |
| 622 | + undefined, |
| 623 | + true |
| 624 | + ) |
| 625 | + expect(results[0].displayText).toBe("align") |
| 626 | + expect((results[0] as TextSuggestion).text).toBe("align") |
| 627 | + expect((results[0] as TextSuggestion).completionItem).toEqual({ |
| 628 | + label: "align", |
| 629 | + sortText: "a", |
| 630 | + additionalTextEdits, |
| 631 | + }) |
| 632 | + const editor = (await atom.workspace.open(join(dirname(__dirname), "fixtures", "hello.js"))) as TextEditor |
| 633 | + const suggestionInsertedEvent = { |
| 634 | + editor, |
| 635 | + triggerPosition: new Point(1, 0), // has no effect? |
| 636 | + suggestion: results[0], |
| 637 | + } as ac.SuggestionInsertedEvent |
| 638 | + AutoCompleteAdapter.applyAdditionalTextEdits(suggestionInsertedEvent) |
| 639 | + |
| 640 | + expect(editor.getBuffer().getTextInRange(Convert.lsRangeToAtomRange(range))).toBe(newText) |
| 641 | + }) |
| 642 | + }) |
| 643 | + |
599 | 644 | describe("applies the change if shouldReplace is false", () => {
|
600 | 645 | it("1", async () => {
|
601 | 646 | const results = await getSuggestionsMock(
|
|
0 commit comments