Skip to content

Commit f7d7901

Browse files
committed
fix: disable class method snippet insertion mode if methodSnippetsInsertText is enabled
1 parent 7ee5442 commit f7d7901

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

src/onCompletionAccepted.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,36 @@ export default (tsApi: { onCompletionAccepted }) => {
6262
const nextChar = editor.document.getText(new vscode.Range(startPos, startPos.translate(0, 1)))
6363
if (!params || ['(', '.', '`'].includes(nextChar)) return
6464

65-
if (isAmbiguous && lastAcceptedAmbiguousMethodSnippetSuggestion !== suggestionName) {
66-
lastAcceptedAmbiguousMethodSnippetSuggestion = suggestionName
67-
return
68-
}
65+
if (getExtensionSetting('methodSnippetsInsertText') === 'disable') {
66+
// handle insertion only if it wasn't handled by methodSnippetsInsertText already
67+
if (isAmbiguous && lastAcceptedAmbiguousMethodSnippetSuggestion !== suggestionName) {
68+
lastAcceptedAmbiguousMethodSnippetSuggestion = suggestionName
69+
return
70+
}
6971

70-
const replaceArguments = getExtensionSetting('methodSnippets.replaceArguments')
71-
72-
const snippet = new vscode.SnippetString('')
73-
snippet.appendText('(')
74-
// todo maybe when have optional (skipped), add a way to leave trailing , with tabstop (previous behavior)
75-
for (const [i, param] of params.entries()) {
76-
const replacer = replaceArguments[param.replace(/\?$/, '')]
77-
if (replacer === null) continue
78-
if (replacer) {
79-
useReplacer(snippet, replacer)
80-
} else {
81-
snippet.appendPlaceholder(param)
72+
const replaceArguments = getExtensionSetting('methodSnippets.replaceArguments')
73+
74+
const snippet = new vscode.SnippetString('')
75+
snippet.appendText('(')
76+
// todo maybe when have optional (skipped), add a way to leave trailing , with tabstop (previous behavior)
77+
for (const [i, param] of params.entries()) {
78+
const replacer = replaceArguments[param.replace(/\?$/, '')]
79+
if (replacer === null) continue
80+
if (replacer) {
81+
useReplacer(snippet, replacer)
82+
} else {
83+
snippet.appendPlaceholder(param)
84+
}
85+
86+
if (i !== params.length - 1) snippet.appendText(', ')
8287
}
8388

84-
if (i !== params.length - 1) snippet.appendText(', ')
89+
snippet.appendText(')')
90+
void editor.insertSnippet(snippet, undefined, {
91+
undoStopAfter: false,
92+
undoStopBefore: false,
93+
})
8594
}
86-
87-
snippet.appendText(')')
88-
void editor.insertSnippet(snippet, undefined, {
89-
undoStopAfter: false,
90-
undoStopBefore: false,
91-
})
9295
if (vscode.workspace.getConfiguration('editor.parameterHints').get('enabled') && params.length > 0) {
9396
void vscode.commands.executeCommand('editor.action.triggerParameterHints')
9497
}

0 commit comments

Comments
 (0)