Skip to content

Commit e953448

Browse files
committed
fix: don't activate method snippet before tick `
1 parent 814347d commit e953448

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/onCompletionAccepted.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as vscode from 'vscode'
22
import { getActiveRegularEditor } from '@zardoy/vscode-utils'
3-
import { conditionallyRegister } from '@zardoy/vscode-utils/build/settings'
43
import { expandPosition } from '@zardoy/vscode-utils/build/position'
54
import { getExtensionSetting, registerExtensionCommand } from 'vscode-framework'
65
import { oneOf } from '@zardoy/utils'
7-
import { RequestOptionsTypes, RequestResponseTypes } from '../typescript/src/ipcTypes'
6+
import { RequestResponseTypes } from '../typescript/src/ipcTypes'
87
import { sendCommand } from './sendCommand'
98

109
export default (tsApi: { onCompletionAccepted }) => {
@@ -19,7 +18,7 @@ export default (tsApi: { onCompletionAccepted }) => {
1918
return
2019
}
2120

22-
const { label, insertText, documentation = '', kind } = item
21+
const { label, insertText, kind } = item
2322
if (kind === vscode.CompletionItemKind.Keyword) {
2423
if (insertText === 'return ') justAcceptedReturnKeywordSuggestion = true
2524
else if (insertText === 'default ') void vscode.commands.executeCommand('editor.action.triggerSuggest')
@@ -37,11 +36,11 @@ export default (tsApi: { onCompletionAccepted }) => {
3736

3837
const enableMethodSnippets = vscode.workspace.getConfiguration(process.env.IDS_PREFIX, item.document).get('enableMethodSnippets')
3938

40-
if (enableMethodSnippets && /* either snippet by vscode or by us to ignore pos */ typeof insertText !== 'object') {
39+
if (enableMethodSnippets && /* snippet by vscode or by us to ignore pos */ typeof insertText !== 'object') {
4140
const editor = getActiveRegularEditor()!
4241
const startPos = editor.selection.start
4342
const nextSymbol = editor.document.getText(new vscode.Range(startPos, startPos.translate(0, 1)))
44-
if (!['(', '.'].includes(nextSymbol)) {
43+
if (!['(', '.', '`'].includes(nextSymbol)) {
4544
const controller = new AbortController()
4645
inFlightMethodSnippetOperation = controller
4746
const params: RequestResponseTypes['getFullMethodSnippet'] | undefined = await sendCommand('getFullMethodSnippet')
@@ -55,14 +54,7 @@ export default (tsApi: { onCompletionAccepted }) => {
5554
const replacer = replaceArguments[param.replace(/\?$/, '')]
5655
if (replacer === null) continue
5756
if (replacer) {
58-
snippet.appendPlaceholder(inner => {
59-
// eslint-disable-next-line unicorn/no-array-for-each
60-
replacer.split(/(?<!\\)\$/g).forEach((text, i, arr) => {
61-
// inner.appendText(text.replace(/\\\$/g, '$'))
62-
inner.value += text
63-
if (i !== arr.length - 1) inner.appendTabstop()
64-
})
65-
})
57+
useReplacer(snippet, replacer)
6658
} else {
6759
snippet.appendPlaceholder(param)
6860
}
@@ -145,3 +137,14 @@ export default (tsApi: { onCompletionAccepted }) => {
145137
}
146138
})
147139
}
140+
141+
function useReplacer(snippet: vscode.SnippetString, replacer: string) {
142+
snippet.appendPlaceholder(inner => {
143+
// eslint-disable-next-line unicorn/no-array-for-each
144+
replacer.split(/(?<!\\)\$/g).forEach((text, i, arr) => {
145+
// inner.appendText(text.replace(/\\\$/g, '$'))
146+
inner.value += text
147+
if (i !== arr.length - 1) inner.appendTabstop()
148+
})
149+
})
150+
}

0 commit comments

Comments
 (0)