Sam's Blog

25 Mar

Visual Studio language services: Improved brace matching hooks

By default, brace matching is performed in response to the left and right arrow keys. It should be done in response to several additional commands, as shown below.

Movement by clicking the mouse is handled in your override of ViewFilter.HandlePreExec:

1
2
3
4
5
6
7
8
9
10
public override bool HandlePreExec( ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut ) 
{ 
    if ( guidCmdGroup == VSConstants.VSStd2K ) 
    {
        if ( (VsCommands2K)cmd == VsCommands2K.ECMD_LEFTCLICK )
            base.Source.OnCommand( base.TextView, (VsCommands2K)cmd, '\0' );
    }
 
    return base.HandlePreExec( ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut );
}

Movement by keystrokes is handled in your override of ViewFilter.HandlePostExec:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public override void HandlePostExec( ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut, bool bufferWasChanged )
{
    if ( guidCmdGroup == VSConstants.VSStd2K )
    {
        switch ( (VsCommands2K)nCmdId )
        {
        case VsCommands2K.LEFT_EXT_COL:
        case VsCommands2K.RIGHT_EXT_COL:
        case VsCommands2K.UP:
        case VsCommands2K.UP_EXT:
        case VsCommands2K.UP_EXT_COL:
        case VsCommands2K.DOWN:
        case VsCommands2K.DOWN_EXT:
        case VsCommands2K.DOWN_EXT_COL:
        case VsCommands2K.HOME:
        case VsCommands2K.HOME_EXT:
        case VsCommands2K.BOL:
        case VsCommands2K.BOL_EXT:
        case VsCommands2K.BOL_EXT_COL:
        case VsCommands2K.FIRSTCHAR:
        case VsCommands2K.FIRSTCHAR_EXT:
        case VsCommands2K.EOL:
        case VsCommands2K.EOL_EXT:
        case VsCommands2K.EOL_EXT_COL:
        case VsCommands2K.LASTCHAR:
        case VsCommands2K.LASTCHAR_EXT:
        case VsCommands2K.PAGEUP:
        case VsCommands2K.PAGEUP_EXT:
        case VsCommands2K.PAGEDN:
        case VsCommands2K.PAGEDN_EXT:
        case VsCommands2K.WORDNEXT:
        case VsCommands2K.WORDNEXT_EXT:
        case VsCommands2K.WORDNEXT_EXT_COL:
        case VsCommands2K.WORDPREV:
        case VsCommands2K.WORDPREV_EXT:
        case VsCommands2K.WORDPREV_EXT_COL:
        case VsCommands2K.BOTTOMLINE:
        case VsCommands2K.BOTTOMLINE_EXT:
        case VsCommands2K.TOPLINE:
        case VsCommands2K.TOPLINE_EXT:
            // check general trigger characters for intellisense
            base.Source.OnCommand( base.TextView, (VsCommands2K)nCmdId, '\0' );
            break;
        }
    }
 
    base.HandlePostExec( ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut, bufferWasChanged );
}

Leave a Reply

© 2024 Sam's Blog | Entries (RSS) and Comments (RSS)

Your Index Web Directorywordpress logo