@@ -13,7 +13,7 @@ export default (tsApi: { onCompletionAccepted }) => {
13
13
let onCompletionAcceptedOverride : ( ( item : any ) => void ) | undefined
14
14
15
15
// eslint-disable-next-line complexity
16
- tsApi . onCompletionAccepted ( async ( item : vscode . CompletionItem & { document : vscode . TextDocument } ) => {
16
+ tsApi . onCompletionAccepted ( async ( item : vscode . CompletionItem & { document : vscode . TextDocument ; tsEntry } ) => {
17
17
if ( onCompletionAcceptedOverride ) {
18
18
onCompletionAcceptedOverride ( item )
19
19
return
@@ -36,57 +36,56 @@ export default (tsApi: { onCompletionAccepted }) => {
36
36
return
37
37
}
38
38
39
- const enableMethodSnippets = vscode . workspace . getConfiguration ( process . env . IDS_PREFIX , item . document ) . get ( 'enableMethodSnippets' )
40
-
41
- if ( enableMethodSnippets && /* snippet by vscode or by us to ignore pos */ typeof insertText !== 'object' ) {
39
+ if ( /* snippet is by vscode or by us to ignore pos */ typeof insertText !== 'object' ) {
42
40
const editor = getActiveRegularEditor ( ) !
43
- const startPos = editor . selection . start
44
- const nextSymbol = editor . document . getText ( new vscode . Range ( startPos , startPos . translate ( 0 , 1 ) ) )
45
- if ( ! [ '(' , '.' , '`' ] . includes ( nextSymbol ) ) {
46
- // all-in handling
47
- const controller = new AbortController ( )
48
- inFlightMethodSnippetOperation = controller
49
- const params : RequestResponseTypes [ 'getFullMethodSnippet' ] | undefined = await sendCommand ( 'getFullMethodSnippet' , {
50
- inputOptions : {
51
- acceptAmbiguous : lastAcceptedAmbiguousMethodSnippetSuggestion === suggestionName ,
52
- } satisfies RequestOptionsTypes [ 'getFullMethodSnippet' ] ,
41
+ if ( item . tsEntry . source ) {
42
+ await new Promise < void > ( resolve => {
43
+ vscode . workspace . onDidChangeTextDocument ( ( { document } ) => {
44
+ if ( editor . document !== document ) return
45
+ resolve ( )
46
+ } )
53
47
} )
48
+ await new Promise ( resolve => {
49
+ setTimeout ( resolve , 0 )
50
+ } )
51
+ }
54
52
55
- if ( controller . signal . aborted ) return
56
- if ( params === 'ambiguous' ) {
57
- lastAcceptedAmbiguousMethodSnippetSuggestion = suggestionName
58
- return
59
- }
60
-
61
- if ( ! params ) {
62
- return
63
- }
53
+ const documentation = typeof item . documentation === 'object' ? item . documentation . value : item . documentation
54
+ const dataMarker = '<!--tep '
55
+ if ( ! documentation ?. startsWith ( dataMarker ) ) return
56
+ const parsed = JSON . parse ( documentation . slice ( dataMarker . length , documentation . indexOf ( 'e-->' ) ) )
57
+ const { methodSnippet : params , isAmbiguous } = parsed
58
+ if ( ! params ) return
64
59
65
- const replaceArguments = getExtensionSetting ( 'methodSnippets.replaceArguments' )
66
-
67
- const snippet = new vscode . SnippetString ( '' )
68
- snippet . appendText ( '(' )
69
- // todo maybe when have optional (skipped), add a way to leave trailing , with tabstop (previous behavior)
70
- for ( const [ i , param ] of params . entries ( ) ) {
71
- const replacer = replaceArguments [ param . replace ( / \? $ / , '' ) ]
72
- if ( replacer === null ) continue
73
- if ( replacer ) {
74
- useReplacer ( snippet , replacer )
75
- } else {
76
- snippet . appendPlaceholder ( param )
77
- }
60
+ if ( isAmbiguous && lastAcceptedAmbiguousMethodSnippetSuggestion !== suggestionName ) {
61
+ lastAcceptedAmbiguousMethodSnippetSuggestion = suggestionName
62
+ return
63
+ }
78
64
79
- if ( i !== params . length - 1 ) snippet . appendText ( ', ' )
65
+ const replaceArguments = getExtensionSetting ( 'methodSnippets.replaceArguments' )
66
+
67
+ const snippet = new vscode . SnippetString ( '' )
68
+ snippet . appendText ( '(' )
69
+ // todo maybe when have optional (skipped), add a way to leave trailing , with tabstop (previous behavior)
70
+ for ( const [ i , param ] of params . entries ( ) ) {
71
+ const replacer = replaceArguments [ param . replace ( / \? $ / , '' ) ]
72
+ if ( replacer === null ) continue
73
+ if ( replacer ) {
74
+ useReplacer ( snippet , replacer )
75
+ } else {
76
+ snippet . appendPlaceholder ( param )
80
77
}
81
78
82
- snippet . appendText ( ')' )
83
- void editor . insertSnippet ( snippet , undefined , {
84
- undoStopAfter : false ,
85
- undoStopBefore : false ,
86
- } )
87
- if ( vscode . workspace . getConfiguration ( 'editor.parameterHints' ) . get ( 'enabled' ) && params . length > 0 ) {
88
- void vscode . commands . executeCommand ( 'editor.action.triggerParameterHints' )
89
- }
79
+ if ( i !== params . length - 1 ) snippet . appendText ( ', ' )
80
+ }
81
+
82
+ snippet . appendText ( ')' )
83
+ void editor . insertSnippet ( snippet , undefined , {
84
+ undoStopAfter : false ,
85
+ undoStopBefore : false ,
86
+ } )
87
+ if ( vscode . workspace . getConfiguration ( 'editor.parameterHints' ) . get ( 'enabled' ) && params . length > 0 ) {
88
+ void vscode . commands . executeCommand ( 'editor.action.triggerParameterHints' )
90
89
}
91
90
}
92
91
} )
0 commit comments