SSlinky / VBA-LanguageServer

VBA Language Server
GNU General Public License v3.0
16 stars 4 forks source link

[Bug] Perhaps not a bug, but what's going on with the minimap? #3

Closed sancarn closed 4 months ago

sancarn commented 4 months ago

Describe the bug

The minimap seems to highlight a bunch of different lines for seemingly no reason?

image

E.G. Each accChild ... and Each accDesc ... and length > 0 and index < length

I imagine these aren't arbitrary... But not sure.

To Reproduce

I opened stdAcc with the extension

Code (if relevant)

For instance:

Public Function FindFirst(ByVal query As stdICallable, optional byval searchType as EAccFindType=EAccFindType.DepthFirst) As stdAcc
    Dim stack() As tFindNode
    ReDim stack(0 To 0)
    stack(0).initialised = true
    stack(0).depth = 0
    Set stack(0).element = Me

    Dim length As Long: length = 1
    Dim index As Long: index = -1

    'Bind globals to query
    Call BindGlobals(query)

    'Loop over the stack/array
    While length > 0 And index < length
        Dim part As tFindNode
        select case searchType
            case EAccFindType.DepthFirst
                'Depth first search, so pop the item out of the stack
                part = stackPopV(stack,length)
            case EAccFindType.BreadthFirst
                'Breadth first search, get item directly out of array, no need to change array size
                index = index + 1
                part = stack(index)
            case else
                Err.Raise 1, "stdAcc#FindFirst", "Invalid search type given. Please use EAccFindType"
        end select

        With part
            If not .initialised Then Exit Function

            'Run query and test options
            Select Case query.Run(.element, .depth)
                Case EAccFindResult.NoMatchFound
                    'Nothing found, search descendents
                    Dim child As stdAcc
                    For Each child In part.element.children
                        Call stackPushV(stack, length, CreateFindNode(.depth + 1, child))
                    Next
                Case EAccFindResult.MatchFound, True, EAccFindResult.MatchFoundSearchDescendents
                    'Found, return element
                    Set FindFirst = .element
                    Exit Function
                Case EAccFindResult.NoMatchCancelSearch
                    'Nothing found, cancel function
                    Set FindFirst = Nothing
                    Exit Function
                case EAccFindResult.NoMatchSkipDescendents
                '    Nothing found, don't search descendents
            End Select
        End With
        'Just make sure no freezing occurs
        DoEvents
    Wend

    'Else set to nothing
    Set FindFirst = Nothing
End Function

Expected behavior

I would expect function declares are meant to be listed alone?

SSlinky commented 4 months ago

I noticed this during development too, but thought it might just be a VSCode thing. I haven't specifically developed anything for the mini map. I'll look into it though.

sancarn commented 4 months ago

Ahhh it could have something to do with code-folding...

sancarn commented 4 months ago

Found the relevant PR: https://github.com/microsoft/vscode/pull/190759

It adds section headers to the minimap, sourced from region markers

So my guess is some areas are being marked as regions by the grammar (or something) which shouldn't be?

SSlinky commented 4 months ago

Yes, good call. After some digging, I figured out the client extension is flagging folding ranges as named regions. Removing that section from vba.language-configuration.json removes the names from the minimap. You can also disable this with "editor.minimap.showRegionSectionHeaders": false.

image

Now to figure out why it thinks folding ranges are regions...

SSlinky commented 4 months ago

Resolved in 5e425d8 but not worth publishing a patch.