From d441f3d268a31a4a514af2db506a5eec47ee617d Mon Sep 17 00:00:00 2001 From: Marie Katrine Ekeberg Date: Mon, 20 Nov 2023 16:19:41 +0100 Subject: [PATCH] Add interactive function for viewing wgsl syntax tree (#4242) --- clients/lsp-wgsl.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/clients/lsp-wgsl.el b/clients/lsp-wgsl.el index 885a3c98d2..a0a9864252 100644 --- a/clients/lsp-wgsl.el +++ b/clients/lsp-wgsl.el @@ -149,6 +149,23 @@ (font-lock-mode)) (switch-to-buffer buffer))))) +(defun lsp-wgsl-syntax-tree () + "Gets the syntax tree of the current buffer." + (interactive) + (lsp-request-async + "wgsl-analyzer/syntaxTree" + (list :textDocument (list :uri (lsp--buffer-uri)) + :range (if (use-region-p) + (lsp--region-to-range (region-beginning) (region-end)) + (lsp--region-to-range (point-min) (point-max)))) + (lambda (syntax-tree) + (let ((buffer (get-buffer-create (format "*WGSL-syntax-tree %s*" (lsp--buffer-uri))))) + (with-current-buffer buffer + (setq-local buffer-read-only nil) + (erase-buffer) + (insert syntax-tree) + (read-only-mode)) + (switch-to-buffer buffer))))) (lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection