Skip to content

Commit

Permalink
fix: Display context when injected language is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaszczuk authored and lewis6991 committed Feb 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent a5d16fd commit fbeff2a
Showing 4 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -145,6 +145,7 @@ Note: if you need support for Neovim 0.6.x please use the tag `compat/0.6`.
- [ ] `ledger`
- [ ] `llvm`
- [ ] `m68k`
- [ ] `markdown_inline`
- [ ] `menhir`
- [ ] `mermaid`
- [ ] `meson`
14 changes: 10 additions & 4 deletions lua/treesitter-context/context.lua
Original file line number Diff line number Diff line change
@@ -247,15 +247,21 @@ function M.get(bufnr, winid)
for i = 1, #parent_trees, 1 do
local langtree = parent_trees[i]
local query = get_context_query(langtree:lang())
if not query then
return
end

local parents = get_parent_nodes(langtree, line_range)
if parents == nil then
return
end

if not query then
-- If the language is not supported we ignore it and continue
-- with remaining languages. This way we can get as much context
-- as possible, even if some injected languages are not supported.
--
-- There's no continue statement in Lua, so we need to get a
-- little creative to skip to the next iteration.
parents = {}
end

for j = #parents, 1, -1 do
local parent = parents[j]
local parent_start_row = parent:range()
19 changes: 19 additions & 0 deletions test/test.md
Original file line number Diff line number Diff line change
@@ -43,3 +43,22 @@
</body>
</html>
```

# Title





Test











17 changes: 17 additions & 0 deletions test/ts_context_spec.lua
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ describe('ts_context', function()
"cpp",
"typescript",
"markdown",
"markdown_inline",
"html",
"javascript",
},
@@ -372,6 +373,22 @@ describe('ts_context', function()
|*10
]]}
end)

-- Separate Markdown testcase to test plugin behavior with
-- unsupported injected languages (markdown_inline does not
-- have queries specified)
it('markdown_inline', function()
cmd('edit test/test.md')
exec_lua [[vim.treesitter.start()]]

feed'47<C-e>'
screen:expect{grid=[[
{2:# Title }|
|*4
^Test |
|*10
]]}
end)
end)

end)

0 comments on commit fbeff2a

Please sign in to comment.