Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for local queries #107

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions langs/tree-sitter-langs-build.el
Original file line number Diff line number Diff line change
Expand Up @@ -353,28 +353,23 @@ non-nil."
(dired-omit-mode -1)))))))

(defun tree-sitter-langs--copy-query (lang-symbol &optional force)
"Copy highlights.scm file of LANG-SYMBOL to `tree-sitter-langs--queries-dir'.
"Copy all quries files of LANG-SYMBOL to `tree-sitter-langs--queries-dir'.
This assumes the repo has already been set up, for example by
`tree-sitter-langs-compile'."
(let ((src (thread-first tree-sitter-langs--repos-dir
(concat (format "tree-sitter-%s" lang-symbol))
file-name-as-directory (concat "queries")
file-name-as-directory (concat "highlights.scm"))))
(when (file-exists-p src)
(let ((dst-dir (file-name-as-directory
(concat tree-sitter-langs--queries-dir
(symbol-name lang-symbol)))))
(unless (file-directory-p dst-dir)
(make-directory dst-dir t))
(message "Copying highlights.scm for %s" lang-symbol)
(let ((default-directory dst-dir))
(if (file-exists-p "highlights.scm")
(when force
(copy-file src dst-dir :force))
(copy-file src dst-dir)))))))
file-name-as-directory (concat "queries"))))
(when (file-directory-p src)
(let ((dst-dir (file-name-as-directory
(concat tree-sitter-langs--queries-dir
(symbol-name lang-symbol)))))
(message "Copying queries for %s" lang-symbol)
(when (and force (file-directory-p dst-dir))
(delete-directory dst-dir t))
(copy-directory src dst-dir nil t t)))))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local query seems located in locals.scm and not highlight.scm.

Do you think we can just pull the entire query files down?


(defun tree-sitter-langs--copy-queries ()
"Copy highlights.scm files to `tree-sitter-langs--queries-dir'.
"Copy query files to `tree-sitter-langs--queries-dir'.
This assumes the repos have already been cloned set up, for example by
`tree-sitter-langs-create-bundle'."
(pcase-dolist (`(,lang-symbol . _) tree-sitter-langs-repos)
Expand Down
13 changes: 7 additions & 6 deletions langs/tree-sitter-langs.el
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ See `tree-sitter-langs-repos'."

(defun tree-sitter-langs--hl-query-path (lang-symbol)
(concat (file-name-as-directory
(concat tree-sitter-langs--queries-dir
(symbol-name lang-symbol)))
"highlights.scm"))
(concat tree-sitter-langs--queries-dir (symbol-name lang-symbol)))))

(defun tree-sitter-langs--hl-default-patterns (lang-symbol)
"Return the bundled default syntax highlighting patterns for LANG-SYMBOL.
Expand All @@ -125,9 +123,12 @@ Return nil if there are no bundled patterns."
('cpp '(c))
('typescript '(javascript))
(_ nil))))
(insert-file-contents (tree-sitter-langs--hl-query-path sym))
(goto-char (point-max))
(insert "\n"))
(let* ((path (tree-sitter-langs--hl-query-path sym))
(quries (directory-files path t "\\.scm$")))
(dolist (query quries)
(insert-file-contents query)
(goto-char (point-max))
(insert "\n"))))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Load all quires at a time.

(buffer-string))
(file-missing nil)))

Expand Down
18 changes: 18 additions & 0 deletions lisp/tree-sitter-hl.el
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,24 @@
"Face for property declarations and definitions."
:group 'tree-sitter-hl-faces)

;;; ------------------------------------
;;; Local

(defface tree-sitter-hl-face:local.scope
'((default :inherit font-lock-variable-name-face))
"Face for new local scope."
:group 'tree-sitter-hl-faces)

(defface tree-sitter-hl-face:local.definition
'((default :inherit font-lock-variable-name-face))
"Face for local definition."
:group 'tree-sitter-hl-faces)

(defface tree-sitter-hl-face:local.reference
'((default :inherit font-lock-variable-name-face))
"Face for new local reference."
:group 'tree-sitter-hl-faces)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are listed here.


;;; ------------------------------------
;;; Strings, comments, text proses.

Expand Down