Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Please add more documentation around ITextViewModelProvider #25

Open
ymassad opened this issue Jul 2, 2020 · 12 comments
Open

Please add more documentation around ITextViewModelProvider #25

ymassad opened this issue Jul 2, 2020 · 12 comments

Comments

@ymassad
Copy link

ymassad commented Jul 2, 2020

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.

@olegtk
Copy link
Member

olegtk commented Jul 7, 2020

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 ?

@ymassad
Copy link
Author

ymassad commented Jul 7, 2020

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

@olegtk
Copy link
Member

olegtk commented Jul 7, 2020

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

@ymassad
Copy link
Author

ymassad commented Jul 7, 2020

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

@olegtk
Copy link
Member

olegtk commented Jul 7, 2020

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?

@ymassad
Copy link
Author

ymassad commented Jul 8, 2020

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.

@olegtk
Copy link
Member

olegtk commented Jul 8, 2020

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
Copy link
Member

olegtk commented Jul 8, 2020

And you create text view using ITextEditorFactoryService.

@ymassad
Copy link
Author

ymassad commented Jul 9, 2020

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.

@olegtk
Copy link
Member

olegtk commented Jul 10, 2020

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

@ymassad
Copy link
Author

ymassad commented Jul 10, 2020

@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.

@NeVeSpl
Copy link

NeVeSpl commented Nov 29, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants