Home Download Buy Blog Forum Support

Scopes and extract_scope

Scopes and extract_scope

Postby rorydriscoll on Fri Feb 24, 2012 11:22 pm

I'm having trouble working out what the exact rules are for the region returned from view.extract_scope. I'm working on better scopes for the Lua grammar, but some of the behaviour is puzzling to me.

e.g. Here's the visual scope for the comment delimiter, plus the text scope description. The cursor is on '--':

source.lua comment.line.double-dash.lua punctuation.definition.comment.lua
Image

This what I would expect. The innermost scope at the cursor is the comment delimiter. As you move to the right where nothing is scoped, the visual scope moves out to match the entire comment. Again, I expect this because it is the now the innermost scope since I never scoped the comment text.

source.lua comment.line.double-dash.lua
Image

Now here's the strange one. When I highlight the word 'function', it matches the entire function's scope, not the keyword 'function' itself. Note that the keyword is the innermost scope.

source.lua meta.function.lua keyword.control.lua
Image

So why does this match the scope 'meta.function.lua' rather than 'keyword.control.lua'?

On a related note, it would be awesome to be able to choose the scope level in extract_scope. This would allow me to visualize all scopes for a particular token. Needless to say this would be very handy when working on language grammars.
rorydriscoll
 
Posts: 3
Joined: Fri Feb 24, 2012 11:07 pm

Re: Scopes and extract_scope

Postby laughedelic on Thu Oct 18, 2012 11:27 pm

I have the same problem. I found, that extract_scope works correctly for scopes, that have begin-end syntax matches and ignores elements, which are simply matched.
Haven't you solved it anyhow?
And yes, it would be so cool to have a function like find(pattern, fromPosition), but with selector instead of pattern...
laughedelic
 
Posts: 4
Joined: Thu Oct 11, 2012 7:38 pm

Re: Scopes and extract_scope

Postby facelessuser on Fri Oct 19, 2012 3:07 pm

I have found extract_scope to be maybe 40% useful. If you happen to be scanning for a region that is very simple, and doesn't touch any similar regions, it seems to work okay. If you try and do any thing other than that, it gets confused in a hurry.

I tried to do something basic like find an html tag.
Basic structure is that the main scope is meta.tag and the end caps are punctuation.definition.tag.begin and punctuation.definition.tag.end.

So the idea was simple, start grabbing the extent of the cursor's scope if it was one of the three. If you are looking left, ensure that the next character to the left was meta.tag -punctuation.definition.tag.end, if so grab that extent and add it to the current.

Do something similar when looking right but exclude the begin part. It worked well enough until you start putting these regions next to each other.

For instance, the opening tags just bleed together in this example (it would group tag.begin and tag.end together for opening tags, but not for closing; it made no sense):
Code: Select all
<div><div><div></div></div></div>


I would find it more useful if it only would return contiguous same scopes opposed to trying to be clever and try to group similar/close enough scopes.
facelessuser
 
Posts: 1457
Joined: Tue Apr 05, 2011 7:38 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 12 guests