8000 feat: remove hard dependency on `nvim-treesitter` by soifou · Pull Request #71 · CKolkey/ts-node-action · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: remove hard dependency on nvim-treesitter #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ with the result.
```lua
{
'ckolkey/ts-node-action',
dependencies = { 'nvim-treesitter' },
opts = {},
},
```
Expand All @@ -49,7 +48,6 @@ with the result.
```lua
use({
'ckolkey/ts-node-action',
requires = { 'nvim-treesitter' },
config = function()
require("ts-node-action").setup({})
end
Expand Down
2 changes: 0 additions & 2 deletions doc/ts-node-action.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ INSTALLATION *ts-node-action-ts-node-action-installation*
>lua
{
'ckolkey/ts-node-action',
dependencies = { 'nvim-treesitter' },
opts = {},
},
<
Expand All @@ -53,7 +52,6 @@ INSTALLATION *ts-node-action-ts-node-action-installation*
>lua
use({
'ckolkey/ts-node-action',
requires = { 'nvim-treesitter' },
config = function()
require("ts-node-action").setup({})
end
Expand Down
12 changes: 9 additions & 3 deletions lua/ts-node-action/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local M = {}

local ts = vim.treesitter

--- @private
--- @param targets TSNode[]
--- @return integer start_row
Expand Down Expand Up @@ -124,14 +126,18 @@ end
--- @return TSNode, string
--- @return nil
function M._get_node()
local root_langtree = require("nvim-treesitter.parsers").get_parser()
if not root_langtree then
-- stylua: ignore
local parser = (vim.fn.has("nvim-0.12") == 1 and ts.get_parser())
or (vim.fn.has("nvim-0.11") == 1 and ts.get_parser(nil, nil, { error = false }))
or (pcall(ts.get_parser, nil, nil))

if not parser then
return
end

local lnum, col = unpack(vim.api.nvim_win_get_cursor(0))
local range4 = { lnum - 1, col, lnum - 1, col }
local langtree = root_langtree:language_for_range(range4)
local langtree = parser:language_for_range(range4)
local node = langtree:named_node_for_range(range4)
return node, langtree:lang()
end
Expand Down
Loading
0