From e3b47496a30e933c3312926eb3fbf2228ea94c4d Mon Sep 17 00:00:00 2001 From: passky Date: Sun, 5 Oct 2025 00:37:41 +0800 Subject: [PATCH] fix: add default value for eglot lsp port extraction as fallback See #169: "network/language_server/remote_port" only presents in settings file when it has been modified from the default value from later version of godot. So it always fail to extraction and return nothing,we can fix that by add a default value. Also: bump gdscript-eglot-version to 4.5 --- gdscript-eglot.el | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/gdscript-eglot.el b/gdscript-eglot.el index 02a9265..b10a1f3 100644 --- a/gdscript-eglot.el +++ b/gdscript-eglot.el @@ -38,30 +38,41 @@ :group 'gdscript) ;;;###autoload -(defcustom gdscript-eglot-version "4.3" +(defcustom gdscript-eglot-version "4.5" "The version of godot in use." :type 'string) +;;;###autoload +(defcustom gdscript-eglot-default-lsp-port 6005 + "The default port for eglot to connect when extraction fails." + :type 'integer + :group 'gdscript-eglot) + (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/")) + ('darwin (expand-file-name "~/Library/Application Support/Godot/")) + ('windows-nt (file-name-concat (getenv "APPDATA") "Godot")) ('gnu/linux (file-name-concat - (or (getenv "XDG_CONFIG_HOME") "~/.config/") + (or (getenv "XDG_CONFIG_HOME") (expand-file-name "~/.config")) "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) - (when (re-search-forward - (rx "network/language_server/remote_port" - (* space) ?= (* space) - (group (+ digit))) - nil t) - (string-to-number (match-string 1)))))) + "Extract LSP port from Godot EDITOR-SETTINGS-FILE. +If extraction fails, return `gdscript-eglot-default-port'. +NOTE: remote_port value only presents if it has been modified from the default value, +So this extract shall fail by default." + (or + (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))))) + gdscript-eglot-default-lsp-port)) ;;;###autoload (defun gdscript-eglot-contact (_interactive) @@ -77,7 +88,7 @@ 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-let ((port (gdscript-eglot--extract-port settings-file))) + (when-let* ((port (gdscript-eglot--extract-port settings-file))) (list "localhost" port))))) (provide 'gdscript-eglot)