[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/graphql-mode 8a4a5fae69 015/122: Fontify field arguments a
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/graphql-mode 8a4a5fae69 015/122: Fontify field arguments as variable names |
Date: |
Sat, 29 Jan 2022 08:03:29 -0500 (EST) |
branch: elpa/graphql-mode
commit 8a4a5fae690338f504468d0f8fc3e2c9f041d89f
Author: David Vazquez Pua <davazp@gmail.com>
Commit: David Vazquez Pua <davazp@gmail.com>
Fontify field arguments as variable names
---
graphql.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 48 insertions(+), 9 deletions(-)
diff --git a/graphql.el b/graphql.el
index f4ba3b72a8..b6d129c1d8 100644
--- a/graphql.el
+++ b/graphql.el
@@ -75,7 +75,7 @@ response from the server."
(setq graphql-url (read-string "GraphQL URL: " )))
(let* ((query (graphql-current-query))
(response (graphql--query query)))
- (with-current-buffer-window
+ (with-current-buffer-window
"*GraphQL*" 'display-buffer-pop-up-window nil
(erase-buffer)
(json-mode)
@@ -123,6 +123,37 @@ response from the server."
(defvar graphql-constants
'("true" "false" "null"))
+
+;;; Check if the point is in an argument list.
+(defun graphql--in-arguments-p ()
+ (let ((opening (second (syntax-ppss))))
+ (eql (char-after opening) ?\()))
+
+
+(defun graphql--field-parameter-matcher (limit)
+ (catch 'end
+ (while t
+ (cond
+ ;; If we are inside an argument list, try to match the first
+ ;; argument that we find or exit the argument list otherwise, so
+ ;; the search can continue.
+ ((graphql--in-arguments-p)
+ (let* ((end (save-excursion (up-list) (point)))
+ (match (search-forward-regexp "\\(\\w+\\):" end t)))
+ (if match
+ ;; unless we are inside a string or comment
+ (let ((state (syntax-ppss)))
+ (when (not (or (nth 3 state)
+ (nth 4 state)))
+ (throw 'end t)))
+ (up-list))))
+ (t
+ ;; If we are not inside an argument list, jump after the next
+ ;; opening parenthesis, and we will try again there.
+ (skip-syntax-forward "^(" limit)
+ (forward-char))))))
+
+
(defvar graphql-font-lock-keywords
`(
;; Type definition
@@ -141,12 +172,20 @@ response from the server."
;; Constants
(,(regexp-opt graphql-constants) . font-lock-constant-face)
- ;; Built-in scalar types
- (,(regexp-opt graphql-builtin-types) . font-lock-type-face)
+
+ ;; Variables
+ ("\\$\\w+" . font-lock-variable-name-face)
+
+ ;; Types
+ (":[[:space:]]*\\[?\\(\\w+\\)\\]?"
+ (1 font-lock-type-face))
+
;; Directives
("@\\w+" . font-lock-keyword-face)
- ;; Variables
- ("\\$\\w+" . font-lock-variable-name-face)))
+
+ ;; Field parameters
+ (graphql--field-parameter-matcher
+ (1 font-lock-variable-name-face))))
(define-derived-mode graphql-mode prog-mode "GraphQL"
@@ -156,10 +195,10 @@ response from the server."
(setq-local comment-start-skip "#+[\t ]*")
(setq-local indent-line-function 'graphql-indent-line)
(setq font-lock-defaults
- (list 'graphql-font-lock-keywords
- nil
- nil
- nil))
+ `(graphql-font-lock-keywords
+ nil
+ nil
+ nil))
(setq imenu-generic-expression
`((nil ,graphql-definition-regex 2))))
- [nongnu] elpa/graphql-mode 0e723b962e 107/122: Factor in quitting function, (continued)
- [nongnu] elpa/graphql-mode 0e723b962e 107/122: Factor in quitting function, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 18f749c1bc 106/122: Simplify buffer naming, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 1b78d07aee 092/122: declare request-response--raw-header function, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 9740e4027b 122/122: Merge pull request #45 from LaurenceWarne/parameter-fontlock-fix, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode d9fa01b446 004/122: Improve highlight of definitions, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 347431ce18 007/122: Fontify fragments, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 836373c72e 010/122: Basic support for imenu, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 497529dd4d 008/122: Fontify query, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 26a5d8a665 043/122: make graphql-current-* function, not command. also graphql-begining-of-variables, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 6e1f5335fa 030/122: Mention json-mode in the README.md, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 8a4a5fae69 015/122: Fontify field arguments as variable names,
ELPA Syncer <=
- [nongnu] elpa/graphql-mode 7798aef2a8 029/122: Fix typo, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 052491e05f 048/122: update variable encoding in post body, ask operation Name if needed, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 83cba48fd8 014/122: Remove unnecessary syntax, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 6017afac92 017/122: Rename graphql.el to graphql-mode.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 7482c1b100 025/122: Add basic commentary, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 36b1a4ed9f 070/122: Merge pull request #16 from emacsjanitors/no-request, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 4b0134a19a 050/122: forget docstring, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 5f2ee4b3b3 024/122: Add melpa badge, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 8e58196e21 023/122: Merge pull request #1 from syohex/fix-package, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 2ee89d4e05 080/122: Fix Error during redisplay, ELPA Syncer, 2022/01/29