@@ -2,19 +2,25 @@ import * as vscode from 'vscode'
22import { getActiveRegularEditor } from '@zardoy/vscode-utils'
33import { conditionallyRegister } from '@zardoy/vscode-utils/build/settings'
44import { expandPosition } from '@zardoy/vscode-utils/build/position'
5- import { getExtensionSetting } from 'vscode-framework'
5+ import { getExtensionSetting , registerExtensionCommand } from 'vscode-framework'
66import { oneOf } from '@zardoy/utils'
77
88export default ( tsApi : { onCompletionAccepted } ) => {
99 let justAcceptedReturnKeywordSuggestion = false
10+ let onCompletionAcceptedOverride : ( ( item : any ) => void ) | undefined
1011
1112 tsApi . onCompletionAccepted ( ( item : vscode . CompletionItem & { document : vscode . TextDocument } ) => {
12- const enableMethodSnippets = vscode . workspace . getConfiguration ( process . env . IDS_PREFIX , item . document ) . get ( 'enableMethodSnippets' )
13+ if ( onCompletionAcceptedOverride ) {
14+ onCompletionAcceptedOverride ( item )
15+ return
16+ }
17+
1318 const { insertText, documentation = '' , kind } = item
1419 if ( kind === vscode . CompletionItemKind . Keyword && insertText === 'return ' ) {
1520 justAcceptedReturnKeywordSuggestion = true
1621 }
1722
23+ const enableMethodSnippets = vscode . workspace . getConfiguration ( process . env . IDS_PREFIX , item . document ) . get ( 'enableMethodSnippets' )
1824 const documentationString = documentation instanceof vscode . MarkdownString ? documentation . value : documentation
1925 const insertFuncArgs = / < ! - - i n s e r t - f u n c : ( .* ) - - > / . exec ( documentationString ) ?. [ 1 ]
2026 console . debug ( 'insertFuncArgs' , insertFuncArgs )
@@ -46,6 +52,29 @@ export default (tsApi: { onCompletionAccepted }) => {
4652 }
4753 } )
4854
55+ registerExtensionCommand ( 'inspectAcceptedCompletion' , async ( ) => {
56+ await vscode . window . withProgress (
57+ {
58+ location : vscode . ProgressLocation . Notification ,
59+ title : 'Waiting for completion to be accepted' ,
60+ cancellable : true ,
61+ } ,
62+ async ( _progress , token ) => {
63+ const accepted = await new Promise < boolean > ( resolve => {
64+ token . onCancellationRequested ( ( ) => {
65+ onCompletionAcceptedOverride = undefined
66+ resolve ( false )
67+ } )
68+ onCompletionAcceptedOverride = item => {
69+ console . dir ( item , { depth : 4 } )
70+ resolve ( true )
71+ }
72+ } )
73+ if ( accepted ) void vscode . window . showInformationMessage ( 'Completion accepted, see console for details' )
74+ } ,
75+ )
76+ } )
77+
4978 conditionallyRegister (
5079 'suggestions.keywordsInsertText' ,
5180 ( ) =>
0 commit comments