Skip to content

Commit

Permalink
Format with stylua
Browse files Browse the repository at this point in the history
  • Loading branch information
L3MON4D3 authored and github-actions[bot] committed May 1, 2023
1 parent 000adfd commit 2a9a3bd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
7 changes: 5 additions & 2 deletions lua/luasnip/extras/snip_location.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: "
Expand Down
10 changes: 5 additions & 5 deletions tests/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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"
Expand Down
63 changes: 40 additions & 23 deletions tests/integration/source_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -135,63 +135,80 @@ 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:~ }|
{0:~ }|
{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",} |
{3: "body": [} |
{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:~ }|
{0:~ }|
{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) })),} |
}, { |
parse("auto???", "autotriggered????????"),|
} |
{0:~ }|
|]]}
end)
|]],
})
end
)
end)

0 comments on commit 2a9a3bd

Please sign in to comment.