[SVN] REQUEST: Scope Querying API

Alain O'Dea alain.odea at gmail.com
Wed Jan 9 00:06:28 UTC 2008


On 8-Jan-08, at 12:43 PM, Charilaos Skiadas wrote:

> On Jan 8, 2008, at 10:47 AM, Thomas Aylott - subtleGradient wrote:
>
>> On Jan 7, 2008, at 10:47 PM, Luke Daley wrote:
>>> On 08/01/2008, at 10:54 AM, Alain O'Dea wrote:
>>>
>>>> I would like to be able to query the current file or other  
>>>> project files for symbols based on scope. I would also like to be  
>>>> able to query for symbols with a common instance of a parent scope.
>>>>
>>>> For illustrative purposes I will use JavaScript-like syntax and  
>>>> JS DOM-like API:
>>>>
>>>> // get all atoms in the current document
>>>> document.getSymbolsByScope("source.erlang meta.function.erlang  
>>>> meta.structure.tuple.erlang  
>>>> constant.other.symbol.unquoted.erlang");
>>>>
>>>> // get all atoms in the current function
>>>> currentFunction = currentScope.getAncestorByScope("source.erlang  
>>>> meta.function.erlang");
>>>> currentFunction.getSymbolsByScope("source.erlang  
>>>> meta.function.erlang meta.structure.tuple.erlang  
>>>> constant.other.symbol.unquoted.erlang");
>>>>
>>>> // get all functions in the current module
>>>> document.getSymbolsByScope("source.erlang meta.function");
>>>
>>> +1 on all of that from me.
>>>
>>> Also, if you could find the closest something from the caret, that  
>>> would be very handy.
>>>
>>> LD.
>>
>> Sounds wonderful.
>> There's already a way to get the scoped out xml of the current file.
>> Maybe there's already some kind of xml thing you can use to do it?
>> Every language on earth parses xml. I'm sure something exists that  
>> can be modified to do what you say.
>>
>> I would love to have something that was really easy to use though.
>>
> I had at some point created a "ScopeHandler" ruby class specifically  
> for this purpose, it kind of works but is not very satisfactory, and  
> pretty slow on even moderately sized documents. But someone might be  
> inspired by it:
>
> http://skiadas.dcostanet.net/afterthought/the-scopehandler-class/
>
> It's not exactly what Alain describes above, but perhaps it might be  
> used to get ideas. It would indeed be wonderful to have something  
> like this out of the box.
>>
>> —Thomas Aylott – subtleGradient—
>
> Haris Skiadas
> Department of Mathematics and Computer Science
> Hanover College

I like how the ScopeHandler works. Some of the cost of the slowness  
could be mitigated if the class were run in a background process that  
serviced scope queries on cached AST/DOM information. Reparsing the  
complete AST/DOM of a document for each scope query (such as code  
completion would use) would make it impractically slow even with the  
most efficient possible XML parser.

TextMate does identify the scopes and appears to do so as it scans the  
document based on seeing the highlighter at work on my less than  
stellar PPC Mac mini. If TextMate fired notifications of these scopes  
as they were encountered a subscriber process could build and track  
the AST/DOM itself. This would make it unnecessary for TextMate to  
carry around the memory expensive complete AST/DOM. Bundle developers  
could then implement code completion with a whatever subset of AST/DOM/ 
scope events they need.



More information about the textmate-dev mailing list