Sublime Forum

Get positions of a Symbol

#1

Hi,

Is there a way to get the positions of a particular symbol (that come from the Grammar)in a text ?
view.syntaxName() give me the symbol name for a position but I want the opposite.
I’ve found the view.getSymbols() but it work only for the symbols declared in Symbol List, but it’s close to what I want.

If it doesn’t exists what about add it to next version ?
Please…

Dominique

0 Likes

#2

[quote=“sublimator”]view.matchSelector(pt, s) will determine if scope ‘s’ matches at point ‘pt’

You’ll have to create your own function to findAll regions matching a scope, but that’s not very hard.[/quote]

I’m not sure I’m understand what You mean.

If I want the positions of all functions in a python source, so basically all occurrence of the scope “source.python meta.function.python”.
So to use view.matchSelector() I need to check every word in the source, it would be really inefficient. Or is it something hidden behind findAll ?

I suppose ST already parse the source and record the positions of the scopes, so we only need a method to ask ST where the scopes ‘x’ are.

0 Likes

#3

I raise this question because I need this kind of functionality and look the best way to implement it.
A priori, only Jon could answer.

A practical example is a command to switch from interface to implementation of a method when both are in same file, like Delphi.
Using scope mean that I use the already defined syntax from language versus define my own RE to find them.

Actually, is finding occurrences of a scope using internal ST2 command quicker than a find with RE (is there some internal structure that hold this information when syntax highlight is processed) ?
Do you think my request have a chance to be heard ?

Thanks.

0 Likes

#4

The realistic case can be a control to switch through program to rendering of a technique whenever the two are usually in identical file, including Delphi.
Applying setting imply I exploit your by now defined syntax through vocabulary compared to outline my very own RE to uncover all of them.In fact, is actually discovering events of a setting making use of inner ST2 control more quickly than a discover along with RE (is presently there a few inner design that carry these records whenever syntax spotlight is actually processed)?
Think my own demand get an opportunity to be noticed?

0 Likes

#5

view.find_by_selector(‘source.python meta.function.python’)
(49, 69), (84, 107), (969, 983), (1018, 1033), (1069, 1080), (1120, 1134), (1169, 1191), (1234, 1256), (1398, 1418), (1459, 1489), (1540, 1557), (1662, 1686), (1724, 1747), (1784, 1808), (1846, 1887), (1944, 1978), (2019, 2060), (2286, 2310), (2355, 2378), (2415, 2435), …

0 Likes