@@ -12,6 +12,7 @@ export default (tsApi: { onCompletionAccepted }) => {
1212 let justAcceptedReturnKeywordSuggestion = false
1313 let onCompletionAcceptedOverride : ( ( item : any ) => void ) | undefined
1414
15+ // eslint-disable-next-line complexity
1516 tsApi . onCompletionAccepted ( async ( item : vscode . CompletionItem & { document : vscode . TextDocument } ) => {
1617 if ( onCompletionAcceptedOverride ) {
1718 onCompletionAcceptedOverride ( item )
@@ -45,11 +46,27 @@ export default (tsApi: { onCompletionAccepted }) => {
4546 inFlightMethodSnippetOperation = controller
4647 const params : RequestResponseTypes [ 'getFullMethodSnippet' ] | undefined = await sendCommand ( 'getFullMethodSnippet' )
4748 if ( ! controller . signal . aborted && params ) {
49+ const replaceArguments = getExtensionSetting ( 'methodSnippets.replaceArguments' )
50+
4851 const snippet = new vscode . SnippetString ( '' )
4952 snippet . appendText ( '(' )
50- // todo maybe when have skipped, add a way to leave trailing , (previous behavior)
53+ // todo maybe when have optional ( skipped) , add a way to leave trailing , with tabstop (previous behavior)
5154 for ( const [ i , param ] of params . entries ( ) ) {
52- snippet . appendPlaceholder ( param )
55+ const replacer = replaceArguments [ param . replace ( / \? $ / , '' ) ]
56+ if ( replacer === null ) continue
57+ 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+ } )
66+ } else {
67+ snippet . appendPlaceholder ( param )
68+ }
69+
5370 if ( i !== params . length - 1 ) snippet . appendText ( ', ' )
5471 }
5572
0 commit comments