nosami / XSVim

[Obsolete] Vim emulation layer for Xamarin Studio / Visual Studio for Mac
MIT License
158 stars 12 forks source link

Support the new C# Editor #252

Open akamud opened 5 years ago

akamud commented 5 years ago

Since VS for Mac 2019 has the new C# Editor that uses the same core from VS 2019 with a lot of improvements, probably everyone will start using the new editor when it leaves preview, so having XSVim working with that is a must. Actually, that is exactly why I am not using the new editor ATM.

Are you working on this already? Do you have any guideline if anyone wants to start working on this?

nosami commented 5 years ago

Hi. This is definitely on my list of stuff to do but I'm not sure where to start with it either :)

It's further complicated by having both editors in VS for Mac 2019. We probably need to support both editors until the old one is deprecated.

nosami commented 5 years ago

Here is a transcript of a chat I had on Slack with some of the guys who worked on the new editor. Maybe it helps.

Jason Imison  
Are there any extensibility APIs with the new editor? like TextEditorExtension for the old editor?
Sandy Armstrong  
there are a bunch of interfaces you can export into MEF
it's pretty different from TextEditorExtension
but for example you can export an ITextViewCreationListener to know when there are new editors created
Jason Imison  
ok, I see. thanks!
David Karlaš  
there are also ICommandHandler<NameOfCommandArgs>
which has GetState of command and Execute command
Jason Imison  
thanks
David Karlaš  
I think it’s best if you trying to achive something to ask and we can brainstorm what best aproach would be
other good way aproaching is finding similar usecase inside editor code itself
Jason Imison  
Well... I was just thinking about my vim addin :)
David Karlaš  
is VSWin addin open source?
Jason Imison  
yeah
David Karlaš  
you can copy probably ALOT
Jason Imison  
yeah... I should see how that hooks in
David Karlaš  
problem might be with commands
Jason Imison  
would actually be awesome to not have to maintain that any more
David Karlaš  
if it’s using old IOleCommands
but those map 1to1 to new ICommandHandler
nosami commented 5 years ago

To get an Addin assembly loaded into MEF

    <Extension path="/MonoDevelop/Ide/Composition">
        <Assembly file="XSVim.dll" />
        </Extension>
corliss commented 5 years ago

Hi, I just upgraded to VSMac 8.1 build 2306, where the new C# editor has been made the default. Vim mode does not work in the new editor, so I turned off the new editor via Preferences. But now the editor doesn't work at all - the block cursor doesn't move. Tried uninstalling & reinstalling the Vim plugin. But could not reinstall - the Vim plugin no longer appears in the Gallery.

As this is a Preview build, I switched back to the Stable channel and now life is good again. This is an important plugin! - will the version that supports the new editor be available soon, please?

nosami commented 5 years ago

@corliss I have a build ready that should work with 8.1 soon. Not the new editor though - that will take a lot longer.

nosami commented 5 years ago

@corliss you can try https://github.com/nosami/XSVim/releases/download/0.65.3.81/XSVim.XSVim_0.65.3.81.mpack for VSMac 8.1. It's mostly untested though. Update - latest 8.1 build is available on the feed

nosami commented 5 years ago

@nosami, thanks for the quick response. Since I'm back to the Stable channel, will hold off until a tested build of XSVim is available.

I did try building and poking around with the XSVim code, but didn't get very far:

  1. How exactly do we debug the plugin? The run_from_source.sh script seems to load the solution as well as install the plugin in the VSMac instance. How does it do this? - the script is just a one-liner which has nothing related to installing the plugin as far as I can tell.

MONODEVELOP_DEV_ADDINS=$(pwd)/XSVim/bin/Debug is the important part. It sets an environment variable that tells VSMac where to look for extra addins.

The way that I debug is to launch a 2nd instance of VSMac from one running the XSVim source code - like this (Make sure that the XSVim branch that you are on is compatible with the version of VSMac - branch 81 for VSMac 8.1 and check the paths):

image

Also, it's possible to debug unit tests using just a single instance.

  1. In some situations, the debug instance of VSMac has a non-working menu bar. Any idea why?

No, sorry. Take a look in the log file and see if you can spot any exceptions.

  1. Do you have a broad idea of what the changes might be to work with the new editor? I'm guessing that some of the host interfaces in the MonoDevelop.Ide.Editor namespace will need to be replaced by their counterparts in the Microsoft.VisualStudio.Text.Editor namespace. If you could provide a short summary, I might be able to pitch in.

You know about as much as me now :)

  1. Since the new editor is only for C#, do you plan to have a single plugin (i.e. the current situation), or two separate plugins? The latter might be cleaner if a lot needs to be reworked, after which a re-unification of the separate assemblies could take place.

I'm not 100% sure, but I did think about having 2 separate Addins. At some point the new editor will work for all file types.

  1. Finally, do you think that the new hosting interfaces are similar enough to VS Windows that the VSVim code could be used as a starting point?

I spoke to @JaredPar about this. This is what he had to say about it.

[02/05 21:51] Jared Parsons
    If you clone the project and open the solution you'll see a project named VimApp. That's just a simple WPF app that hosts the editor and VsVim. It's an easy way for me to test out my changes and isolate VS from editor bugs.
​[02/05 21:52] Jared Parsons
    For someone who understood VsMac probably not much.
​[02/05 21:53] Jared Parsons
    Mostly it's just getting a MEF composition together, authoring an IVimHost implementation, exporting the IVimHost implementation, and then deciding what parts of the host you want to fill out. 
​[02/05 21:53] Jared Parsons
    You wouldn't get a block caret at first because that's in the WPF layer. That would need to be re-implemeneted on VSMac. 
​[02/05 21:54] Jared Parsons
    The IVimHost interface has lots of functions like CloseView, GoToDef. The logic expects them to all fail though so the host can be very minimal at first. 

It might be easier to port VSVim to Mac than it is to port XSVim to the new editor. I don't really have much idea of how much effort that would be at this point, especially as I'm not familiar at all with how the new editor works.

Cheers!

nosami commented 5 years ago

@corliss Not sure how you managed to comment from the future 🙂 image

My reply has finished above your last comment :)

corliss commented 5 years ago

Let's hope git doesn't have the same reordering problems as GitHub! I deleted my previous comment since it appeared after this one, too.

Thanks for the detailed response. VsVim deserves a closer look - from the above it looks like it is already platform-independent, just requiring a host implementation.

If you could please update this issue when a smoke-tested version of the 8.1 plugin is available I will upgrade again and start experimenting.

Cheers.

bmatzelle commented 5 years ago

@nosami have you had the time to work on updating XSVim to work with 8.1? is there a way to get XSVim working without installing the old version of VSMac?

nosami commented 5 years ago

@bmatzelle There is a version of XSVim that works with 8.1 but you need to make sure that you use the old editor (the new editor is the default in 8.1)

image

bmatzelle commented 5 years ago

That did it. Thanks!

nosami commented 5 years ago

I am working on porting VSVim to Mac here I guess this extension won't be needed at some point in the future as the old editor is used less and less.