3838 :group 'gdscript )
3939
4040;;;### autoload
41- (defcustom gdscript-eglot-version " 4.3 "
41+ (defcustom gdscript-eglot-version " 4.5 "
4242 " The version of godot in use."
4343 :type 'string )
4444
45+ ;;;### autoload
46+ (defcustom gdscript-eglot-default-lsp-port 6005
47+ " The default port for eglot to connect when extraction fails."
48+ :type 'integer
49+ :group 'gdscript-eglot )
50+
4551(defun gdscript-eglot--get-config-dir ()
4652 " Get system-specific directory with Godot configuration files."
4753 (pcase system-type
48- ('darwin " ~/Library/Application Support/Godot/" )
49- ('windows-nt (substitute-in- file-name " $ APPDATA/ Godot/ " ))
54+ ('darwin ( expand-file-name " ~/Library/Application Support/Godot/" ) )
55+ ('windows-nt (file-name-concat ( getenv " APPDATA" ) " Godot" ))
5056 ('gnu/linux (file-name-concat
51- (or (getenv " XDG_CONFIG_HOME" ) " ~/.config/ " )
57+ (or (getenv " XDG_CONFIG_HOME" ) ( expand-file-name " ~/.config" ) )
5258 " godot" ))))
5359
5460(defun gdscript-eglot--extract-port (editor-settings-file )
55- " Extract LSP port from Godot editor settings file."
56- (when (file-exists-p editor-settings-file)
57- (with-temp-buffer
58- (insert-file-contents editor-settings-file)
59- (when (re-search-forward
60- (rx " network/language_server/remote_port"
61- (* space) ?= (* space)
62- (group (+ digit)))
63- nil t )
64- (string-to-number (match-string 1 ))))))
61+ " Extract LSP port from Godot EDITOR-SETTINGS-FILE.
62+ If extraction fails, return `gdscript-eglot-default-port' .
63+ NOTE: remote_port value only presents if it has been modified from the default value,
64+ So this extract shall fail by default."
65+ (or
66+ (when (file-exists-p editor-settings-file)
67+ (with-temp-buffer
68+ (insert-file-contents editor-settings-file)
69+ (when (re-search-forward
70+ (rx " network/language_server/remote_port"
71+ (* space) ?= (* space)
72+ (group (+ digit)))
73+ nil t )
74+ (string-to-number (match-string 1 )))))
75+ gdscript-eglot-default-lsp-port))
6576
6677;;;### autoload
6778(defun gdscript-eglot-contact (_interactive )
@@ -77,7 +88,7 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-04/msg01070.html."
7788 (settings-file (file-name-concat
7889 config-dir
7990 (format " editor_settings-%s .tres " gdscript-eglot-version))))
80- (when-let ((port (gdscript-eglot--extract-port settings-file)))
91+ (when-let* ((port (gdscript-eglot--extract-port settings-file)))
8192 (list " localhost" port)))))
8293
8394(provide 'gdscript-eglot )
0 commit comments