emacs-lsp / lsp-java

lsp-mode :heart: java
https://emacs-lsp.github.io/lsp-java
GNU General Public License v3.0
650 stars 90 forks source link

exceptions and log messages in `dap-debug` buffers #338

Open deb75 opened 3 years ago

deb75 commented 3 years ago

Hello,

I noticed that when some exceptions are raised and displayed in the dab-debug buffer like this :

Exception in thread "main" java.lang.RuntimeException: sdsd
    at com.tttt.wwwww.qqqqqqq.eazazaza.Example10.main(Example10.java:73)

I am able to jump on the place where the exception has been thrown by clicking on the line "at ..."

I wonder if this could be possible with log messages which appears like this :

10:23:01.095 - DEBUG - Myclass.mymethod - my message

When I click on it, emacs reacts with :

Find this error in (default *unknown*)

Is there a way of configuring lsp-java or/and the log messages format so that lsp-java is able to jump on the place where the log message is emitted ?

Regards

deb75 commented 3 years ago

Any hints ?

Is there a way to jump to the line in corresponding file which produced the logging message just by clicking on the logging message ? It is possible with exception message but it seems due to the comint mode according to my (very poor) understanding.

Regards

deb75 commented 3 years ago

Hi,

I finally ended up writing some functions to do it :

(defun logjump/select-inside-paren ()
  (let (p1 p2)
    (skip-chars-backward "^(")
    (setq p1 (point))
    (skip-chars-forward "^)")
    (setq p2 (point))
    (buffer-substring-no-properties p1 p2)))

(defun logjump/open-file-at-line ()
  (interactive)
  (let (s l  lineno filepath p)
    (setq p (point))
    (setq s (logjump/select-inside-paren))
    (setq l (split-string s ":"))
    (setq lineno (string-to-number (nth 1 l)))
    (setq filepath (car (directory-files-recursively (expand-file-name "src" (projectile-project-root)) (car l))))
    (if (< (length (window-list)) 2)
        (split-window-below))
    (other-window 1)
    (find-file filepath)
    (goto-line lineno)
    (other-window -1)
    (goto-char p)))

(add-hook 'dap-server-log-mode  (lambda() (local-set-key [f5] 'logjump/open-file-at-line)))

The last line with the hook is currently not working. When dap-java opens a server log buffer, it should set a local key, but I have to do it manually.

The function takes the log line below the point and looks for the pattern "(filename:34)". Then, it uses the projectile project root and assumes sources are in "src" subfolder. I did that to avoid searching everywhere when the project directory tree is large.

I would like to perform some enhancements :

but I do not really know the way to go

Any hints ?

Regards