@@ -20,8 +20,6 @@ export const linkProvider: LinkProvider = (doc: vscode.TextDocument) => {
20
20
lines . forEach ( ( line , index ) => {
21
21
for ( const regex of regexes ) {
22
22
const match = line . match ( regex ) ;
23
- // get reflection properties for classes
24
- // auto complete them + hover?
25
23
26
24
if ( ! match || match . index === undefined ) {
27
25
continue ;
@@ -96,73 +94,47 @@ export const hoverProvider: HoverProvider = (
96
94
doc : vscode . TextDocument ,
97
95
pos : vscode . Position ,
98
96
) : vscode . ProviderResult < vscode . Hover > => {
97
+ const components = getBladeComponents ( ) . items ;
98
+ const regexes = [ new RegExp ( / < \/ ? x - ( [ ^ \s > ] + ) / ) ] ;
99
+
100
+ if ( components . prefixes . length > 0 ) {
101
+ regexes . push (
102
+ new RegExp ( `<\\/?((${ components . prefixes . join ( "|" ) } )\\:[^\\s>]+)` ) ,
103
+ ) ;
104
+ }
105
+
106
+ for ( const regex of regexes ) {
107
+ const linkRange = doc . getWordRangeAtPosition ( pos , regex ) ;
108
+
109
+ if ( ! linkRange ) {
110
+ continue ;
111
+ }
112
+
113
+ const match = doc
114
+ . getText ( linkRange )
115
+ . replace ( "<" , "" )
116
+ . replace ( "/" , "" )
117
+ . replace ( "x-" , "" ) ;
118
+
119
+ const component = components . components [ match ] ;
120
+
121
+ if ( ! component ) {
122
+ return null ;
123
+ }
124
+
125
+ return new vscode . Hover (
126
+ new vscode . MarkdownString (
127
+ component . paths
128
+ . map (
129
+ ( path ) =>
130
+ `[${ path } ](${
131
+ vscode . Uri . file ( projectPath ( path ) ) . fsPath
132
+ } )`,
133
+ )
134
+ . join ( "\n\n" ) ,
135
+ ) ,
136
+ ) ;
137
+ }
138
+
99
139
return null ;
100
- // const links: vscode.DocumentLink[] = [];
101
- // const text = doc.getText();
102
- // const lines = text.split("\n");
103
- // const views = getBladeComponents().items;
104
-
105
- // lines.forEach((line, index) => {
106
- // const match = line.match(/<\/?x-([^\s>]+)/);
107
-
108
- // if (match && match.index !== undefined) {
109
- // const componentName = match[1];
110
- // // Standard component
111
- // const viewName = `components.${componentName}`;
112
- // // Index component
113
- // const indexName = `${viewName}.index`;
114
- // // Index component (via same name)
115
- // const sameIndexName = `${viewName}.${componentName.split(".").pop()}`;
116
-
117
- // const possibleNames = [
118
- // componentName,
119
- // viewName,
120
- // indexName,
121
- // sameIndexName,
122
- // ];
123
-
124
- // const view = views.find((v) => possibleNames.includes(v.key));
125
-
126
- // if (!view) {
127
- // return;
128
- // }
129
-
130
- // // return new vscode.Hover(
131
- // // new vscode.MarkdownString(
132
- // // `[${item.path}](${
133
- // // vscode.Uri.file(projectPath(item.path)).fsPath
134
- // // })`,
135
- // // ),
136
- // // );
137
- // // new vscode.DocumentLink(
138
- // // new vscode.Range(
139
- // // new vscode.Position(index, match.index + 1),
140
- // // new vscode.Position(
141
- // // index,
142
- // // match.index + match[0].length,
143
- // // ),
144
- // // ),
145
- // // vscode.Uri.parse(projectPath(view.path)),
146
- // // ),
147
- // // );
148
- // }
149
- // });
150
-
151
- // return null;
152
- // return Promise.resolve(links);
153
- // return findHoverMatchesInDoc(doc, pos, toFind, getBladeComponents, (match) => {
154
- // const item = getBladeComponents().items.find((view) => view.key === match);
155
-
156
- // if (!item) {
157
- // return null;
158
- // }
159
-
160
- // return new vscode.Hover(
161
- // new vscode.MarkdownString(
162
- // `[${item.path}](${
163
- // vscode.Uri.file(projectPath(item.path)).fsPath
164
- // })`,
165
- // ),
166
- // );
167
- // });
168
140
} ;
0 commit comments