@@ -11,6 +11,7 @@ export default (
1111 sourceFile : ts . SourceFile ,
1212 jsxCompletionsMap : Configuration [ 'jsxCompletionsMap' ] ,
1313) : ts . CompletionEntry [ ] => {
14+ const originalNode = node
1415 // ++ patch with jsxCompletionsMap
1516 // -- don't
1617 // <div| - identifier, not attribute --
@@ -78,13 +79,24 @@ export default (
7879 const enableJsxAttributesShortcuts = sharedCompletionContext . c ( 'jsxAttributeShortcutCompletions.enable' )
7980 if ( enableJsxAttributesShortcuts !== 'disable' ) {
8081 const locals = collectLocalSymbols ( node , sharedCompletionContext . typeChecker )
82+ let attrib = originalNode . parent as ts . JsxAttribute | undefined
83+ if ( ! ts . isJsxAttribute ( attrib ! ) ) {
84+ attrib = undefined
85+ }
8186 entries = entries . flatMap ( entry => {
8287 if ( locals . includes ( entry . name ) ) {
8388 const insertText = `${ entry . name } ={${ entry . name } }`
84- const additionalSuggestions = {
89+ const pos = attrib ? attrib . end - attrib . getWidth ( ) : 0
90+ const additionalSuggestions : ts . CompletionEntry = {
8591 ...entry ,
8692 name : insertText ,
8793 insertText,
94+ replacementSpan : attrib
95+ ? {
96+ start : pos ,
97+ length : attrib . end - pos ,
98+ }
99+ : undefined ,
88100 }
89101 return enableJsxAttributesShortcuts === 'after' ? [ entry , additionalSuggestions ] : [ additionalSuggestions , entry ]
90102 }
0 commit comments