Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9737c25

Browse files
committed
fix(scope): textobjects should use synchronous treesitter parsing.Closes#2448
1 parent8ff16ab commit9737c25

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

‎lua/snacks/scope.lua‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ M.meta = {
1010
---@fieldbuf?number
1111
---@fieldpos?{[1]:number,[2]:number}-- (1,0)indexed
1212
---@fieldend_pos?{[1]:number,[2]:number}-- (1,0)indexed
13+
---@fieldasync?boolean run scope detection asynchronously(defaults to true)
1314

1415
---@classsnacks.scope.TextObject:snacks.scope.Opts
1516
---@fieldlinewise?boolean if nil,use visual mode. Defaults to`false`when not in visual mode
@@ -396,7 +397,12 @@ function TSScope:init(cb, opts)
396397
ifnotparserthen
397398
returncb()
398399
end
399-
Snacks.util.parse(parser,opts.treesitter.injections,cb)
400+
ifopts.async==falsethen
401+
parser:parse()
402+
cb()
403+
else
404+
Snacks.util.parse(parser,opts.treesitter.injections,cb)
405+
end
400406
end
401407

402408
---@paramoptssnacks.scope.Opts
@@ -731,6 +737,7 @@ function M.textobject(opts)
731737
end
732738
localinner=notopts.edge
733739
opts.edge=true-- always include the edge of the scope to make inner work
740+
opts.async=false-- run synchronously
734741

735742
M.get(function(scope)
736743
ifnotscopethen

‎lua/snacks/util/init.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ M.base64 = vim.base64 and vim.base64.encode
459459
---@paramon_parsefun(err?:string,trees?:table<integer,TSTree>)Function invoked when parsing completes.
460460
functionM.parse(parser,range,on_parse)
461461
---@diagnosticdisable-next-line:invisible
462-
localhave_async= (vim.treesitter.languagetreeor {})._async_parse~=nil
462+
localhave_async=vim.fn.has("nvim-0.11.4")==1or(vim.treesitter.languagetreeor {})._async_parse~=nil
463463
ifhave_asyncthen
464464
parser:parse(range,on_parse)
465465
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp