feat: improve tree-sitter syntax highlighting with named nodes
- Add aliases for keywords (VAR_INPUT, BEGIN, IF, etc.) as named nodes - Add aliases for built-in types (INT, BOOL, STRING, etc.) as type_builtin - Add aliases for constants (TRUE, FALSE) - Add aliases for operators (AND, OR, NOT, MOD) - Add prefix node for # variable prefix highlighting - Highlight FB instance names in calls - Highlight FB parameter names as properties - Update README with detailed syntax highlighting features - Update .gitignore for *.wasm files
This commit is contained in:
@@ -1,5 +1,19 @@
|
||||
local M = {}
|
||||
|
||||
local function get_builtin_interface(var_type)
|
||||
local builtin = require("scl.builtin_instructions")
|
||||
local clean_type = var_type:gsub('"', ''):gsub("#", ""):upper()
|
||||
local params_info = builtin.get_parameters(clean_type)
|
||||
if params_info then
|
||||
return {
|
||||
inputs = params_info.inputs or {},
|
||||
outputs = params_info.outputs or {},
|
||||
inouts = {},
|
||||
}
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function get_fb_interface(var_type)
|
||||
local fb_parser = require("scl.fb_parser")
|
||||
local clean_type = var_type:gsub('"', '')
|
||||
@@ -49,44 +63,69 @@ function M.fill_multiline_params()
|
||||
local line_before_cursor = line:sub(1, col)
|
||||
|
||||
local known_vars = get_known_variables(bufnr)
|
||||
local builtin = require("scl.builtin_instructions")
|
||||
|
||||
local fb_name = nil
|
||||
local fb_prefix = ""
|
||||
local is_builtin_function = false
|
||||
|
||||
local prefix, var_name = line_before_cursor:match("(#?)([%w_]+)%s*%(%s*$")
|
||||
if var_name and known_vars[var_name] then
|
||||
fb_prefix = prefix or ""
|
||||
fb_name = var_name
|
||||
end
|
||||
|
||||
if not fb_name then
|
||||
prefix, var_name = line_before_cursor:match("(#?)([%w_]+)%s*%([^)]-,%s*$")
|
||||
if var_name and known_vars[var_name] then
|
||||
if var_name then
|
||||
if known_vars[var_name] then
|
||||
fb_prefix = prefix or ""
|
||||
fb_name = var_name
|
||||
elseif builtin.is_known_function(var_name) then
|
||||
fb_prefix = prefix or ""
|
||||
fb_name = var_name
|
||||
is_builtin_function = true
|
||||
end
|
||||
end
|
||||
|
||||
if not fb_name then
|
||||
vim.notify("No FB instance found before cursor", vim.log.levels.WARN)
|
||||
prefix, var_name = line_before_cursor:match("(#?)([%w_]+)%s*%([^)]-,%s*$")
|
||||
if var_name then
|
||||
if known_vars[var_name] then
|
||||
fb_prefix = prefix or ""
|
||||
fb_name = var_name
|
||||
elseif builtin.is_known_function(var_name) then
|
||||
fb_prefix = prefix or ""
|
||||
fb_name = var_name
|
||||
is_builtin_function = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not fb_name then
|
||||
vim.notify("No FB instance or known function found before cursor", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local var_type = get_variable_type(fb_name, bufnr)
|
||||
if not var_type then
|
||||
vim.notify("Cannot find type for: " .. fb_name, vim.log.levels.WARN)
|
||||
return
|
||||
local fb_interface = nil
|
||||
|
||||
if is_builtin_function then
|
||||
fb_interface = get_builtin_interface(fb_name)
|
||||
else
|
||||
local var_type = get_variable_type(fb_name, bufnr)
|
||||
if not var_type then
|
||||
vim.notify("Cannot find type for: " .. fb_name, vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local clean_type = var_type:gsub('"', '')
|
||||
|
||||
fb_interface = get_builtin_interface(clean_type)
|
||||
|
||||
if not fb_interface then
|
||||
if not is_fb_type(clean_type) then
|
||||
vim.notify(clean_type .. " is not an FB/Function type", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
fb_interface = get_fb_interface(clean_type)
|
||||
end
|
||||
end
|
||||
|
||||
local clean_type = var_type:gsub('"', '')
|
||||
if not is_fb_type(clean_type) then
|
||||
vim.notify(clean_type .. " is not an FB/Function type", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local fb_interface = get_fb_interface(clean_type)
|
||||
if not fb_interface then
|
||||
vim.notify("Cannot get interface for: " .. clean_type, vim.log.levels.WARN)
|
||||
vim.notify("Cannot get interface for: " .. (clean_type or fb_name), vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -102,7 +141,7 @@ function M.fill_multiline_params()
|
||||
end
|
||||
|
||||
if #params == 0 then
|
||||
vim.notify("No parameters found for: " .. clean_type, vim.log.levels.WARN)
|
||||
vim.notify("No parameters found for: " .. (clean_type or fb_name), vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user