question

werat avatar image
0 Votes"
werat asked TianyuSun-MSFT commented

Implementing custom code-completion for the Immediate Window

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://docs.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://docs.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

vs-extensions
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @werat , welcome to Microsoft Q&A forum. The official document doesn’t provide more information, the Remarks should be the important(key) information. Perhaps you need to check the Remarks again and try to meet the requirements that it pointed.

This interface is called by the command window of the environment and is accessed by calling QueryInterface on the same object that implements IVsLanguageInfo.

This interface was created when statement completion support was added to the Watch Window, and the support for multiple filters in the language was required…

0 Votes 0 ·

Hi, I've checked the Remarks section, but it's not very helpful either. I've implemented my language service like this -- MyLanguageService : IVsLanguageInfo, IVsImmediateStatementCompletion2, i.e. interface is implemented on the same object that implements IVsLanguageInfo (as the remark says). However something else is missing, because none of the methods of IVsImmediateStatementCompletion2 are ever called.

0 Votes 0 ·

Hi @werat , do you also meet the requirement that this sentence “This interface was created when statement completion support was added to the Watch Window, and the support for multiple filters in the language was required” points?

0 Votes 0 ·
Show more comments

0 Answers