Pure-D / serve-d

D LSP server (dlang language server protocol server)
MIT License
200 stars 48 forks source link

Attempt att using serve-d via lsp-mode in Emacs #317

Open nordlow opened 1 year ago

nordlow commented 1 year ago

Adding

(defun serve-d-command ()
  "Shell command to start serve-d."
  '("dub" "run" "serve-d@~master")) ;; "--logfile" "serve-d.log" "--loglevel" "all"

(require 'lsp-mode nil t)

(dolist (mode '(d-mode d-ts-mode))
  ;; (add-hook mode #'lsp)
  (add-to-list 'lsp-language-id-configuration `(,mode . "d")))

(lsp-register-client
 (make-lsp-client
  :new-connection (lsp-stdio-connection #'serve-d-command)
  :major-modes '(d-mode d-ts-mode)
  :server-id 'serve-d))

to my ~/.emacs.d/init.el followed by a manual evalutation of

(dolist (mode '(d-mode d-ts-mode))
  ;; (add-hook mode #'lsp)
  (add-to-list 'lsp-language-id-configuration `(,mode . "d")))

(lsp-register-client
 (make-lsp-client
  :new-connection (lsp-stdio-connection #'serve-d-command)
  :major-modes '(d-mode d-ts-mode)
  :server-id 'serve-d))

and manual activation of lsp-mode in d-mode sets up a connection to an instance of serve-d.

However trying out xref-find-definitions on, for instance, the symbol WordOrder.mostSignificantWordFirst at https://github.com/nordlow/gmp-d/blob/master/src/gmp/z.d#L312 results in

Debugger entered--Lisp error: (error "Attempted to get unknown instance component DCDComponent in instance cwd:$HOME/Work/gmp-d")
  error("Attempted to get unknown instance component DCDComponent in instance cwd:$HOME/Work/gmp-d")
  lsp-request("textDocument/definition" (:textDocument (:uri "file://$HOME/Work/gmp-d/src/gmp/z.d") :position (:line 311 :character 25)))
  #f(compiled-function (backend identifier) #<bytecode 0xc84f7d380117922>)(xref-lsp #("mostSignificantWordFirst" 0 24 (identifier-at-point t face (highlight-symbol-face font-lock-constant-face) fontified t)))
  apply(#f(compiled-function (backend identifier) #<bytecode 0xc84f7d380117922>) xref-lsp #("mostSignificantWordFirst" 0 24 (identifier-at-point t face (highlight-symbol-face font-lock-constant-face) fontified t)))
  xref-backend-definitions(xref-lsp #("mostSignificantWordFirst" 0 24 (identifier-at-point t face (highlight-symbol-face font-lock-constant-face) fontified t)))
  #f(compiled-function () #<bytecode -0xe5cbf2f02411dfc>)()
  xref-show-definitions-buffer(#f(compiled-function () #<bytecode -0xe5cbf2f02411dfc>) ((window . #<window 9 on z.d>) (display-action) (auto-jump)))
  xref--show-defs(#f(compiled-function () #<bytecode -0xe5cbf2f02411dfc>) nil)
  xref--find-definitions(#("mostSignificantWordFirst" 0 24 (identifier-at-point t face (highlight-symbol-face font-lock-constant-face) fontified t)) nil)
  xref-find-definitions(#("mostSignificantWordFirst" 0 24 (identifier-at-point t face (highlight-symbol-face font-lock-constant-face) fontified t)))
  funcall-interactively(xref-find-definitions #("mostSignificantWordFirst" 0 24 (identifier-at-point t face (highlight-symbol-face font-lock-constant-face) fontified t)))
  command-execute(xref-find-definitions)

. What's missing?

See also https://forum.dlang.org/post/phfkgudvadkqkmnvfrvu@forum.dlang.org.

WebFreak001 commented 1 year ago

lookup works fine here with vscode, so it's likely an issue with how serve-d is initialized with emacs.

Can you share more log, especially the initialization parts?

nordlow commented 1 year ago

lookup works fine here with vscode, so it's likely an issue with how serve-d is initialized with emacs.

Can you share more log, especially the initialization parts?

Ok, thanks.

Which logs are you referring? The output from serve-d?

WebFreak001 commented 1 year ago

the LSP logs, ideally also what emacs sends and receives, but the serve-d logs alone (e.g. piped to a file) would probably also help already.

Enable trace logging for it