Posted 12 years ago by Matthew Smith - Developer, One Plus One Solutions Pty Limited
Version: 4.0.0244
Avatar
Hi,

I have a question in regards to the Dynamic Syntax Language and outlining.

I'm designing a dynanic language definition for a basic language, which under certain circumstances requires a method or function to not have a end method/function call. I need to identify these and not set them as outlined when required.

Example code

'Outline this
Method TestA(x:Int, y:Int)
End Method

'Don't outline this
Method TestB(x:Int, y:Int) Abstract
I have used the provided Vb.Net Language Definition and DynamicOutlingingSyntaxLanguage class as the basis for my language's code.

This is the language definition for the method

<ExplicitPatternGroup TokenKey="MethodReservedWordToken" Style="ReservedWordStyle" LookBehind="^|[^\.]" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect">
    <ExplicitPattern Value="Method" />
</ExplicitPatternGroup>
<!-- Foldable End Reserved Words -->
<ExplicitPatternGroup TokenKey="EndMethodReservedWordToken" Style="ReservedWordStyle" LookBehind="^|[^\.]" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect">
    <ExplicitPattern Value="End Method" />
     <ExplicitPattern Value="EndMethod" />
</ExplicitPatternGroup>
Any assistance would be appreciated.

Regards, Matt

Comments (6)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Matthew,

In your language's GetTokenOutliningAction implementation, when you see MethodReservedWordToken,
I'd use a TextStream scan forward to look at the tokens on the same line to determine
if the method is a block start or not. If it is, do the normal outlining code like in
the sample, otherwise do nothing.


Actipro Software Support

Posted 12 years ago by Matthew Smith - Developer, One Plus One Solutions Pty Limited
Avatar
Thanks

I'll check that out

Regards, Matt

Posted 12 years ago by Matthew Smith - Developer, One Plus One Solutions Pty Limited
Avatar
Ok, I've added the following code in the area you have suggested:

Case "MethodReservedWordToken"
    Dim validateStream As TokenStream = tokenStream
    Dim isAbstract As Boolean = False

    'Does this line end with Abstract
    Do
    'Get token information
    Dim currentToken As IToken = validateStream.Peek
    Dim currentTokenText As String = validateStream.Document.GetTokenText(currentToken)

    'Exit?
    If (validateStream.IsDocumentEnd) Then Exit Do

    'Process tokens
    Select Case currentToken.Key
        Case "LineTerminatorToken", "CommentDefaultToken"
        Exit Do

        Case "ReservedWordToken"
        If (currentTokenText.Equals("Abstract", StringComparison.CurrentCultureIgnoreCase)) Then
            isAbstract = True
            Exit Do

        End If

    End Select

    'Move next token
    validateStream.Read()

    Loop

    'Outline section?
    If (Not isAbstract) Then
    outliningKey = "MethodBlock"
    tokenAction = OutliningNodeAction.Start

    End If
The question I have now is that the outlining process is a little inconsistent in it's application. It outlines Ok when I initially load the sample file, but once I remove the 'Abtract' token and add an End Method, the outlining won't be picked up again until do some major re-editing of the line.

I think (from memory), this may be because of a partial parsing of the document vs. a full reparse, but I'm not sure what to do next.

Would this require custom outlining by me??

[Modified at 03/01/2007 06:44 PM]

Regards, Matt

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I remember now that another customer ran into something similar a while back. I think they ended up implementing custom outlining and it worked out well for them. That will be your best solution but I will attempt to provide you a quick workaround too here that won't be 100% accurate but will help a lot.

The problem here is that the parse range that the outlining code is looking at updating (based on the optimized parse range passed to PerformAutomaticOutlining) doesn't know to extend back to the start of your method declaration when the abstract word is added/removed.

What I'm going to do is unseal the DynamicOutliningSyntaxLanguage.PerformAutomaticOutlining method so that in your class you can override it. This way when you call the base PerformAutomaticOutlining method, you can pass a TextRange that starts farther back in this scenario (or in all scenarios). Perhaps you just move it back another 100 or 200 characters. That should catch most cases. Just be sure you don't pass a start offset less than zero.


Actipro Software Support

Posted 12 years ago by Matthew Smith - Developer, One Plus One Solutions Pty Limited
Avatar
Great! thanks again for your help. I'll look for that in the next release. Might also play with some custom stuff.


[Modified at 03/04/2007 04:49 PM]

Regards, Matt

Posted 12 years ago by Matthew Smith - Developer, One Plus One Solutions Pty Limited
Avatar
Tested the newly unsealed function - works great thanks!

        Public Overrides Function PerformAutomaticOutlining(ByVal document As ActiproSoftware.SyntaxEditor.Document, ByVal parseTextRange As ActiproSoftware.SyntaxEditor.TextRange) As ActiproSoftware.SyntaxEditor.TextRange
            'Set outlining back to capture any changes to an entire outlining row
            Dim newTextRange As New TextRange(Math.Max(0, parseTextRange.StartOffset - 100), parseTextRange.EndOffset)
            Return MyBase.PerformAutomaticOutlining(document, newTextRange)

        End Function

Regards, Matt

The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.