@@ -163,6 +163,25 @@ const createModules = (document: vscode.TextDocument, position: vscode.Position)
163
163
return [ ] ;
164
164
} ;
165
165
166
+ const createHover = ( document : vscode . TextDocument , position : vscode . Position ) : vscode . Hover => {
167
+ const hoverText = document . getText ( document . getWordRangeAtPosition ( position ) ) ;
168
+ const rm = new RegExp ( `([a-zA-Z0-9$_ ]+)\\.${ hoverText } ([a-zA-Z0-9$_ ]*)` ) ;
169
+ const match = rm . exec ( document . lineAt ( position . line ) . text ) ;
170
+ const modules = Object . keys ( iotjs ) ;
171
+ let hoverContent : vscode . MarkdownString [ ] = [ ] ;
172
+ const availableModules = defaultModules . concat ( lookForModules ( document . getText ( ) ) ) ;
173
+ const hoverModule = availableModules . find ( mod => mod . link === match [ 1 ] ) . mod ;
174
+
175
+ modules . forEach ( mod => {
176
+ for ( let i in iotjs [ mod ] ) {
177
+ if ( hoverText === iotjs [ mod ] [ i ] . insertText && hoverModule === mod ) {
178
+ hoverContent . push ( iotjs [ mod ] [ i ] . documentation ) ;
179
+ }
180
+ }
181
+ } ) ;
182
+ return new vscode . Hover ( hoverContent ) ;
183
+ } ;
184
+
166
185
export const activate = ( context : vscode . ExtensionContext ) => {
167
186
context . subscriptions . push (
168
187
vscode . commands . registerCommand ( 'iotjs-debug.provideInitialConfigurations' , provideInitialConfigurations ) ,
@@ -176,7 +195,12 @@ export const activate = (context: vscode.ExtensionContext) => {
176
195
provideCompletionItems ( document : vscode . TextDocument , position : vscode . Position ) {
177
196
return createItems ( document , position ) ;
178
197
}
179
- } , '.' )
198
+ } , '.' ) ,
199
+ vscode . languages . registerHoverProvider ( JS_MODE , {
200
+ provideHover ( document : vscode . TextDocument , position : vscode . Position ) {
201
+ return createHover ( document , position ) ;
202
+ }
203
+ } )
180
204
) ;
181
205
} ;
182
206
0 commit comments