11import * as vscode from 'vscode'
2+ import { getActiveRegularEditor } from '@zardoy/vscode-utils'
3+ import { } from 'vscode-framework'
24
35export const activate = async ( ) => {
46 const tsExtension = vscode . extensions . getExtension ( 'vscode.typescript-language-features' )
@@ -21,4 +23,34 @@ export const activate = async () => {
2123 if ( affectsConfiguration ( process . env . IDS_PREFIX ! ) ) syncConfig ( )
2224 } )
2325 syncConfig ( )
26+
27+ api . onCompletionAccepted ( ( item : vscode . CompletionItem & { document : vscode . TextDocument } ) => {
28+ const enableMethodSnippets = vscode . workspace . getConfiguration ( process . env . IDS_PREFIX , item . document ) . get ( 'enableMethodSnippets' )
29+ const { documentation = '' } = item
30+ const documentationString = documentation instanceof vscode . MarkdownString ? documentation . value : documentation
31+ const insertFuncArgs = / < ! - - i n s e r t - f u n c : ( .* ) - - > / . exec ( documentationString ) ?. [ 1 ]
32+ if ( enableMethodSnippets && insertFuncArgs !== undefined ) {
33+ const editor = getActiveRegularEditor ( ) !
34+ const startPos = editor . selection . start
35+ const nextSymbol = editor . document . getText ( new vscode . Range ( startPos , startPos . translate ( 0 , 1 ) ) )
36+ if ( nextSymbol !== '(' ) {
37+ const snippet = new vscode . SnippetString ( '' )
38+ snippet . appendText ( '(' )
39+ const args = insertFuncArgs . split ( ',' )
40+ for ( const [ i , arg ] of args . entries ( ) ) {
41+ if ( ! arg ) continue
42+ snippet . appendPlaceholder ( arg )
43+ if ( i !== args . length - 1 ) snippet . appendText ( ', ' )
44+ }
45+
46+ snippet . appendText ( ')' )
47+ void editor . insertSnippet ( snippet , undefined , {
48+ undoStopAfter : false ,
49+ undoStopBefore : false ,
50+ } )
51+ if ( vscode . workspace . getConfiguration ( 'editor.parameterHints' ) . get ( 'enabled' ) )
52+ void vscode . commands . executeCommand ( 'editor.action.triggerParameterHints' )
53+ }
54+ }
55+ } )
2456}
0 commit comments