Skip to content

Commit bf63a49

Browse files
committed
test: add test for applyAdditionalTextEdits
1 parent b06c7d2 commit bf63a49

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

test/adapters/autocomplete-adapter.test.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import AutoCompleteAdapter, { grammarScopeToAutoCompleteSelector } from "../../lib/adapters/autocomplete-adapter"
22
import { ActiveServer } from "../../lib/server-manager.js"
33
import * as ls from "../../lib/languageclient"
4-
import { CompositeDisposable, Point } from "atom"
4+
import { CompositeDisposable, Point, TextEditor } from "atom"
55
import * as ac from "atom/autocomplete-plus"
6+
67
import { createSpyConnection, createFakeEditor } from "../helpers.js"
78
import { TextSuggestion, SnippetSuggestion } from "../../lib/types/autocomplete-extended"
89
import { CompletionItem, Range } from "../../lib/languageclient"
10+
import { dirname, join } from "path"
11+
import { Convert } from "../../lib/main"
912

1013
function createRequest({
1114
prefix = "",
@@ -596,6 +599,48 @@ describe("AutoCompleteAdapter", () => {
596599
})
597600
})
598601

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+
599644
describe("applies the change if shouldReplace is false", () => {
600645
it("1", async () => {
601646
const results = await getSuggestionsMock(

0 commit comments

Comments
 (0)