From 3052839d71eccbb5d17c4942bba695cb293b28da Mon Sep 17 00:00:00 2001 From: Kato Muso Date: Mon, 4 Nov 2024 09:28:33 +0000 Subject: [PATCH 1/5] Refactor gdscript-eglot-contact --- gdscript-eglot.el | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/gdscript-eglot.el b/gdscript-eglot.el index 4aeae12..c875e79 100644 --- a/gdscript-eglot.el +++ b/gdscript-eglot.el @@ -52,30 +52,25 @@ definitions of HOST, PORT, and INTERACTIVE. For more context, see https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-04/msg01070.html." (save-excursion - (let* ((cfg-dir (pcase system-type - ('darwin "~/Library/Application Support/Godot/") - ('windows-nt (substitute-in-file-name "$APPDATA/Godot/")) - ('gnu/linux (file-name-concat - (or (getenv "XDG_CONFIG_HOME") "~/.config/") - "godot")))) - (cfg-buffer (find-file-noselect - (file-name-concat - cfg-dir - (format "editor_settings-%s.tres" - gdscript-eglot-version)))) - (port - (with-current-buffer cfg-buffer - (goto-char 0) - (and - (re-search-forward - (rx "network/language_server/remote_port" - (* space) ?= (* space) - (group (+ digit))) - nil t) - (string-to-number (match-string 1)))))) - (kill-buffer cfg-buffer) - ;; then return the host-port list when found - (and port (list "localhost" port))))) + (let* ((config-dir (pcase system-type + ('darwin "~/Library/Application Support/Godot/") + ('windows-nt (substitute-in-file-name "$APPDATA/Godot/")) + ('gnu/linux (file-name-concat + (or (getenv "XDG_CONFIG_HOME") "~/.config/") + "godot")))) + (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)))))) (provide 'gdscript-eglot) ;;; gdscript-eglot.el ends here. From f8fce3ad1ab84406ebcacbd59fde0e75bfd14eee Mon Sep 17 00:00:00 2001 From: Kato Muso Date: Tue, 5 Nov 2024 06:52:29 +0000 Subject: [PATCH 2/5] Add gdscript-eglot--get-config-dir function --- gdscript-eglot.el | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/gdscript-eglot.el b/gdscript-eglot.el index c875e79..e558892 100644 --- a/gdscript-eglot.el +++ b/gdscript-eglot.el @@ -42,6 +42,14 @@ "The version of godot in use." :type 'string) +(defun gdscript-eglot--get-config-dir () + (pcase system-type + ('darwin "~/Library/Application Support/Godot/") + ('windows-nt (substitute-in-file-name "$APPDATA/Godot/")) + ('gnu/linux (file-name-concat + (or (getenv "XDG_CONFIG_HOME") "~/.config/") + "godot")))) + ;;;###autoload (defun gdscript-eglot-contact (_interactive) "Attempt to help `eglot' contact the running gdscript LSP. @@ -52,12 +60,7 @@ definitions of HOST, PORT, and INTERACTIVE. For more context, see https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-04/msg01070.html." (save-excursion - (let* ((config-dir (pcase system-type - ('darwin "~/Library/Application Support/Godot/") - ('windows-nt (substitute-in-file-name "$APPDATA/Godot/")) - ('gnu/linux (file-name-concat - (or (getenv "XDG_CONFIG_HOME") "~/.config/") - "godot")))) + (let* ((config-dir (gdscript-eglot--get-config-dir)) (settings-file (file-name-concat config-dir (format "editor_settings-%s.tres" gdscript-eglot-version)))) From 686feebf2da438d5b527ad9300a0379d15cf2a3c Mon Sep 17 00:00:00 2001 From: Kato Muso Date: Tue, 5 Nov 2024 07:04:14 +0000 Subject: [PATCH 3/5] 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. From 88f6bca508c36dbd4d2810acf87aca386430cd74 Mon Sep 17 00:00:00 2001 From: Kato Muso Date: Fri, 6 Dec 2024 23:40:11 +0000 Subject: [PATCH 4/5] Add docstring for gdscript-eglot--get-config-dir function --- gdscript-eglot.el | 1 + 1 file changed, 1 insertion(+) diff --git a/gdscript-eglot.el b/gdscript-eglot.el index 89f7f0d..7b2a097 100644 --- a/gdscript-eglot.el +++ b/gdscript-eglot.el @@ -43,6 +43,7 @@ :type 'string) (defun gdscript-eglot--get-config-dir () + "Get system-specific directory with Godot configuration files." (pcase system-type ('darwin "~/Library/Application Support/Godot/") ('windows-nt (substitute-in-file-name "$APPDATA/Godot/")) From f320e02427f3c9bf37d060b02356e68399f49db0 Mon Sep 17 00:00:00 2001 From: Kato Muso Date: Fri, 6 Dec 2024 23:40:53 +0000 Subject: [PATCH 5/5] Add docstring for gdscript-eglot--extract-port function --- gdscript-eglot.el | 1 + 1 file changed, 1 insertion(+) diff --git a/gdscript-eglot.el b/gdscript-eglot.el index 7b2a097..02a9265 100644 --- a/gdscript-eglot.el +++ b/gdscript-eglot.el @@ -52,6 +52,7 @@ "godot")))) (defun gdscript-eglot--extract-port (editor-settings-file) + "Extract LSP port from Godot editor settings file." (when (file-exists-p editor-settings-file) (with-temp-buffer (insert-file-contents editor-settings-file)