@@ -2,19 +2,25 @@ import * as vscode from 'vscode'
2
2
import { getActiveRegularEditor } from '@zardoy/vscode-utils'
3
3
import { conditionallyRegister } from '@zardoy/vscode-utils/build/settings'
4
4
import { expandPosition } from '@zardoy/vscode-utils/build/position'
5
- import { getExtensionSetting } from 'vscode-framework'
5
+ import { getExtensionSetting , registerExtensionCommand } from 'vscode-framework'
6
6
import { oneOf } from '@zardoy/utils'
7
7
8
8
export default ( tsApi : { onCompletionAccepted } ) => {
9
9
let justAcceptedReturnKeywordSuggestion = false
10
+ let onCompletionAcceptedOverride : ( ( item : any ) => void ) | undefined
10
11
11
12
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
+
13
18
const { insertText, documentation = '' , kind } = item
14
19
if ( kind === vscode . CompletionItemKind . Keyword && insertText === 'return ' ) {
15
20
justAcceptedReturnKeywordSuggestion = true
16
21
}
17
22
23
+ const enableMethodSnippets = vscode . workspace . getConfiguration ( process . env . IDS_PREFIX , item . document ) . get ( 'enableMethodSnippets' )
18
24
const documentationString = documentation instanceof vscode . MarkdownString ? documentation . value : documentation
19
25
const insertFuncArgs = / < ! - - i n s e r t - f u n c : ( .* ) - - > / . exec ( documentationString ) ?. [ 1 ]
20
26
console . debug ( 'insertFuncArgs' , insertFuncArgs )
@@ -46,6 +52,29 @@ export default (tsApi: { onCompletionAccepted }) => {
46
52
}
47
53
} )
48
54
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
+
49
78
conditionallyRegister (
50
79
'suggestions.keywordsInsertText' ,
51
80
( ) =>
0 commit comments