From 686feebf2da438d5b527ad9300a0379d15cf2a3c Mon Sep 17 00:00:00 2001 From: Kato Muso Date: Tue, 5 Nov 2024 07:04:14 +0000 Subject: [PATCH] Add gdscript-eglot--extract-port function --- gdscript-eglot.el | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/gdscript-eglot.el b/gdscript-eglot.el index e558892..89f7f0d 100644 --- a/gdscript-eglot.el +++ b/gdscript-eglot.el @@ -50,6 +50,17 @@ (or (getenv "XDG_CONFIG_HOME") "~/.config/") "godot")))) +(defun gdscript-eglot--extract-port (editor-settings-file) + (when (file-exists-p editor-settings-file) + (with-temp-buffer + (insert-file-contents editor-settings-file) + (when (re-search-forward + (rx "network/language_server/remote_port" + (* space) ?= (* space) + (group (+ digit))) + nil t) + (string-to-number (match-string 1)))))) + ;;;###autoload (defun gdscript-eglot-contact (_interactive) "Attempt to help `eglot' contact the running gdscript LSP. @@ -64,16 +75,8 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-04/msg01070.html." (settings-file (file-name-concat config-dir (format "editor_settings-%s.tres" gdscript-eglot-version)))) - (when (file-exists-p settings-file) - (when-let ((port (with-temp-buffer - (insert-file-contents settings-file) - (when (re-search-forward - (rx "network/language_server/remote_port" - (* space) ?= (* space) - (group (+ digit))) - nil t) - (string-to-number (match-string 1)))))) - (list "localhost" port)))))) + (when-let ((port (gdscript-eglot--extract-port settings-file))) + (list "localhost" port))))) (provide 'gdscript-eglot) ;;; gdscript-eglot.el ends here.