@@ -316,6 +316,9 @@ function handleSplunkDocument(context) {
316
316
// Register Setting completion items for this spec
317
317
let trimWhitespace = vscode . workspace . getConfiguration ( ) . get ( 'splunk.spec.trimEqualSignWhitespace' )
318
318
context . subscriptions . push ( provideSettingCompletionItems ( specConfig , trimWhitespace ) ) ;
319
+
320
+ // Register Hovers
321
+ context . subscriptions . push ( provideHovers ( specConfig ) ) ;
319
322
}
320
323
321
324
// Set up diagnostics (linting)
@@ -403,6 +406,55 @@ function checkSpecFilePath(specFilePath) {
403
406
return specFilePath ;
404
407
}
405
408
409
+ function provideHovers ( specConfig ) {
410
+
411
+ let enableHover = vscode . workspace . getConfiguration ( ) . get ( 'splunk.showDocumentationOnHover' ) ;
412
+ if ( ! enableHover ) {
413
+ return ;
414
+ }
415
+
416
+ // Get the currently open document
417
+ let currentDocument = path . basename ( vscode . window . activeTextEditor . document . uri . fsPath ) ;
418
+
419
+ vscode . languages . registerHoverProvider ( { language : 'splunk' , pattern : `**/${ currentDocument } ` } , {
420
+
421
+ provideHover ( document , position , token ) {
422
+
423
+ const range = document . getWordRangeAtPosition ( position , / \w [ - \w \. ] * / g) ;
424
+ const word = document . getText ( range ) ;
425
+
426
+ if ( ( document . lineAt ( position . line ) . text . startsWith ( '[' ) ) ) {
427
+ // This is a stanza
428
+
429
+ // Get stanzas for this .spec file
430
+ // Find the hovered word
431
+ // Add a hover for the value
432
+ let stanza = specConfig [ "stanzas" ] . find ( item => item . stanzaName === word )
433
+ if ( stanza ) {
434
+ let hoverContent = new vscode . MarkdownString ( stanza [ "docString" ] )
435
+ hoverContent . isTrusted = true ;
436
+ return new vscode . Hover ( hoverContent ) ;
437
+ }
438
+ } else {
439
+ // This might be a setting
440
+ let parentStanza = getParentStanza ( document , position . line ) ;
441
+ if ( parentStanza ) {
442
+ let stanzaSettings = splunkSpec . getStanzaSettings ( specConfig , parentStanza )
443
+ let setting = stanzaSettings . find ( item => item . name === word )
444
+ if ( setting ) {
445
+ let hoverContent = new vscode . MarkdownString ( setting [ "docString" ] )
446
+ hoverContent . isTrusted = true ;
447
+ return new vscode . Hover ( hoverContent ) ;
448
+ }
449
+ }
450
+ }
451
+ }
452
+
453
+ } )
454
+
455
+ return null
456
+ }
457
+
406
458
function provideStanzaCompletionItems ( specConfig ) {
407
459
408
460
// Get the currently open document
0 commit comments