@@ -11,8 +11,16 @@ export default (
11
11
sourceFile : tslib . SourceFile ,
12
12
jsxCompletionsMap : Configuration [ 'jsxCompletionsMap' ] ,
13
13
) : tslib . CompletionEntry [ ] => {
14
- // TODO refactor to findNodeAtPosition
14
+ // ++ patch with jsxCompletionsMap
15
+ // -- don't
16
+ // <div| - identifier, not attribute --
17
+ // <div | - not identifier, not attribute ++
18
+ // <div t| - identifier -> attribute ++
19
+ // <div a={} t={} - in attributes ++
20
+ // <div t={|} - isn't attribute, so doesn't matter --
21
+ let jsxAttributeCandidate = ! ts . isIdentifier ( node )
15
22
if ( ts . isIdentifier ( node ) ) node = node . parent
23
+ // fix builtin jsx attribute completion
16
24
if ( ts . isJsxAttribute ( node ) && node . initializer ) {
17
25
entries = entries . map ( entry => {
18
26
return {
@@ -21,9 +29,15 @@ export default (
21
29
}
22
30
} )
23
31
}
24
- if ( ts . isJsxAttribute ( node ) ) node = node . parent
25
- if ( ts . isJsxAttributes ( node ) ) node = node . parent
26
- if ( Object . keys ( jsxCompletionsMap ) . length && ( ts . isJsxOpeningElement ( node ) || ts . isJsxSelfClosingElement ( node ) ) ) {
32
+ if ( ts . isJsxAttribute ( node ) ) {
33
+ jsxAttributeCandidate = true
34
+ node = node . parent
35
+ }
36
+ if ( ts . isJsxAttributes ( node ) ) {
37
+ jsxAttributeCandidate = true
38
+ node = node . parent
39
+ }
40
+ if ( jsxAttributeCandidate && Object . keys ( jsxCompletionsMap ) . length && ( ts . isJsxOpeningElement ( node ) || ts . isJsxSelfClosingElement ( node ) ) ) {
27
41
const tagName = node . tagName . getText ( )
28
42
// TODO use the same perf optimization for replaceSuggestions
29
43
const patchEntries : Record < number , Configuration [ 'jsxCompletionsMap' ] [ string ] > = { }
@@ -34,7 +48,7 @@ export default (
34
48
if ( comparingTagName && comparingTagName !== tagName ) continue
35
49
const comparingName = key . slice ( splitTagNameIdx + 1 )
36
50
if ( comparingName . includes ( '*' ) ) {
37
- const regexMatch = new RegExp ( escapeStringRegexp ( comparingName ) . replaceAll ( '\\*' , '.*' ) )
51
+ const regexMatch = new RegExp ( `^ ${ escapeStringRegexp ( comparingName ) . replaceAll ( '\\*' , '.*' ) } $` )
38
52
entries . forEach ( ( { name, kind } , index ) => {
39
53
if ( kind === ts . ScriptElementKind . memberVariableElement && regexMatch . test ( name ) ) {
40
54
patchEntries [ index ] = patchMethod
0 commit comments