@@ -11,6 +11,7 @@ export default (
11
11
sourceFile : ts . SourceFile ,
12
12
jsxCompletionsMap : Configuration [ 'jsxCompletionsMap' ] ,
13
13
) : ts . CompletionEntry [ ] => {
14
+ const originalNode = node
14
15
// ++ patch with jsxCompletionsMap
15
16
// -- don't
16
17
// <div| - identifier, not attribute --
@@ -78,13 +79,24 @@ export default (
78
79
const enableJsxAttributesShortcuts = sharedCompletionContext . c ( 'jsxAttributeShortcutCompletions.enable' )
79
80
if ( enableJsxAttributesShortcuts !== 'disable' ) {
80
81
const locals = collectLocalSymbols ( node , sharedCompletionContext . typeChecker )
82
+ let attrib = originalNode . parent as ts . JsxAttribute | undefined
83
+ if ( ! ts . isJsxAttribute ( attrib ! ) ) {
84
+ attrib = undefined
85
+ }
81
86
entries = entries . flatMap ( entry => {
82
87
if ( locals . includes ( entry . name ) ) {
83
88
const insertText = `${ entry . name } ={${ entry . name } }`
84
- const additionalSuggestions = {
89
+ const pos = attrib ? attrib . end - attrib . getWidth ( ) : 0
90
+ const additionalSuggestions : ts . CompletionEntry = {
85
91
...entry ,
86
92
name : insertText ,
87
93
insertText,
94
+ replacementSpan : attrib
95
+ ? {
96
+ start : pos ,
97
+ length : attrib . end - pos ,
98
+ }
99
+ : undefined ,
88
100
}
89
101
return enableJsxAttributesShortcuts === 'after' ? [ entry , additionalSuggestions ] : [ additionalSuggestions , entry ]
90
102
}
0 commit comments