3737(require 'cus-edit )
3838(require 'ht )
3939(require 'shr )
40+ (require 'hl-line )
4041
4142(defgroup lsp-sonarlint nil
4243 " SonarLint lsp server group"
@@ -468,16 +469,25 @@ Returns a list of plists with the overlay, step number, and message."
468469 (overlay-put ov 'face 'lsp-sonarlint-secondary-location-face ))
469470 (setq lsp-sonarlint--previously-focused-overlays nil ))
470471
472+ (defun lsp-sonarlint--highlight-target (overlay )
473+ " Highlight OVERLAY."
474+ (lsp-sonarlint--unfocus-overlays)
475+ (overlay-put overlay 'face 'lsp-sonarlint-highlighted-secondary-face )
476+ (push overlay lsp-sonarlint--previously-focused-overlays))
477+
471478(defun lsp-sonarlint--focus-on-target (overlay )
472- " Highlight the OVERLAY in the target buffer ."
479+ " Put point to OVERLAY and make it visible in another window ."
473480 (when-let ((target-buffer (overlay-buffer overlay))
474481 (prev-buffer (current-buffer )))
475482 (switch-to-buffer-other-window target-buffer)
476483 (goto-char (overlay-start overlay))
477- (switch-to-buffer-other-window prev-buffer)
478- (lsp-sonarlint--unfocus-overlays)
479- (overlay-put overlay 'face 'lsp-sonarlint-highlighted-secondary-face )
480- (push overlay lsp-sonarlint--previously-focused-overlays)))
484+ (hl-line-highlight ) ; make sure the line highlighting is updated
485+ (switch-to-buffer-other-window prev-buffer)))
486+
487+ (defvar lsp-sonarlint--original-buffer nil
488+ " The buffer with code and SonarLint issues.
489+
490+ Useful when exploring secondary locations, which uses an auxiliary buffer." )
481491
482492(defun lsp-sonarlint--on-line-move (&rest _args )
483493 " Highlight the current line in the secondary locations buffer."
@@ -487,7 +497,13 @@ Returns a list of plists with the overlay, step number, and message."
487497 (setq focus-overlay (overlay-get ovl 'focus-location ))))
488498 (overlays-at (point )))
489499 (when focus-overlay
490- (lsp-sonarlint--focus-on-target focus-overlay)))))
500+ (lsp-sonarlint--focus-on-target focus-overlay)
501+ (lsp-sonarlint--highlight-target focus-overlay))))
502+ (when (eq (current-buffer ) lsp-sonarlint--original-buffer)
503+ (when-let ((focus-overlay (seq-find (lambda (ovl ) (overlay-get ovl 'lsp-sonarlint--message-overlay ))
504+ (overlays-at (point )))))
505+ (lsp-sonarlint--focus-on-target (overlay-get focus-overlay 'lsp-sonarlint--message-overlay ))
506+ (hl-line-highlight ))))
491507
492508
493509(defun lsp-sonarlint--on-kill-buffer (&rest _args )
@@ -503,8 +519,10 @@ pointing to the `:overlay' from LOC-MESSAGE."
503519 (insert (plist-get loc-message :message ))
504520 (let ((overlay (lsp-sonarlint--make-overlay-between
505521 `(:begin ,(line-beginning-position )
506- :end ,(line-end-position )))))
507- (overlay-put overlay 'focus-location (plist-get loc-message :overlay ))
522+ :end ,(line-end-position ))))
523+ (focus-overlay (plist-get loc-message :overlay )))
524+ (overlay-put overlay 'focus-location focus-overlay)
525+ (overlay-put focus-overlay 'lsp-sonarlint--message-overlay overlay)
508526 overlay))
509527
510528(defun lsp-sonarlint--extract-located-messages (locations )
@@ -601,11 +619,6 @@ adjust offsets to account for the number labels prepended to each location."
601619 'face 'lsp-sonarlint-embedded-msg-face )))))
602620 (lsp-sonarlint--extract-located-messages locations)))
603621
604- (defvar lsp-sonarlint--original-buffer nil
605- " The buffer with code and SonarLint issues.
606-
607- Useful when exploring secondary locations, which uses an auxiliary buffer." )
608-
609622(defun lsp-sonarlint--show-all-locations (command )
610623 " Show all secondary locations listed in COMMAND for the focused issue."
611624 (lsp-sonarlint--remove-secondary-loc-highlights)
0 commit comments