42
42
" The version of godot in use."
43
43
:type 'string )
44
44
45
+ (defun gdscript-eglot--get-config-dir ()
46
+ " Get system-specific directory with Godot configuration files."
47
+ (pcase system-type
48
+ ('darwin " ~/Library/Application Support/Godot/" )
49
+ ('windows-nt (substitute-in-file-name " $APPDATA/Godot/" ))
50
+ ('gnu/linux (file-name-concat
51
+ (or (getenv " XDG_CONFIG_HOME" ) " ~/.config/" )
52
+ " godot" ))))
53
+
54
+ (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 ))))))
65
+
45
66
;;;### autoload
46
67
(defun gdscript-eglot-contact (_interactive )
47
68
" Attempt to help `eglot' contact the running gdscript LSP.
@@ -52,30 +73,12 @@ definitions of HOST, PORT, and INTERACTIVE.
52
73
For more context, see
53
74
https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-04/msg01070.html."
54
75
(save-excursion
55
- (let* ((cfg-dir (pcase system-type
56
- ('darwin " ~/Library/Application Support/Godot/" )
57
- ('windows-nt (substitute-in-file-name " $APPDATA/Godot/" ))
58
- ('gnu/linux (file-name-concat
59
- (or (getenv " XDG_CONFIG_HOME" ) " ~/.config/" )
60
- " godot" ))))
61
- (cfg-buffer (find-file-noselect
62
- (file-name-concat
63
- cfg-dir
64
- (format " editor_settings-%s .tres "
65
- gdscript-eglot-version))))
66
- (port
67
- (with-current-buffer cfg-buffer
68
- (goto-char 0 )
69
- (and
70
- (re-search-forward
71
- (rx " network/language_server/remote_port"
72
- (* space) ?= (* space)
73
- (group (+ digit)))
74
- nil t )
75
- (string-to-number (match-string 1 ))))))
76
- (kill-buffer cfg-buffer)
77
- ; ; then return the host-port list when found
78
- (and port (list " localhost" port)))))
76
+ (let* ((config-dir (gdscript-eglot--get-config-dir))
77
+ (settings-file (file-name-concat
78
+ config-dir
79
+ (format " editor_settings-%s .tres " gdscript-eglot-version))))
80
+ (when-let ((port (gdscript-eglot--extract-port settings-file)))
81
+ (list " localhost" port)))))
79
82
80
83
(provide 'gdscript-eglot )
81
84
; ;; gdscript-eglot.el ends here.
0 commit comments