Skip to content

Commit e144fe6

Browse files
committed
fix: fix optional chaining (?.) auto insertion with method snippets with insert text
1 parent e820410 commit e144fe6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

typescript/src/completions/functionCompletions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export default (entries: ts.CompletionEntry[]) => {
5050
const originalText = entry.insertText ?? entry.name
5151
const insertTextSnippetAdd = `(${methodSnippet.map((x, i) => `$\{${i + 1}:${x}}`).join(', ')})`
5252
// https://github.com/zardoy/typescript-vscode-plugins/issues/161
53-
const beforeDotWorkaround = prior.isMemberCompletion && prevChar === '.'
53+
// todo implement workaround for ?. as well
54+
const beforeDotWorkaround = !entry.replacementSpan && prior.isMemberCompletion && prevChar === '.'
5455
return {
5556
...entry,
5657
insertText: (beforeDotWorkaround ? '.' : '') + insertTextAfterEntry(originalText, insertTextSnippetAdd),
@@ -63,7 +64,7 @@ export default (entries: ts.CompletionEntry[]) => {
6364
start: position - 1,
6465
length: (c('editorSuggestInsertModeReplace') ? wordRangeAtPos(fullText, position).length : 0) + 1,
6566
}
66-
: undefined,
67+
: entry.replacementSpan,
6768
kind: ts.ScriptElementKind.functionElement,
6869
isSnippet: true,
6970
}

0 commit comments

Comments
 (0)