Compare commits

...

3 Commits

2 changed files with 62 additions and 3 deletions

View File

@@ -0,0 +1,31 @@
-- Copyright 2006-2025 Mitchell. See LICENSE.
-- go with SQL LPeg lexer.
local lexer = lexer
local starts_line = lexer.starts_line
local B, P, S = lpeg.B, lpeg.P, lpeg.S
local lex = lexer.new(..., {inherit = lexer.load('go')})
local open_brace = lex:tag(lexer.OPERATOR, P('{'))
local close_brace = lex:tag(lexer.OPERATOR, P('}'))
local backtick = lex:tag(lexer.STRING, P('`'))
local ws = lex:get_rule('whitespace')
local tpl = lexer.new("template")
tpl:add_rule('keyword', lex:tag(lexer.KEYWORD, lexer.word_match('if else end with range break define continue template block')))
tpl:add_rule('constant', lex:get_rule('constant'))
tpl:add_rule('operator', lex:get_rule('operator') + lex:tag(lexer.OPERATOR, S('$')))
local func = lexer.after_set(' \t\n{|', lexer.word)
tpl:add_rule('function', lex:tag(lexer.FUNCTION, func))
tpl:add_rule('identifier', lex:get_rule('identifier'))
tpl:add_rule('string', lex:get_rule('string'))
tpl:add_rule('number', lex:get_rule('number'))
local sql = lexer.load('sql')
local sql_kwd = lexer.word_match('ALTER CREATE DELETE DROP GRANT INSERT SELECT UPDATE WITH')
sql:embed(tpl, open_brace * open_brace, close_brace * close_brace)
lex:embed(sql, backtick * #(ws^0 * sql_kwd), backtick)
return lex

View File

@@ -23,6 +23,10 @@ local plugins = {
plug.init(plugins, true) plug.init(plugins, true)
vis.ftdetect.filetypes.go_ext = vis.ftdetect.filetypes.go
vis.ftdetect.filetypes.go = nil
plug.plugins.lspc.ls_map.go_ext = plug.plugins.lspc.ls_map.go
vis.ftdetect.filetypes.templ = { vis.ftdetect.filetypes.templ = {
ext = { "%.templ$" }, ext = { "%.templ$" },
} }
@@ -181,6 +185,22 @@ end
local ripgrep = 'rg --column --line-number --color=always --smart-case' local ripgrep = 'rg --column --line-number --color=always --smart-case'
local function close_prev_win()
vis:feedkeys('<vis-window-prev>')
if not vis.win:close() then
vis:feedkeys('<vis-window-next>')
vis:info('No write since last change')
end
end
local function close_next_win()
vis:feedkeys('<vis-window-next>')
if not vis.win:close() then
vis:feedkeys('<vis-window-prev>')
vis:info('No write since last change')
end
end
vis.events.subscribe(vis.events.INIT, function() vis.events.subscribe(vis.events.INIT, function()
vis:command('set autoindent') vis:command('set autoindent')
@@ -190,8 +210,8 @@ vis.events.subscribe(vis.events.INIT, function()
vis:map(vis.modes.NORMAL, '<M-k>', '<vis-window-prev>') vis:map(vis.modes.NORMAL, '<M-k>', '<vis-window-prev>')
vis:map(vis.modes.NORMAL, '<M-j>', '<vis-window-next>') vis:map(vis.modes.NORMAL, '<M-j>', '<vis-window-next>')
vis:map(vis.modes.NORMAL, ' K', '<vis-window-prev>:q<Enter>', 'close previous window') vis:map(vis.modes.NORMAL, ' K', close_prev_win)
vis:map(vis.modes.NORMAL, ' J', '<vis-window-next>:q<Enter><vis-window-prev>', 'close next window') vis:map(vis.modes.NORMAL, ' J', close_next_win)
vis:map(vis.modes.NORMAL, ' l[', ':lspc-prev-diagnostic<Enter>') vis:map(vis.modes.NORMAL, ' l[', ':lspc-prev-diagnostic<Enter>')
vis:map(vis.modes.NORMAL, ' l]', ':lspc-next-diagnostic<Enter>') vis:map(vis.modes.NORMAL, ' l]', ':lspc-next-diagnostic<Enter>')
@@ -295,4 +315,12 @@ end)
vis.events.subscribe(vis.events.WIN_OPEN, function(win) vis.events.subscribe(vis.events.WIN_OPEN, function(win)
vis:command('set relativenumber') vis:command('set relativenumber')
end) end)
vis.events.subscribe(vis.events.FILE_SAVE_PRE, function(file, path)
if path:find('[.]go$') then
-- formatting is async, so when reformated you should write file again
vis:command('lspc-format')
end
return true
end)