@@ -18,23 +18,30 @@ export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => {
18
18
// Standard component
19
19
const viewName = "components." + componentName ;
20
20
// Index component
21
- const altName = `${ viewName } .${ componentName } ` ;
22
- const view = views . find ( ( v ) => [ viewName , altName ] . includes ( v . key ) ) ;
23
-
24
- if ( view ) {
25
- links . push (
26
- new vscode . DocumentLink (
27
- new vscode . Range (
28
- new vscode . Position ( index , match . index + 1 ) ,
29
- new vscode . Position (
30
- index ,
31
- match . index + match [ 0 ] . length ,
32
- ) ,
21
+ const indexName = `${ viewName } .index` ;
22
+ // Index component (via same name)
23
+ const sameIndexName = `${ viewName } .${ componentName . split ( "." ) . pop ( ) } ` ;
24
+
25
+ const view = views . find ( ( v ) =>
26
+ [ viewName , indexName , sameIndexName ] . includes ( v . key ) ,
27
+ ) ;
28
+
29
+ if ( ! view ) {
30
+ return ;
31
+ }
32
+
33
+ links . push (
34
+ new vscode . DocumentLink (
35
+ new vscode . Range (
36
+ new vscode . Position ( index , match . index + 1 ) ,
37
+ new vscode . Position (
38
+ index ,
39
+ match . index + match [ 0 ] . length ,
33
40
) ,
34
- vscode . Uri . parse ( projectPath ( view . path ) ) ,
35
41
) ,
36
- ) ;
37
- }
42
+ vscode . Uri . parse ( projectPath ( view . path ) ) ,
43
+ ) ,
44
+ ) ;
38
45
}
39
46
} ) ;
40
47
@@ -69,11 +76,23 @@ export const completionProvider: vscode.CompletionItemProvider = {
69
76
70
77
return getViews ( )
71
78
. items . filter ( ( view ) => view . key . startsWith ( pathPrefix ) )
72
- . map (
73
- ( view ) =>
74
- new vscode . CompletionItem (
75
- "x-" + view . key . replace ( pathPrefix , "" ) ,
76
- ) ,
77
- ) ;
79
+ . map ( ( view ) => {
80
+ const parts = view . key . split ( "." ) ;
81
+
82
+ if ( parts [ parts . length - 1 ] === "index" ) {
83
+ parts . pop ( ) ;
84
+ }
85
+
86
+ while (
87
+ parts . length > 1 &&
88
+ parts [ parts . length - 1 ] === parts [ parts . length - 2 ]
89
+ ) {
90
+ parts . pop ( ) ;
91
+ }
92
+
93
+ return new vscode . CompletionItem (
94
+ "x-" + parts . join ( "." ) . replace ( pathPrefix , "" ) ,
95
+ ) ;
96
+ } ) ;
78
97
} ,
79
98
} ;
0 commit comments