Other Editors
wgsl-analyzer works with any editor that supports the Language Server Protocol.
This page assumes that you have already installed the wgsl-analyzer binary.
Emacs (using lsp-mode)
- Assumes you are using
wgsl-mode: https://github.com/acowley/wgsl-mode
Add the following to your init.el
(with-eval-after-load 'lsp-mode
(add-to-list 'lsp-language-id-configuration '(wgsl-mode . "wgsl"))
(lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection "wgsl-analyzer")
:activation-fn (lsp-activate-on "wgsl")
:server-id 'wgsl-analyzer)))
Eglot
Eglot is the more minimalistic and lightweight LSP client for Emacs, integrates well with existing Emacs functionality and is built into Emacs starting from release 29.
After installing Eglot, for example, using M-x package-install (not needed from Emacs 29), you can enable it using the M-x eglot command or load it automatically in wgsl-mode using
(add-hook 'wgsl-mode-hook 'eglot-ensure)
For more detailed instructions and options see the Eglot manual (also available from Emacs using M-x info) and the Eglot readme.
Eglot does not support the wgsl-analyzer extensions to the language-server protocol and does not aim to do so in the future.
The eglot-x package adds experimental support for those LSP extensions.
LSP Mode
LSP-mode is the original LSP-client for emacs. Compared to Eglot it has a larger codebase and supports more features, like LSP protocol extensions. With extension packages like LSP UI it offers a lot of visual eyecandy. Further it integrates well with DAP mode for support of the Debug Adapter Protocol.
You can install LSP-mode using M-x package-install and then run it using the M-x lsp command or load it automatically in WGSL/WESL buffers with
(add-hook 'wgsl-mode-hook 'lsp-deferred)
For more information on how to set up LSP mode and its extension package see the instructions in the LSP mode manual.
Also see the wgsl-analyzer section for wgsl-analyzer specific options and commands, which you can optionally bind to keys.
Vim/Neovim
There are several LSP client implementations for Vim or Neovim:
Using coc-wgsl-analyzer
-
Install coc.nvim by following the instructions at coc.nvim (Node.js required)
-
Run
:CocInstall coc-wgsl-analyzerto installcoc-wgsl-analyzer, this extension implements most of the features supported in the VS Code extension:- automatically install and upgrade stable/nightly releases
- same configurations as VS Code extension. For example,
wgsl-analyzer.server.path. - same commands too,
wgsl-analyzer.analyzerStatus,wgsl-analyzer.ssretc. - inlay hints for variables and method chaining, Neovim Only
Note
coc-wgsl-analyzeris capable of installing or updating thewgsl-analyzerbinary on its own.
Note
for code actions, use
coc-codeaction-cursorandcoc-codeaction-selected;coc-codeactionandcoc-codeaction-lineare unlikely to be useful.
Using LanguageClient-neovim
-
Install LanguageClient-neovim by following the instructions
- The GitHub project wiki has extra tips on configuration
-
Configure by adding this to your Vim/Neovim config file (replacing the existing WGSL or WESL-specific line if it exists):
let g:LanguageClient_serverCommands = { \ 'wgsl': ['wgsl-analyzer'], \ 'wesl': ['wgsl-analyzer'], \ }
Using lsp
-
Configure the
.wgsland.weslfiletypeCreate
/ftdetect/wgsl.luaand/ftdetect/wesl.luain your neovim configuration.vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { pattern = "*.wgsl", command = "setfiletype wgsl" })vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { pattern = "*.wesl", command = "setfiletype wesl" }) -
Configure the nvim lsp
local lspconfig = require('lspconfig') lspconfig.wgsl_analyzer.setup({})
Using lazyVim
-
Create the file
~/.config/nvim/lua/plugins/wgsl.lua:return { { "neovim/nvim-lspconfig", init = function() vim.filetype.add({ extension = { wesl = "wesl", }, }) -- Reuse the wgsl treesitter parser for wesl buffers vim.treesitter.language.register("wgsl", "wesl") end, opts = { servers = { wgsl_analyzer = { filetypes = { "wgsl", "wesl" }, root_markers = { "wesl.toml", ".git" }, single_file_support = true, }, }, }, }, { "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = { "wgsl" } }, }, } -
Reload nvim.
Using coc.nvim
-
open Neovim / Vim and type
:CocConfigto configure coc.nvim. -
under
.languageserver: { ... }create a new field"wgsl-analyzer-language-server". The field should look like this:// { // "languageserver": { "wgsl-analyzer-language-server": { "command": "wgsl-analyzer", // alternatively you can specify the absolute path to your binary. "filetypes": ["wgsl", "wesl"], }, // ... // } -
In order for your editor to recognize WGSL files as such, you need to put this into your
vim.rc" Recognize wgsl au BufNewFile,BufRead *.wgsl set filetype=wgsl
Using nvim-cmp/cmp_nvim_lsp
Requires nvim-cmp and cmp_nvim_lsp.
-
Your existing setup should look similar to this:
local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities()) local lspconfig = require("lspconfig") -
Pass capabilities to the
wgsl-analyzersetup:lspconfig.wgsl_analyzer.setup({ filetypes = { "wgsl", "wesl" }, capabilities = capabilities, })
YouCompleteMe
Install YouCompleteMe by following the instructions.
wgsl-analyzer is the default in ycm, it should work out of the box.
ALE
To use the LSP server in ale:
let g:ale_linters = {'wgsl': ['analyzer'], 'wesl': ['analyzer']}
nvim-lsp
Neovim has built-in support for the Language Server Protocol. Most of the heavy lifting is done with “framework” plugins. Use the plugin neovim/nvim-lspconfig to get the wgsl-analyzer neovim-lsp config.
- Install neovim/nvim-lspconfig
- Add
lua vim.lsp.enable('wgsl_analyzer')to yourinit.vim - Customize your setup.
lua << EOF
-- You can pass LSP settings to the server:
vim.lsp.config("wgsl_analyzer", {
settings = {
["wgsl-analyzer"] = {
-- add configuration here
},
},
})
-- You can enable different LSP features
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local client = assert(vim.lsp.get_client_by_id(ev.data.client_id))
-- Inlay hints display inferred types, etc.
if client:supports_method("inlayHint/resolve") then
vim.lsp.inlay_hint.enable(true, { bufnr = ev.buf })
end
-- Completion can be invoked using ctrl+x ctrl+o.
-- It displays a list of names inferred from the context.
-- For example, functions, variables, and constants.
if client:supports_method("textDocument/completion") then
vim.lsp.completion.enable(true, client.id, ev.buf, {})
end
end,
})
EOF
Note that the hints are only visible after wgsl-analyzer has finished loading and you have to edit the file to trigger a re-render.
vim-lsp
vim-lsp is installed by following the plugin instructions.
It can be as simple as adding this line to your .vimrc:
Plug 'prabirshrestha/vim-lsp'
Next you need to register the wgsl-analyzer binary.
If it is available in $PATH, you may want to add this to your .vimrc:
if executable('wgsl-analyzer')
au User lsp_setup call lsp#register_server({
\ 'name': 'wgsl-analyzer Language Server',
\ 'cmd': {server_info->['wgsl-analyzer']},
\ 'whitelist': ['wgsl', 'wesl'],
\ })
endif
There is no dedicated UI for the server configuration, so you would need to send any options as a value of the initialization_options field, as described in the Configuration section.
if executable('wgsl-analyzer')
au User lsp_setup call lsp#register_server({
\ 'name': 'wgsl-analyzer Language Server',
\ 'cmd': {server_info->['wgsl-analyzer']},
\ 'whitelist': ['wgsl', 'wesl'],
\ 'initialization_options': {
\ },
\ })
endif
Sublime Text
Sublime Text 4
Follow the instructions in LSP-rust-analyzer, but substitute rust with wgsl or wesl where applicable.
Install LSP-file-watcher-chokidar to enable file watching (workspace/didChangeWatchedFiles).
Sublime Text 3
- Install the LSP package.
- From the command palette, run
LSP: Enable Language Server Globallyand selectwgsl-analyzer.
If it worked, you should see “wgsl-analyzer, Line X, Column Y” on the left side of the status bar, and after waiting a bit, functionalities like tooltips on hovering over variables should become available.
If you get an error saying No such file or directory: 'wgsl-analyzer', see the wgsl-analyzer binary installation section.
GNOME Builder
No support.
Eclipse IDE
No support.
Kate Text Editor
Support for the language server protocol is built into Kate through the LSP plugin, which is included by default.
To change wgsl-analyzer config options, start from the following example and put it into Kate’s “User Server Settings” tab (located under the LSP Client settings):
{
"servers": {
"wgsl": {
"command": ["wgsl-analyzer"],
"url": "https://github.com/wgsl-analyzer/wgsl-analyzer",
"highlightingModeRegex": "^WGSL$"
},
"wesl": {
"command": ["wgsl-analyzer"],
"url": "https://github.com/wgsl-analyzer/wgsl-analyzer",
"highlightingModeRegex": "^WESL$"
}
}
}
Then click on apply, and restart the LSP server for your WGSL code or WESL project.
juCi++
juCi++ has built-in support for the language server protocol.
Kakoune
Kakoune supports LSP with the help of kak-lsp.
Follow the instructions to install kak-lsp.
To configure kak-lsp, refer to the configuration section.
It is about copying the configuration file to the right place.
The latest versions should use wgsl-analyzer by default.
Finally, you need to configure Kakoune to talk to kak-lsp (see Usage section).
A basic configuration will only get you LSP but you can also activate inlay diagnostics and auto-formatting on save.
The following might help you understand all of this:
eval %sh{kak-lsp --kakoune -s $kak_session} # Not needed if you load it with plug.kak.
hook global WinSetOption filetype=(wgsl|wesl) %{
# Enable LSP
lsp-enable-window
# Auto-formatting on save
hook window BufWritePre .* lsp-formatting-sync
# Configure inlay hints (only on save)
hook window -group wgsl-inlay-hints BufWritePost .* wgsl-analyzer-inlay-hints
hook -once -always window WinSetOption filetype=.* %{
remove-hooks window wgsl-inlay-hints
}
}
Helix
Helix supports LSP by default.
Visual Studio
No support.
Lapce
No support.
Zed
The project lucascompython/WGSL-WESL-zed is an extension for Zed. It a thin adapter for wgsl-analyzer.
IntelliJ IDEs
This includes:
- IntelliJ IDEA Ultimate
- WebStorm
- PhpStorm
- PyCharm Professional
- DataSpell
- RubyMine
- CLion
- Aqua
- DataGrip
- GoLand
- Rider
- RustRover
No support.
See #207