Sublime Forum

View.expand_to_scope() bug

#1

According to the release note of Build 4131:

API: View.expand_to_scope now returns None when the text point doesn’t match the selector

but its not the case I tested below:

A{"bug"};
f("bug");
m["bug"];
a="bug";

paste above code in a new text, set syntax to C++; and at console input:

>>> view.expand_to_scope(view.find('\\{',0).a,'string')
Region(1, 6)
>>> view.expand_to_scope(view.find('\\(',0).a,'string')
Region(11, 16)
>>> view.expand_to_scope(view.find('\\[',0).a,'string')
Region(21, 26)
>>> view.expand_to_scope(view.find('=',0).a,'string')
Region(31, 36)

this is absurd.

This issue is not limited to ‘string’. It seems the implementation have some wrong treats on some punctuations: such as [, ], (, ), =, and comma.

0 Likes

#2

Looks like a bug with correct token boundary calculations, which is triggered when calling expand_to_scope for a position before the start of a token. It even returns the region off by one then.

>>> view.expand_to_scope(0, "string")
None
>>> view.expand_to_scope(1, "string")
Region(1, 6)
>>> view.expand_to_scope(2, "string")
Region(2, 7)
>>> view.expand_to_scope(3, "string")
Region(2, 7)
>>> view.expand_to_scope(7, "string")
Region(2, 7)
>>> view.expand_to_scope(8, "string")
None

Maybe worth a bug report at https://github.com/sublimehq/sublime_text/issues

0 Likes

#3

@deathaxe You are right. And I dont know if there are more unexpected errors in this functionality. But I am not going to make a bug report. I just hope their developers fix it in a few minutes after they view this post.

0 Likes