Search code examples
c#visual-studio-2015vs-extensibility

Provide intellisense for custom language in Visual Studio when caret is in virtual space


I'm developing an extension for visual studio that provides intellisense for a custom language.
So far I started with this sample, more specifically this code. Sadly, this sample (and all others I've seen on the internet) has problems with virtual spaces. When the cursor is placed in such a virtual space, the triggerPoint that is obtained with session.GetTriggerPoint(snapshot) is set back to the non-virtual position before the cursor (and as far as I know, SnapshotPoint can only represent non-virtual positions) which leads to a wrongly positioned intellisense window: Screenshot

How can I fix this? I tried to understand how it is done in the roslyn extension, but that code is horrific complicated (it seems like ~5k LOC and ~100 classes just for autocompletion).


Solution

  • By the way, I managed to find the code that is responsible for that in roslyn:

    if (this.TextView.Caret.Position.VirtualBufferPosition.IsInVirtualSpace)
    {
        // Convert any virtual whitespace to real whitespace by doing an empty edit at the caret position.
        _editorOperationsFactoryService.GetEditorOperations(TextView).InsertText("");
    }