3

I am developing an extension for visual studio code using language server protocol, and I am including the support for "Go to symbol in workspace". My problem is that I don't know how to select the matches... Actually I use this function I wrote:

function IsInside(word1, word2)
{
    var ret = "";
    var i1 = 0;
    var lenMatch =0, maxLenMatch = 0, minLenMatch = word1.length;
    for(var i2=0;i2<word2.length;i2++)
    {
        if(word1[i1]==word2[i2])
        {
            lenMatch++;
            if(lenMatch>maxLenMatch) maxLenMatch = lenMatch;
            ret+=word1[i1];
            i1++;
            if(i1==word1.length)
            {
                if(lenMatch<minLenMatch) minLenMatch = lenMatch;
                // Trying to filter like VSCode does.
                return maxLenMatch>=word1.length/2 && minLenMatch>=2?  ret : undefined;
            }
        } else
        {
            ret+="Z";
            if(lenMatch>0 && lenMatch<minLenMatch)
                minLenMatch = lenMatch;
            lenMatch=0;
        }
    }
    return undefined;
}

That return the sortText if the word1 is inside the word2, undefined otherwise. My problem are cases like this:

**strong text**

My algorithm see that 'aller' is inside CallServer, but the interface does not mark it like expected.

There is a library or something that I must use for this? the code of VSCode is big and complex and I don't know where start looking for this information...

Gama11
  • 31,714
  • 9
  • 78
  • 100
Perry
  • 1,113
  • 2
  • 10
  • 22

1 Answers1

1

VSCode's API docs for provideWorkspaceSymbols() provide the following guidance (which I don't think your example violates):

The query-parameter should be interpreted in a relaxed way as the editor will apply its own highlighting and scoring on the results. A good rule of thumb is to match case-insensitive and to simply check that the characters of query appear in their order in a candidate symbol. Don't use prefix, substring, or similar strict matching.

These docs were added in response to this discussion, where somebody had very much the same issue as you.

Having a brief look at VSCode sources, internally it seems to use filters.matchFuzzy2() for the highlighting (see here and here). I don't think it's exposed in the API, so you would probably have to copy it if you wanted the behavior to match exactly.

Gama11
  • 31,714
  • 9
  • 78
  • 100
  • Thanks, I see that github should be only for issue report and I did not search inside issues... – Perry Feb 01 '19 at 06:52