unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Ruijie Yu <ruijie@netyu.xyz>
Cc: Eli Zaretskii <eliz@gnu.org>,
	62795@debbugs.gnu.org, xiliuya <xiliuya@aliyun.com>
Subject: bug#62795: 29.0.90; eglot: gdscript default port is 6005
Date: Sun, 16 Apr 2023 12:08:50 +0100	[thread overview]
Message-ID: <87zg78yth9.fsf@gmail.com> (raw)
In-Reply-To: <sdvleis2x7c.fsf@netyu.xyz> (Ruijie Yu's message of "Sun, 16 Apr 2023 13:49:27 +0800")

Ruijie Yu <ruijie@netyu.xyz> writes:

> 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)))
>> -----

We're getting closer, but this is not what I meant at all.  It's much
simpler.

  (defun gdscript-eglot-contact (&optional _interactive)
    "Produce a suitable value for LSP contact in `eglot-server-programs'."
    (list "localhost"
          (string-to-number
           (shell-command-to-string
            "awk -F'=' '/network\\/language_server\\/remote_port/ {print $2;}' $HOME/.config/godot/editor_settings-4.tres"))))

In your configuration, or in gdscript-mode.el directly

  (add-to-list 'eglot-server-programs
               '(gdscript-mode . gdscript-eglot-contact))

Do you follow the idea?  You can add a function object to
eglot-server-programs _instead_ of the host/port list.  The docstring of
eglot-server-programs should be clear on the matter.

     [...]

     CONTACT can be:
    
     [...]
    
     * A list (HOST PORT [TCP-ARGS...]) where HOST is a string and
       PORT is a positive integer for connecting to a server via TCP.
    
     [...]
    
     * A function of a single argument producing any of the above
       values for CONTACT.  The argument's value is non-nil if the
       connection was requested interactively (e.g. from the `eglot'
       command), and nil if it wasn't (e.g. from `eglot-ensure').  If
       the call is interactive, the function can ask the user for
       hints on finding the required programs, etc.  Otherwise, it
       should not ask the user for any input, and return nil or signal
       an error if it can't produce a valid CONTACT.   [...]


If it's not clear, let us know.

Another detail: I think the use of `awk` can probably be be optimized
away Elisp code for processing text.  Same for the shell use of $HOME
which is also has an Elisp abstraction (see docstring of
`expand-file-name`).  In theory, you don't need shell-command-to-string
at all.

If the function is made simple enough and portable across operating
systems where the Godot engine runs, then a lambda version of it can be
added to eglot.el IMO.  But it's really better to add it to
gdscript-mode.el, wherever it is maintained.

João







  parent reply	other threads:[~2023-04-16 11:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-12 10:33 bug#62795: 29.0.90; eglot: gdscript default port is 6005 xiliuya via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-15  8:07 ` Eli Zaretskii
2023-04-15  8:17   ` João Távora
2023-04-15 12:19     ` xiliuya via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-15 13:13       ` João Távora
2023-04-15 13:28         ` xiliuya via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-15 14:04           ` xiliuya via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-16  3:48         ` xiliuya via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-16  5:49           ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-16  6:16             ` xiliuya via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-16  7:36               ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-16  8:57                 ` xiliuya via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-16 11:08             ` João Távora [this message]
2023-04-16 12:29               ` xiliuya via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-17  7:33                 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-17  8:43                   ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-17 13:22                     ` xiliuya via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-16 11:16             ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zg78yth9.fsf@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=62795@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=ruijie@netyu.xyz \
    --cc=xiliuya@aliyun.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).