mirror of
https://github.com/godotengine/emacs-gdscript-mode.git
synced 2025-12-31 21:48:34 +03:00
Compare commits
29 Commits
jcs090218-
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79739fc80f | ||
|
|
9822c8a921 | ||
|
|
e94dfd9dc7 | ||
|
|
e3b47496a3 | ||
|
|
bd0a741066 | ||
|
|
a0d25b46d8 | ||
|
|
2afbcecdd2 | ||
|
|
5136be407a | ||
|
|
1938aa7e2d | ||
|
|
3f3739dd88 | ||
|
|
17c270190b | ||
|
|
e18cf2cea3 | ||
|
|
f195ca86f8 | ||
|
|
703c776260 | ||
|
|
d83b971e20 | ||
|
|
208e231138 | ||
|
|
707e77ded3 | ||
|
|
c3d9988984 | ||
|
|
f320e02427 | ||
|
|
88f6bca508 | ||
|
|
686feebf2d | ||
|
|
f8fce3ad1a | ||
|
|
3052839d71 | ||
|
|
bee7f99c6f | ||
|
|
d1076e1b59 | ||
|
|
52b3637df8 | ||
|
|
21be7cd6d3 | ||
|
|
b03647b62e | ||
|
|
e0c8700d25 |
6
.github/dependabot.yml
vendored
Normal file
6
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
schedule:
|
||||
interval: daily
|
||||
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@@ -23,6 +23,7 @@ jobs:
|
||||
- 27.2
|
||||
- 28.2
|
||||
- 29.4
|
||||
- 30.2
|
||||
experimental: [false]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
@@ -41,7 +42,7 @@ jobs:
|
||||
emacs-version: 27.2
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: jcs090218/setup-emacs@master
|
||||
with:
|
||||
|
||||
2
Eask
2
Eask
@@ -1,3 +1,5 @@
|
||||
;; -*- mode: eask; lexical-binding: t -*-
|
||||
|
||||
(package "gdscript-mode"
|
||||
"0.1.0"
|
||||
"Major mode for Godot's GDScript language")
|
||||
|
||||
@@ -231,7 +231,7 @@ To support Gdscript, we must install [gdscript-grammar](https://github.com/Prest
|
||||
git clone https://github.com/PrestonKnopp/tree-sitter-gdscript.git
|
||||
cd tree-sitter-gdscript/src
|
||||
cc -std=c99 -c parser.c
|
||||
cc -c scanner.cc
|
||||
cc -c scanner.c -I./
|
||||
cc -shared parser.o scanner.o -o libtree-sitter-gdscript.so
|
||||
```
|
||||
|
||||
|
||||
@@ -38,9 +38,41 @@
|
||||
:group 'gdscript)
|
||||
|
||||
;;;###autoload
|
||||
(defcustom gdscript-eglot-version 4
|
||||
(defcustom gdscript-eglot-version "4.5"
|
||||
"The version of godot in use."
|
||||
:type 'integer)
|
||||
: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 (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") (expand-file-name "~/.config"))
|
||||
"godot"))))
|
||||
|
||||
(defun gdscript-eglot--extract-port (editor-settings-file)
|
||||
"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)
|
||||
@@ -52,30 +84,12 @@ 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 (or (getenv "XDG_CONFIG_HOME")
|
||||
(pcase system-type
|
||||
('darwin "~/Library/Application Support/Godot/")
|
||||
('windows-nt "%APPDATA%\\Godot\\")
|
||||
('gnu/linux "~/.config/"))))
|
||||
(cfg-buffer
|
||||
(find-file-noselect
|
||||
(expand-file-name
|
||||
(format "godot/editor_settings-%d.tres"
|
||||
gdscript-eglot-version)
|
||||
cfg-dir)))
|
||||
(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 (gdscript-eglot--get-config-dir))
|
||||
(settings-file (file-name-concat
|
||||
config-dir
|
||||
(format "editor_settings-%s.tres" gdscript-eglot-version))))
|
||||
(when-let* ((port (gdscript-eglot--extract-port settings-file)))
|
||||
(list "localhost" port)))))
|
||||
|
||||
(provide 'gdscript-eglot)
|
||||
;;; gdscript-eglot.el ends here.
|
||||
|
||||
@@ -68,64 +68,121 @@ It must be a function with two arguments: TYPE and NAME.")
|
||||
(if (string= type "class")
|
||||
"*class definition*"
|
||||
"*function definition*"))
|
||||
|
||||
|
||||
;;; Keywords
|
||||
|
||||
(defvar gdscript-ts--treesit-keywords '("and" "as" "break" "class" "class_name"
|
||||
"const" "continue" "elif" "else" "enum" "export" "extends" "for" "func" "if" "in" "is"
|
||||
"master" "match" "not" "onready" "or" "pass" "puppet" "remote" "remotesync" "return" "setget" "signal"
|
||||
"var" "while"))
|
||||
(defvar gdscript-ts--keyword-regex
|
||||
(rx bot (| "func" "var" "const" "set" "get" "setget" "signal" "extends"
|
||||
"match" "if" "elif" "else" "for" "in" "while" "break" "continue"
|
||||
"pass" "return" "when" "yield" "await"
|
||||
"class" "class_name" "abstract" "is" "onready" "tool" "static"
|
||||
"export" "as" "void" "enum" "assert" "breakpoint"
|
||||
"sync" "remote" "master" "puppet"
|
||||
"remotesync" "mastersync" "puppetsync"
|
||||
"trait" "namespace" "super"
|
||||
"and" "or" "not"
|
||||
"await" "yield" "self") eot))
|
||||
|
||||
;;; Types
|
||||
|
||||
(defvar gdscript-ts--builtin-type-regex
|
||||
"\\`\\(int\\|bool\\|float\\|void\\|Vector2\\|Vector2i\\|Vector3\\|Vector3i\\|Vector4\\|Vector4i\\|Color\\|Rect2\\|Rect2i\\|Array\\|Basis\\|Dictionary\\|Plane\\|Quat\\|RID\\|Rect3\\|Transform\\|Transform2D\\|Transform3D\\|AABB\\|String\\|Color\\|NodePath\\|PoolByteArray\\|PoolIntArray\\|PoolRealArray\\|PoolStringArray\\|PoolVector2Array\\|PoolVector3Array\\|PoolColorArray\\|bool\\|int\\|float\\|Signal\\|Callable\\|StringName\\|Quaternion\\|Projection\\|PackedByteArray\\|PackedInt32Array\\|PackedInt64Array\\|PackedFloat32Array\\|PackedFloat64Array\\|PackedStringArray\\|PackedVector2Array\\|PackedVector2iArray\\|PackedVector3Array\\|PackedVector3iArray\\|PackedVector4Array\\|PackedColorArray\\|JSON\\|UPNP\\|OS\\|IP\\|JSONRPC\\|XRVRS\\)\\'")
|
||||
|
||||
(defvar gdscript-ts--type-regex
|
||||
"\\`[A-Z][a-zA-Z0-9_]*[a-z][a-zA-Z0-9_]*\\'")
|
||||
|
||||
;;; Constants
|
||||
|
||||
(defvar gdscript-ts--constant-regex "\\`[A-Z_][A-Z0-9_]+\\'")
|
||||
|
||||
|
||||
;;; Setting
|
||||
|
||||
(defvar gdscript-ts--feature-list
|
||||
'(( comment definition)
|
||||
( keyword string type annotation)
|
||||
( number constant escape-sequence)
|
||||
( bracket delimiter function operator property)))
|
||||
|
||||
(defvar gdscript-ts--treesit-settings
|
||||
(treesit-font-lock-rules
|
||||
:language 'gdscript
|
||||
:feature 'comment
|
||||
'((comment) @font-lock-comment-face)
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'constant
|
||||
`(([(null) (false) (true)] @font-lock-constant-face)
|
||||
(const_statement name: (name) @font-lock-constant-face)
|
||||
(enumerator left: (identifier) @font-lock-constant-face)
|
||||
((identifier) @font-lock-constant-face
|
||||
(:match ,gdscript-ts--constant-regex @font-lock-constant-face))
|
||||
(variable_statement
|
||||
name: (name) @font-lock-constant-face
|
||||
(:match ,gdscript-ts--constant-regex @font-lock-constant-face)))
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'bracket
|
||||
`(["[" "]" "(" ")" "{" "}"] @font-lock-bracket-face)
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'delimiter
|
||||
`(["," ":" "."] @font-lock-delimiter-face)
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'type
|
||||
`(((identifier) @font-lock-builtin-face
|
||||
(:match ,gdscript-ts--builtin-type-regex @font-lock-builtin-face))
|
||||
(get_node) @font-lock-builtin-face
|
||||
((identifier) @font-lock-type-face
|
||||
(:match ,gdscript-ts--type-regex @font-lock-type-face))
|
||||
(enum_definition name: (_) @font-lock-type-face)
|
||||
(class_name_statement (name) @font-lock-type-face)
|
||||
(class_definition (name) @font-lock-type-face))
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'definition
|
||||
'((function_definition (name) @font-lock-function-name-face)
|
||||
(class_definition
|
||||
(name) @font-lock-function-name-face)
|
||||
(parameters (identifier) @font-lock-variable-name-face))
|
||||
'((function_definition (name) @font-lock-function-name-face))
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'annotation
|
||||
'((annotation "@" @font-lock-preprocessor-face
|
||||
(identifier) @font-lock-preprocessor-face))
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'keyword
|
||||
`(([,@gdscript-ts--treesit-keywords] @font-lock-keyword-face)
|
||||
([(false) (true)] @font-lock-keyword-face))
|
||||
`((ERROR _ @font-lock-keyword-face (:match ,gdscript-ts--keyword-regex @font-lock-keyword-face))
|
||||
(_ _ @font-lock-keyword-face (:match ,gdscript-ts--keyword-regex @font-lock-keyword-face)))
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'string
|
||||
'((string) @font-lock-string-face)
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'type
|
||||
'(((type) @font-lock-type-face)
|
||||
(get_node) @font-lock-type-face)
|
||||
|
||||
:feature 'function
|
||||
:language 'gdscript
|
||||
'((call (identifier) @font-lock-function-call-face)
|
||||
'((call (identifier) @font-lock-builtin-face (:match "preload" @font-lock-builtin-face))
|
||||
(call (identifier) @font-lock-function-call-face)
|
||||
(attribute_call (identifier) @font-lock-function-call-face))
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'variable
|
||||
'((_ (name) @font-lock-variable-name-face))
|
||||
|
||||
:feature 'number
|
||||
:language 'gdscript
|
||||
'(([(integer) (float)] @font-lock-number-face))
|
||||
|
||||
:feature 'property
|
||||
:language 'gdscript
|
||||
:feature 'property
|
||||
'((attribute (identifier) (identifier) @font-lock-property-use-face))
|
||||
|
||||
:feature 'operator
|
||||
:language 'gdscript
|
||||
`(["+" "-" "*" "/" "^" ">" "<" "="] @font-lock-operator-face)))
|
||||
`(["+" "+=" "-" "-=" "*" "*=" "/" "/=" "^" "^=" ">" ">="
|
||||
"<" "<=" "|" "|=" "%" "%=" "&" "&=" ">>" ">>=" "<<" "<<="
|
||||
"||" "&&" "==" "!=" "->" "~" "=" ":="]
|
||||
@font-lock-operator-face)
|
||||
|
||||
:language 'gdscript
|
||||
:override t
|
||||
:feature 'escape-sequence
|
||||
'((escape_sequence) @font-lock-escape-face)))
|
||||
|
||||
|
||||
;;; Funtion
|
||||
@@ -220,10 +277,7 @@ Similar to `gdscript-imenu-create-index' but use tree-sitter."
|
||||
:syntax-table gdscript-mode-syntax-table
|
||||
(when (treesit-ready-p 'gdscript)
|
||||
(treesit-parser-create 'gdscript)
|
||||
(setq-local treesit-font-lock-feature-list
|
||||
'(( comment definition)
|
||||
( keyword string type)
|
||||
( function variable number property operator)))
|
||||
(setq-local treesit-font-lock-feature-list gdscript-ts--feature-list)
|
||||
(setq-local treesit-font-lock-settings gdscript-ts--treesit-settings)
|
||||
;;; TODO: create-imenu
|
||||
(setq-local imenu-create-index-function
|
||||
|
||||
Reference in New Issue
Block a user