Skip to content

Commit

Permalink
Implement from and to for completions
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohaszing committed Aug 9, 2024
1 parent 3dbaf72 commit 18afb26
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export function createCompletionSource(options: createCompletionSource.Options):
}

const completionOptions: Completion[] = []
let minFrom = context.pos
let maxTo = context.pos + 1

for (const item of items) {
const { commitCharacters, detail, documentation, kind, label, textEdit, textEditText } = item
Expand All @@ -196,6 +198,12 @@ export function createCompletionSource(options: createCompletionSource.Options):
const range = 'range' in textEdit ? textEdit.range : textEdit.replace
const from = textDocument.offsetAt(range.start)
const to = textDocument.offsetAt(range.end)
if (from < minFrom) {
minFrom = from
}
if (to > maxTo) {
maxTo = to
}
const insert = textEdit.newText
const insertTextFormat = item.insertTextFormat ?? itemDefaults?.insertTextFormat

Expand All @@ -211,7 +219,8 @@ export function createCompletionSource(options: createCompletionSource.Options):
}

return {
from: context.pos,
from: minFrom,
to: maxTo,
commitCharacters: itemDefaults?.commitCharacters,
options: completionOptions
}
Expand Down

0 comments on commit 18afb26

Please sign in to comment.