Format with stylua

This commit is contained in:
L3MON4D3 2023-05-01 20:43:26 +00:00 committed by github-actions[bot]
parent 1d4fab1f4c
commit a5b31ead81
7 changed files with 75 additions and 40 deletions

View file

@ -63,7 +63,9 @@ local function json_find_snippet_definition(bufnr, extension, snippet_name)
local root = parser:parse()[1]:root()
-- don't want to pass through whether this file is json or jsonc, just use
-- parser-language.
local query = tsquery_parse(parser:lang(), ([[
local query = tsquery_parse(
parser:lang(),
([[
(pair
key: (string (string_content) @key (#eq? @key "%s"))
) @snippet
@ -134,7 +136,8 @@ function M.jump_to_snippet(snip, opts)
elseif vim.api.nvim_buf_get_name(0):match("%.jsonc?$") then
local extension = vim.api.nvim_buf_get_name(0):match("jsonc?$")
local ok
ok, fcall_range = pcall(json_find_snippet_definition, 0, extension, snip.name)
ok, fcall_range =
pcall(json_find_snippet_definition, 0, extension, snip.name)
if not ok then
print(
"Could not determine range of snippet-definition: "

View file

@ -38,7 +38,7 @@ local M = {}
-- Instead, it is inserted into the global environment before a luasnippet-file
-- is loaded, and removed from it immediately when this is done
local function get_loaded_file_debuginfo()
-- we can skip looking at the first four stackframes, since
-- we can skip looking at the first four stackframes, since
-- 1 is this function
-- 2 is the snippet-constructor
-- ... (here anything is going on, could be 0 stackframes, could be many)
@ -51,7 +51,7 @@ local function get_loaded_file_debuginfo()
repeat
current_call_depth = current_call_depth + 1
debuginfo = debug.getinfo(current_call_depth, "n")
until (debuginfo.name == "_luasnip_load_files")
until debuginfo.name == "_luasnip_load_files"
-- ret is stored into a local, and not returned immediately to prevent tail
-- call optimization, which seems to invalidate the stackframe-numbers
@ -112,10 +112,14 @@ local function _luasnip_load_files(ft, files, add_opts)
-- Since this function has to reach the snippet-constructor, and fenvs
-- aren't inherited by called functions, we have to set it in the global
-- environment.
_G.__luasnip_get_loaded_file_frame_debuginfo = util.ternary(session.config.loaders_store_source, get_loaded_file_debuginfo, nil)
_G.__luasnip_get_loaded_file_frame_debuginfo = util.ternary(
session.config.loaders_store_source,
get_loaded_file_debuginfo,
nil
)
local run_ok, file_snippets, file_autosnippets = pcall(func)
-- immediately nil it.
_G.__luasnip_get_loaded_file_frame_debuginfo = nil
_G.__luasnip_get_loaded_file_frame_debuginfo = nil
if not run_ok then
log.error("Failed to execute\n: %s", file, file_snippets)
@ -169,7 +173,11 @@ end
function M._load_lazy_loaded_ft(ft)
for _, load_call_paths in ipairs(cache.lazy_load_paths) do
_luasnip_load_files(ft, load_call_paths[ft] or {}, load_call_paths.add_opts)
_luasnip_load_files(
ft,
load_call_paths[ft] or {},
load_call_paths.add_opts
)
end
end

View file

@ -62,7 +62,10 @@ local function parse_snipmate(buffer, filename)
}
)
if session.config.loaders_store_source then
snip._source = source.from_location(filename, {line = snip_begin_line, line_end = i-1})
snip._source = source.from_location(
filename,
{ line = snip_begin_line, line_end = i - 1 }
)
end
table.insert(snippets[snippet_type], snip)
end

View file

@ -275,7 +275,8 @@ local function S(context, nodes, opts)
if __luasnip_get_loaded_file_frame_debuginfo ~= nil then
-- this snippet is being lua-loaded, and the source should be recorded.
snip._source = source.from_debuginfo(__luasnip_get_loaded_file_frame_debuginfo())
snip._source =
source.from_debuginfo(__luasnip_get_loaded_file_frame_debuginfo())
end
return snip

View file

@ -4,12 +4,15 @@ local M = {}
function M.from_debuginfo(debuginfo)
assert(debuginfo.source, "debuginfo contains source")
assert(debuginfo.source:match("^@"), "debuginfo-source is a file: " .. debuginfo.source)
assert(
debuginfo.source:match("^@"),
"debuginfo-source is a file: " .. debuginfo.source
)
return {
-- omit leading '@'.
file = debuginfo.source:sub(2),
line = debuginfo.currentline
line = debuginfo.currentline,
}
end
@ -17,7 +20,7 @@ function M.from_location(file, opts)
assert(file, "source needs file")
opts = opts or {}
return {file = file, line = opts.line, line_end = opts.line_end}
return { file = file, line = opts.line, line_end = opts.line_end }
end
function M.set(snippet, source)

View file

@ -29,8 +29,7 @@ function M.session_setup_luasnip(opts)
opts = opts or {}
local no_snip_globals = opts.no_snip_globals ~= nil and opts.no_snip_globals
or false
local setup_extend = opts.setup_extend ~= nil and opts.setup_extend
or {}
local setup_extend = opts.setup_extend ~= nil and opts.setup_extend or {}
local setup_parsers
if opts.setup_parsers ~= nil then
setup_parsers = opts.setup_parsers
@ -50,7 +49,7 @@ function M.session_setup_luasnip(opts)
if setup_parsers then
-- adding the lua-parser, is either a nop or adds the parser on
-- versions where it does not exist by default.
exec_lua[[
exec_lua([[
ts_lang_add =
(vim.treesitter.language and vim.treesitter.language.add)
and function(lang, path)
@ -63,10 +62,11 @@ function M.session_setup_luasnip(opts)
ts_lang_add("json", os.getenv("LUASNIP_SOURCE") .. "/tests/parsers/json.so")
ts_lang_add("jsonc", os.getenv("LUASNIP_SOURCE") .. "/tests/parsers/jsonc.so")
]]
]])
end
helpers.exec_lua([[
helpers.exec_lua(
[[
-- MYVIMRC might not be set when nvim is loaded like this.
vim.env.MYVIMRC = "/.vimrc"

View file

@ -91,7 +91,7 @@ describe("loaders:", function()
"expands? jumps? $1 $2 !" |
] |
}, |
Could not determine ran...help treesitter-parsers |]]
Could not determine ran...help treesitter-parsers |]],
})
end)
@ -135,14 +135,16 @@ describe("loaders:", function()
it("vscode: correctly highlights definition if parser installed", function()
ls_helpers.session_setup_luasnip({
no_snip_globals = true,
setup_extend = {loaders_store_source = true},
setup_parsers = true })
setup_extend = { loaders_store_source = true },
setup_parsers = true,
})
ls_helpers.loaders["vscode(rtp)"]()
feed("iall1")
exec_lua("ls.expand()")
screen:expect{grid=[[
screen:expect({
grid = [[
expands? jumps? ^ ! |
{0:~ }|
{0:~ }|
@ -150,10 +152,14 @@ describe("loaders:", function()
{0:~ }|
{0:~ }|
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
feed("<esc>")
exec_lua([[require("luasnip.extras.snip_location").jump_to_active_snippet()]])
screen:expect{grid=[[
exec_lua(
[[require("luasnip.extras.snip_location").jump_to_active_snippet()]]
)
screen:expect({
grid = [[
{ |
{3: ^ "snip1": {} |
{3: "prefix": "all1",} |
@ -161,19 +167,24 @@ describe("loaders:", function()
{3: "expands? jumps? $1 $2 !"} |
{3: ]} |
{3: },} |
|]]}
|]],
})
end)
it("lua: highlights definition (should always work, the lua-parser is installed by default).", function()
ls_helpers.session_setup_luasnip({
no_snip_globals = true,
setup_extend = {loaders_store_source = true},
setup_parsers = true })
ls_helpers.loaders["lua(rtp)"]()
it(
"lua: highlights definition (should always work, the lua-parser is installed by default).",
function()
ls_helpers.session_setup_luasnip({
no_snip_globals = true,
setup_extend = { loaders_store_source = true },
setup_parsers = true,
})
ls_helpers.loaders["lua(rtp)"]()
feed("iall1")
exec_lua("ls.expand()")
screen:expect{grid=[[
feed("iall1")
exec_lua("ls.expand()")
screen:expect({
grid = [[
expands? jumps? ^ ! |
{0:~ }|
{0:~ }|
@ -181,10 +192,14 @@ describe("loaders:", function()
{0:~ }|
{0:~ }|
{0:~ }|
{2:-- INSERT --} |]]}
feed("<esc>")
exec_lua([[require("luasnip.extras.snip_location").jump_to_active_snippet()]])
screen:expect{grid=[[
{2:-- INSERT --} |]],
})
feed("<esc>")
exec_lua(
[[require("luasnip.extras.snip_location").jump_to_active_snippet()]]
)
screen:expect({
grid = [[
return { |
{3: ^ s("all1", fmt("expands? jumps? {} {} !", {}|
{3: i(1), i(2) })),} |
@ -192,6 +207,8 @@ describe("loaders:", function()
parse("auto???", "autotriggered????????"),|
} |
{0:~ }|
|]]}
end)
|]],
})
end
)
end)