1
1
import * as vscode from 'vscode'
2
2
import { getActiveRegularEditor } from '@zardoy/vscode-utils'
3
- import { conditionallyRegister } from '@zardoy/vscode-utils/build/settings'
4
3
import { expandPosition } from '@zardoy/vscode-utils/build/position'
5
4
import { getExtensionSetting , registerExtensionCommand } from 'vscode-framework'
6
5
import { oneOf } from '@zardoy/utils'
7
- import { RequestOptionsTypes , RequestResponseTypes } from '../typescript/src/ipcTypes'
6
+ import { RequestResponseTypes } from '../typescript/src/ipcTypes'
8
7
import { sendCommand } from './sendCommand'
9
8
10
9
export default ( tsApi : { onCompletionAccepted } ) => {
@@ -19,7 +18,7 @@ export default (tsApi: { onCompletionAccepted }) => {
19
18
return
20
19
}
21
20
22
- const { label, insertText, documentation = '' , kind } = item
21
+ const { label, insertText, kind } = item
23
22
if ( kind === vscode . CompletionItemKind . Keyword ) {
24
23
if ( insertText === 'return ' ) justAcceptedReturnKeywordSuggestion = true
25
24
else if ( insertText === 'default ' ) void vscode . commands . executeCommand ( 'editor.action.triggerSuggest' )
@@ -37,11 +36,11 @@ export default (tsApi: { onCompletionAccepted }) => {
37
36
38
37
const enableMethodSnippets = vscode . workspace . getConfiguration ( process . env . IDS_PREFIX , item . document ) . get ( 'enableMethodSnippets' )
39
38
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' ) {
41
40
const editor = getActiveRegularEditor ( ) !
42
41
const startPos = editor . selection . start
43
42
const nextSymbol = editor . document . getText ( new vscode . Range ( startPos , startPos . translate ( 0 , 1 ) ) )
44
- if ( ! [ '(' , '.' ] . includes ( nextSymbol ) ) {
43
+ if ( ! [ '(' , '.' , '`' ] . includes ( nextSymbol ) ) {
45
44
const controller = new AbortController ( )
46
45
inFlightMethodSnippetOperation = controller
47
46
const params : RequestResponseTypes [ 'getFullMethodSnippet' ] | undefined = await sendCommand ( 'getFullMethodSnippet' )
@@ -55,14 +54,7 @@ export default (tsApi: { onCompletionAccepted }) => {
55
54
const replacer = replaceArguments [ param . replace ( / \? $ / , '' ) ]
56
55
if ( replacer === null ) continue
57
56
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 )
66
58
} else {
67
59
snippet . appendPlaceholder ( param )
68
60
}
@@ -145,3 +137,14 @@ export default (tsApi: { onCompletionAccepted }) => {
145
137
}
146
138
} )
147
139
}
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