bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#62795: 29.0.90; eglot: gdscript default port is 6005


From: Ruijie Yu
Subject: bug#62795: 29.0.90; eglot: gdscript default port is 6005
Date: Sun, 16 Apr 2023 13:49:27 +0800
User-agent: mu4e 1.9.22; emacs 30.0.50

TLDR: I think the Melpa package "gdscript-mode" needs to define a
function `gdscript-mode-find-lsp', and eglot needs decide how to use
this function to get the port number.  Elaborations below.

xiliuya via "Bug reports for GNU Emacs, the Swiss army knife of text editors" 
<bug-gnu-emacs@gnu.org> writes:

> João Távora <joaotavora@gmail.com> writes:
>
>> I see.  So it's not an inferior process to Emacs. Then
>> maybe a function can be crafted in Elisp -- and housed
>> in gdscript-mode -- that somehow discovers if the Godot
>> Engine is running and finds the correct port.  Then
>> gdscript-mode can add that function to eglot-server-programs.
>
> I wrote this function to add gdscript-mode:
> -----
> (defun eglot-add-gdscript-lsp ()
>   (let* ((lsp-port (string-to-number
>                     (shell-command-to-string
>                      "awk -F'=' '/network\\/language_server\\/remote_port/ 
> {print $2;}' $HOME/.config/godot/editor_settings-4.tres")))
>          (lsp-list (cons 'gdscript-mode  (list "localhost" lsp-port
>                                                ))))
>     (push  lsp-list
>            eglot-server-programs)))
> -----

This is a user-local config file, with an interesting "_4" in its name.
Is it possible to have other numbers attached to the file name?  Does it
have a global default port for which we can search?  Something like
"/usr/share/godot/..." or "/etc/godot/..."?  Also, from your original
report, there seems to be a default value compiled into its C/C++
source.  Is there any chance to retrieve that value from a distributed
package?

I am looking at the last bullet point of `eglot-server-programs', at
which João seems to be hinting: creating a function that guesses (in our
case, look into config files to search for) the correct port number for
this lsp server.

I don't have this language environment setup nor even the gdscript-mode
library installed, but my guess is that this skeleton code should be in
gdscript-mode (modulo all my naming choices):

```emacs-lisp
(defun gdscript-mode-find-lsp (interactive-p)
  (let (port)
    ;; search for the port in this order: $XDG_CONFIG_HOME, /etc, /usr.
    ;; This uses some regexp extracted from your awk expression.
    (ignore port 'todo)
    ;; then return the host-port list when found
    (and port (list "localhost" port))))
```

One thing remains for eglot to decide (IMO), is what happens to the
eglot entry.  Do we do one of the two methods below, or is there a
better way?

```emacs-lisp
;; Method 1: This requires `gdscript-mode-find-lsp' be already defined
;; or autoloaded.
(push (cons 'gdscript-mode #'gdscript-mode-find-lsp))

;; Method 2.
(push (cons 'gdscript-mode
            (lambda (i)
              (and (require 'gdscript-mode nil t)
                   (fboundp 'gdscript-mode-find-lsp)
                   (gdscript-mode-find-lsp i)))))
```

The rest, including the discussion of how exactly to implement this
function, should then be handled in the repo of "gdscript-mode", since
it is not part of GNU Elpa nor NonGNU Elpa.

-- 
Best,


RY





reply via email to

[Prev in Thread] Current Thread [Next in Thread]