Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 8c57bcf
Author: Marie Katrine Ekeberg <mke@themkat.net>
Date:   Tue Nov 7 11:52:54 2023 +0100

    Add missing mkdocs entry

commit 253ef1f
Author: Marie Katrine Ekeberg <mke@themkat.net>
Date:   Tue Nov 7 11:51:01 2023 +0100

    Add lsp-clients docs entry

commit 8a0b65d
Author: Marie Katrine Ekeberg <mke@themkat.net>
Date:   Fri Nov 3 18:46:22 2023 +0100

    Add changelog entry for wgsl-analyzer

commit 7627a27
Author: Marie Katrine Ekeberg <mke@themkat.net>
Date:   Fri Nov 3 18:44:49 2023 +0100

    Commented out non-working config paameter

commit f9b27f5
Author: Marie Katrine Ekeberg <mke@themkat.net>
Date:   Fri Nov 3 18:05:31 2023 +0100

    Added the rest of the configuration properties

commit 70cb86e
Author: Marie Katrine Ekeberg <mke@themkat.net>
Date:   Fri Nov 3 17:46:57 2023 +0100

    Sending configuration now finally works

commit 52811aa
Author: Marie Katrine Ekeberg <mke@themkat.net>
Date:   Wed Oct 18 14:21:52 2023 +0200

    Add function to execute the lsp extension full source

commit 71bbf89
Author: Marie Katrine Ekeberg <mke@themkat.net>
Date:   Mon Oct 16 16:48:44 2023 +0200

    Add barebones wgsl-analyzer support
  • Loading branch information
yyoncho committed Nov 11, 2023
1 parent 8cc035e commit f8727d3
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Add Mojo 🔥 support
* Add lsp-solidity, using the implementation from NomicFoundation
* Change rust-analyzer base URL to be github.com/rust-lang/rust-analyzer, rather than rust-analyzer/rust-analyzer.
* Add support for wgsl using [[https://github.com/wgsl-analyzer/wgsl-analyzer][wgsl-analyzer]]
* Add [[https://github.com/wader/jq-lsp][jq-lsp]]
* Add architecture triples for [[https://github.com/WhatsApp/erlang-language-platform][erlang-language-platform]] file downloads, to support macos on ARM and X86.
* Add semantic token support for [[https://github.com/WhatsApp/erlang-language-platform][erlang-language-platform]] in lsp-erlang client.
Expand Down
170 changes: 170 additions & 0 deletions clients/lsp-wgsl.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
;;; lsp-wgsl.el --- description -*- lexical-binding: t; -*-

;; Copyright (C) 2023 emacs-lsp maintainers

;; Author: emacs-lsp maintainers
;; Keywords: lsp, wgsl, shaders, graphics programming,

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; LSP Clients for WGSL (WebGPU Shading Language).

;;; Code:

(defgroup lsp-wgsl nil
"LSP support for wgsl, using wgsl-analyzer."
:group 'lsp-mode
:link '(url-link "https://github.com/wgsl-analyzer/wgsl-analyzer")
:package-version '(lsp-mode . "8.0.1"))


(defcustom lsp-wgsl-server-command "wgsl_analyzer"
"Command to run the wgsl-analyzer executable."
:type 'boolean
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

;; Various toggling settings for the lsp server
(defcustom lsp-wgsl-diagnostics-type-errors t
"Whether to show type errors in diagnostics or not."
:type 'boolean
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

(defcustom lsp-wgsl-diagnostics-naga-parsing-errors t
"Whether to show naga parsing errors in diagnostics or not."
:type 'boolean
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

(defcustom lsp-wgsl-diagnostics-naga-validation-errors t
"Whether to show naga validation errors in diagnostics or not."
:type 'boolean
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

(defcustom lsp-wgsl-diagnostics-naga-version "main"
"Naga version to use."
:type 'string
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

(defcustom lsp-wgsl-inlayhints-enabled t
"Whether to enable inlay hints or not."
:type 'boolean
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

(defcustom lsp-wgsl-inlayhints-typehints t
"Whether to enable type hints or not when using inlay hints."
:type 'boolean
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

(defcustom lsp-wgsl-inlayhints-parameterhints t
"Whether to enable parameter hints or not when using inlay hints."
:type 'boolean
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

(defcustom lsp-wgsl-inlayhints-structlayout t
"Whether to enable struct layout hints or not when using inlay hints."
:type 'boolean
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

;; TODO: maybe type choice instead?
(defcustom lsp-wgsl-inlayhints-type-verbosity "compact"
"The type verbosity to use for inlay hints."
:type '(choice (string "full")
(string "compact")
(string "inner"))
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

(defcustom lsp-wgsl-custom-imports (lsp-ht)
"List of custom imports in the style of Bevy"
:type 'ht
:group 'lsp-wgsl
:package-version '(lsp-mode . "8.0.1"))

;; (defcustom lsp-wgsl-shaderdefs []
;; "Defines that should be valid for preprocessor operations like ifdef."
;; :type 'vector
;; :group 'lsp-wgsl
;; :package-version '(lsp-mode . "8.0.1"))

;; wgsl-analyzer is a bit weird with how it gets config.
;; Currently it relies on a custom extension to query the clients.
;; (could not get standard custom-settings blocks to work)
(defun lsp-wgsl--send-configuration (&rest _)
;; TODO: why doesnt this behave like the normal lists?!?!? I cant just send a list?!?!?! why the fuck?!?!
(list :customImports lsp-wgsl-custom-imports
:diagnostics (list :typeErrors (lsp-json-bool lsp-wgsl-diagnostics-type-errors)
:nagaParsingErrors (lsp-json-bool lsp-wgsl-diagnostics-naga-parsing-errors)
:nagaValidationErrors (lsp-json-bool lsp-wgsl-diagnostics-naga-validation-errors)
:nagaVersion lsp-wgsl-diagnostics-naga-version)
:inlayHints (list :enabled (lsp-json-bool lsp-wgsl-inlayhints-enabled)
:typeHints (lsp-json-bool lsp-wgsl-inlayhints-typehints)
:parameterHints (lsp-json-bool lsp-wgsl-inlayhints-parameterhints)
:structLayoutHints (lsp-json-bool lsp-wgsl-inlayhints-structlayout)
:typeVerbosity lsp-wgsl-inlayhints-type-verbosity)
:shaderDefs []
;; not configurable at the moment, as they don't seem to have much effect.
;; Fails if not given.
:trace (list :extension t
:server t)))


;; Various interactive functions to use the custom LSP extensions from the server
(defun lsp-wgsl-full-source ()
"Gets the full source of the file with all imports and preprocessor definitions resolved."
(interactive)
(lsp-request-async
"wgsl-analyzer/fullSource"
(list :textDocument (list :uri (lsp--buffer-uri)))
(lambda (source)
(let ((buffer (get-buffer-create "*WGSL-full-source*")))
(with-current-buffer buffer
(setq-local buffer-read-only nil)
(erase-buffer)
(insert source)
(read-only-mode)
;; activate only syntax highlighting
(font-lock-add-keywords nil wgsl-font-lock-keywords)
(font-lock-mode))
(switch-to-buffer buffer)))))


(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection
(lambda ()
lsp-wgsl-server-command))
:initialized-fn (lambda (workspace)
(with-lsp-workspace workspace
;; wgsl-analyzer handles configuration in a VERY non-standard way
;; https://github.com/wgsl-analyzer/wgsl-analyzer/issues/77
(lsp--set-configuration '())))
:request-handlers (lsp-ht ("wgsl-analyzer/requestConfiguration" #'lsp-wgsl--send-configuration))
:activation-fn (lsp-activate-on "wgsl")
:priority -1
:server-id 'wgsl-analyzer))


(lsp-consistency-check lsp-wgsl)

(provide 'lsp-wgsl)
;;; lsp-wgsl.el ends here
8 changes: 8 additions & 0 deletions docs/lsp-clients.json
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,14 @@
"lsp-install-server": "vue-semantic-server",
"debugger": "Not available"
},
{
"name": "wgsl-analyzer",
"full-name": "wgsl",
"server-name": "wgsl-analyzer",
"server-url": "https://github.com/wgsl-analyzer/wgsl-analyzer",
"installation": "cargo install --git https://github.com/wgsl-analyzer/wgsl-analyzer wgsl_analyzer",
"debugger": "Not available"
},
{
"name": "xml",
"full-name": "XML",
Expand Down
1 change: 1 addition & 0 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ Changes take effect only when a new session is started."
(rst-mode . "restructuredtext")
(glsl-mode . "glsl")
(shader-mode . "shaderlab")
(wgsl-mode . "wgsl")
(jq-mode . "jq")
(jq-ts-mode . "jq"))
"Language id configuration.")
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ nav:
- Vimscript: page/lsp-vimscript.md
- Vue 2: page/lsp-vetur.md
- Vue 3: page/lsp-volar.md
- wgsl: page/lsp-wgsl.md
- XML: page/lsp-xml.md
- YAML: page/lsp-yaml.md
- Zig: page/lsp-zig.md
Expand Down

0 comments on commit f8727d3

Please sign in to comment.