Crates.io | luau-ast-rs-grammar |
lib.rs | luau-ast-rs-grammar |
version | 0.0.2 |
source | src |
created_at | 2023-06-20 20:38:34.300305 |
updated_at | 2023-06-24 07:04:19.101718 |
description | luau grammar for the tree-sitter parsing library |
homepage | |
repository | https://github.com/tree-sitter/tree-sitter-luau |
max_upload_size | |
id | 895481 |
size | 838,269 |
Luau grammar for tree-sitter
languages.toml
file if it doesn't already exist (docs)languages.toml
:[[language]]
name = "luau"
scope = "source.luau"
injection-regex = "^luau$"
file-types = ["luau", "server.lua", "client.lua"]
comment-token = "--"
indent = { tab-width = 2, unit = " "}
# language-server = { command = "luau-lsp", args = ["lsp", "--definitions=<path-to-robloxTypes.d.lua>"] }
roots = [ "aftman.toml", "default.project.json", "wally.toml" ]
[[grammar]]
name = "luau"
source = { git = "https://github.com/polychromatist/tree-sitter-luau" }
.\scripts\clone_helix_queries.ps1
(or manually clone from .\helix-queries\
into <helix-config>\runtime\queries\luau
)hx --grammar fetch
&& hx --grammar build
There is now a Luau parser packaged in nvim-treesitter which will cause a conflict if naively overwritten.
See the issue.
Due to this, the script scripts/clone_queries.ps1
is now incorrect and has been removed.
As it stands (5/13/2023), the parser packaged in nvim-treesitter is somewhat OK, but not fully correct. This is not my parser.
Here is the approach I used to overwrite it.
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
local myhome = os.getenv "USERPROFILE" or os.getenv "HOME" -- user profile path, if needed
local mypath = "CHANGE_THIS"
-- Example:
-- local mypath = myhome .. "/techstuff/hunter2/cloned_repos"
parser_config.luau = {
install_info = {
url = mypath .. "/tree-sitter-luau",
files = {"src/parser.c", "src/scanner.c"},
-- generate_requires_npm = false,
-- requires_generate_from_grammar = false
},
}
:TSInstall luau
au BufRead,BufNewFile *.luau set filetype=luau
-- set queries for luau. parser_config segment should be above
do
for i, v in pairs{"highlights", "indents", "folds", "injections", "locals"} do
local fd = io.open(mypath .. "/tree-sitter-luau/nvim-queries/" .. v .. ".scm")
local txt = fd:read"*a"
fd:close()
vim.treesitter.query.set("luau", v, txt)
end
end
local MY_LUAU_LSP_PATH = "C:\\bin\\luau-lsp.exe"
local MY_DIAGNOSTIC_KEY = "" -- ctrl N
local MY_LOOKUP_KEY = "K" -- shift K
-- LSP Diagnostics Options Setup
local sign = function(opts)
vim.fn.sign_define(opts.name, {
texthl = opts.name,
text = opts.text,
numhl = ''
})
end
sign({name = 'DiagnosticSignError', text = ''})
sign({name = 'DiagnosticSignWarn', text = ''})
sign({name = 'DiagnosticSignHint', text = ''})
sign({name = 'DiagnosticSignInfo', text = ''})
vim.diagnostic.config({
virtual_text = false,
signs = true,
update_in_insert = true,
underline = true,
severity_sort = false,
float = {
border = 'rounded',
source = 'always',
header = '',
prefix = '',
},
})
-- overwrite keymap on LSP enabled buffers
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
vim.keymap.set('n', MY_LOOKUP_KEY, vim.lsp.buf.hover, { buffer = args.buf })
vim.keymap.set('n', MY_DIAGNOSTIC_KEY, function()
vim.diagnostic.open_float(nil, { focusable = false })
end, {buffer = true})
end
})
-- autocmd-event LSP Server Start Callback
function _G.start_luau_lsp()
vim.lsp.start({
name = 'nvim-luau-lsp',
cmd = {MY_LUAU_LSP_PATH, 'lsp'},
root_dir = vim.fs.dirname(vim.fs.find({'aftman.toml', 'wally.toml', 'default.project.json'}, { upward = true })[1])
})
end
-- enable signcolumn and register autocmd-event
vim.cmd([[
set signcolumn=yes
au BufRead,BufNewFile *.luau lua _G.start_luau_lsp()
]])