vs-editor-api icon indicating copy to clipboard operation
vs-editor-api copied to clipboard

Please add more documentation around ITextViewModelProvider

Open ymassad opened this issue 3 years ago • 12 comments

It is not documented how an extension developer can create their own implementation of ITextViewModelProvider and how such implementation can be used by Visual Studio. Please add more details about this interface.

ymassad avatar Jul 02 '20 18:07 ymassad

I filed a doc bug to improve the documentaiton. ITextViewModelProvider is pretty esoteric extensibility point, it only useful in advanced scenarios, for example to support virtual documents. What are you trying to achieve, @ymassad ?

olegtk avatar Jul 07 '20 18:07 olegtk

I am trying to create a custom editor that contains text from multiple text buffers.

ymassad avatar Jul 07 '20 18:07 ymassad

That's a standard scenario (cshtml, aspx, razor files use it) supported through projection: https://docs.microsoft.com/en-us/visualstudio/extensibility/inside-the-editor?view=vs-2019#projection, I don't think you need ITextViewModelProvider for that

olegtk avatar Jul 07 '20 19:07 olegtk

The page you mentioned talks about projection buffers from a "text buffer" perspective. How would one use such a buffer in an editor?

ymassad avatar Jul 07 '20 20:07 ymassad

VS "editor" is ITextView control over a single ITextBuffer representing document in a file. In projection case ITextBuffer is actually IProjectionBuffer, created via IProjectionBufferFactoryService.CreateProjectionBuffer and which represents more than one ITextBuffer projected into one. See also https://stackoverflow.com/a/37290780.

Can you share more details about what are you trying to achieve?

olegtk avatar Jul 07 '20 20:07 olegtk

Given an ITextBuffer, how would you create a view? Is there a TextViewFactory that one can use?

I was reading the following article:

https://joshvarty.com/2014/08/01/ripping-the-visual-studio-editor-apart-with-projection-buffers/

Where ITextViewModelProvider is used, and I wanted to understand why it works.

Regarding what I am trying to achieve, I want to hide certain text from an editor (CSharp ContenTtype) and also add text (just in the view, not the .cs files). If this is possible in the standard editor of VS then that is great. If not, I want to create a new editor window like the one in https://joshvarty.com/2014/08/01/ripping-the-visual-studio-editor-apart-with-projection-buffers/

I was able to do the later using ITextViewModelProvider, but I need to understand the code that I am writing and why it works.

ymassad avatar Jul 08 '20 07:07 ymassad

Yes, it's supported, that's how cshtml, aspx or razor files work - they project content from 2 files (e.g. aspx and generated cs files containing C# portion of aspx). Where is the added text is originating from? Do you actually want it to be part of the projected text buffer (so that user can select/copy it just like C# code) or you only need it as a adornment displayed inline of C# code (like Debugger tips or Code Lens above every method in C# for example)?

olegtk avatar Jul 08 '20 20:07 olegtk

And you create text view using ITextEditorFactoryService.

olegtk avatar Jul 08 '20 20:07 olegtk

Thanks @olegtk

I want to replace some C# code with things like adornments. I did successfully replace these pieces of code with adornments but one issue is that you lose some VS features like IntelliSense and the squiggles in case of error or warning. I tried also successfully to create outlining to "replace" the C# code with other text. This has the nice feature of allowing the user to see the read code behind the "adornments". And if the user double clicks on an error in the error list VS automatically expands the outlining region and shows the error. Still not sure if this is a good option. The plus sign on the left is usually associated with real regions and it might confuse users.

I am exploring all these options to figure out exactly how I am going to implement the requirement.

I was exploring the option to create a new editor where I can add or remove code (via the projection buffer) and that's when ITextViewModelProvider came up.

In general, I found the documentation of visual studio extensibility to be lacking.

ymassad avatar Jul 09 '20 14:07 ymassad

Sorry, still not entirely sure what are you trying to achieve...

olegtk avatar Jul 10 '20 00:07 olegtk

@olegtk , I, my self, am not sure what is the exact behavior that I need. In any case, there are only a finite amount of behaviors that can be achieved with Visual Studio extensibility.

I am exploring different VS extensibility features and testing them and attempting to use them to see if they will help make the experience of devs who will use my product better. The product involves a lot of code generation and I would like to hide the names of some generated C# classes that the users have to put in their code.

While doing such exploration, I came across ITextViewModelProvider and I think the documentation around it lacks.

I think that the documentation of VS extensibility should be detailed enough to enable anyone to explore them and see how they can help them. I hope you agree.

ymassad avatar Jul 10 '20 11:07 ymassad

One piece of the puzzle is missing. How to connect custom created IProjectionBuffer with existing ITextView or how to connect custom created ITextView with existing VS Editor. ITextViewModelProvider gave such an opportunity, but it seems that it is not working since version 2019.3 of VS.

I really would like to see a sample showing how to achieve something like cshtml/aspx with the help of IProjectionBuffer and without creating a custom editor. As I checked razor repository, they do not use IProjectionBuffer to achieve that result of mixing two languages in one view.

NeVeSpl avatar Nov 29 '20 18:11 NeVeSpl