Implementing custom code-completion for the Immediate Window

Andy Hippo 1 Reputation point
2021-05-09T08:21:14.29+00:00

Hi everyone!

I'm working on an extension that provides a custom debug engine for Visual Studio -- https://github.com/googlestadia/vsi-lldb. The debug engine is similar to MIEngine (https://github.com/microsoft/MIEngine). The underlying debugger is LLDB and the extension provides all the necessary integrations (attach, stepping, natvis and expression evaluation, etc).

My question is about implementing custom code-completion in the Immediate Window.

The expressions in the Immediate Window are handled by IDebugExpressionContext2 [1] and IDebugExpression2. This works fine, when the user enters the expressions and hits Enter IDebugExpressionContext2::ParseText is invoked, IDebugExpression2 object is created and the expression is eventually evaluated [2].

Now I want to implement basic code-completion for the expressions in the Immediate Window. For example, to show a list of members when the user types foo-> and such. I can easily do this using my expression evaluation engine (https://github.com/google/lldb-eval), but I can't figure out how to implement it in Visual Studio.

I have found an interface IVsImmediateStatementCompletion2 [3]. Looking at the name, this seems like exactly what I want :) However I'm not sure how what is the proper way to implement this interface. The documentation says this interface should be implemented on the same object that implements IVsLanguageInfo -- this matches what I see in Roslyn [4].

My extension currently doesn't provide a language service implementation, only the debug engine. I've tried adding a dummy implementation like class MyLanguageService : IVsLanguageInfo, IVsImmediateStatementCompletion2 and registering it via [ProvideLanguageService] and [ProvideService]. After I registered it for ".cpp" files, I can see that methods for IVsLanguageInfo are being called (namely GetColorizer and GetCodeWindowManager), but IVsImmediateStatementCompletion2 is never triggered.

So here's the big question, how do I implement a custom completion for the Immediate Window in my DebugEngine? Thanks!

[1] https://learn.microsoft.com/en-us/visualstudio/extensibility/debugger/reference/idebugexpressioncontext2?view=vs-2019
[2] https://github.com/googlestadia/vsi-lldb/blob/121d52b74564a51dc7e860c7c1eb9729b20627b3/YetiVSI/DebugEngine/DebugStackFrame.cs#L222
[3] https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.textmanager.interop.ivsimmediatestatementcompletion2?view=visualstudiosdk-2017
[4] https://github.com/dotnet/roslyn/blob/dd21600f51cf5464b4721b69ab1c8e86bfa0c101/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService%602.IVsImmediateStatementCompletion2.cs#L20

Community Center Not monitored
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.