C# Intellisense #12

Closed
shirhatti opened this Issue Aug 5, 2014 · 79 comments

Projects

None yet
@shirhatti
Member

C# Intellisense

Investigating using Roslyn (In-memory C# compiler) and DesignTimeHost to provide code completions in Sublime

Initial Prototype

Initial prototype lives at SublimeSharp

C# Intellisense

@jchannon
Contributor
jchannon commented Aug 6, 2014

To confirm we need the WebAPI app running in the background to get the plugin to give output?

@shirhatti
Member

Yes. The API should run at http://localhost:5000

The plugin.py should be added to your packages directory

This is a Windows-only prototype at the moment

@shirhatti shirhatti closed this Aug 6, 2014
@shirhatti shirhatti reopened this Aug 6, 2014
@shirhatti
Member

@jchannon I wrote a Powershell one-liner that makes installing the Sublime Plugin easier

(Invoke-WebRequest http://shirhatti.com/Plugin.sublime-package).Content >((Get-ChildItem Env:APPDATA).Value + '\Sublime Text 3\Installed Packages\Plugin.sublime-package')

To remove the Plugin

Remove-Item ((Get-ChildItem Env:APPDATA).Value + '\Sublime Text 3\Installed Packages\Plugin.sublime-package')

Edit

If you want to try it out without running the WebAPI try

Mac

wget http://shirhatti.com/Pluginnobackend.sublime-package -P ~/Library/Application\ Support/Sublime\ Text\ 3/Installed\ Packages

Windows

(Invoke-WebRequest http://shirhatti.com/Pluginnobackend.sublime-package).Content >((Get-ChildItem Env:APPDATA).Value + '\Sublime Text 3\Installed Packages\Plugin.sublime-package')
@glennblock

Nice progress @shirhatti!

@jchannon
Contributor
jchannon commented Aug 6, 2014

Nice!

I'm wondering if we try and get this working via Omnisharp as that has all the functionality we need at the moment. Its tied to NRefactory though so there would be effort needed to move Omnisharp across to Roslyn once that is complete.

Thoughts?

UPDATE: There is currently this https://github.com/moonrabbit/OmniSharpSublime but @nosami had to hack it to work and some of the features don't seem to work but the base is there. Do we try and get that into a stable state?

@Mpdreamz
Mpdreamz commented Aug 6, 2014

HI Guys I would love this.

I did some work try to port the typescript plugin for sublime from 2 to 3. It followed the exact same approach: typescript language services hosted somewhere and using HTTP to get errors/intellisense suggestions.

OmniSharpServer follows the same paradigm, I love the work @nosami did but his initial estimations are that its quite some work

OmniSharp/omnisharp-server#75

Maybe the two projects could benefit from a common API ?

@nosami
nosami commented Aug 6, 2014

NRefactory has already started to implement intellisense using Roslyn - see https://github.com/icsharpcode/NRefactory/blob/roslyn/ICSharpCode.NRefactory.CSharp/Features/Completion/CompletionEngine.cs and they are making headway on rewriting their automated code issues / refactorings.

It's actually quite simple - but there is no point in making the switch over until the refactorings are ported over to Roslyn. OmniSharp server gives you much more than intellisense - https://github.com/nosami/OmniSharpServer/tree/master/OmniSharp

If I made the switch over to using the Roslyn branch of NRefactory now, you would lose quite a bit of functionality.

If I dropped the NRefactory dependency and switched over to Roslyn, the OmniSharp server would be much simpler than it is now I think, but it wouldn't have any refactorings.

At this moment in time, the only way to get the best of both would be for OmniSharp to have two ASTs in memory for each file, the Roslyn version and the NRefactory version. That seems a little excessive, although doable.

Really I think the best solution is to just wait for NRefactory to finish their porting work. Then OmniSharp server should just work against Roslyn without too many changes. I won't be changing any of the public API regardless.

@nosami
nosami commented Aug 6, 2014

I should probably add that you can already do Asp.Net vNext programming with https://github.com/nosami/Omnisharp and https://github.com/sp3ctum/omnisharp-emacs today :)

If I were a Sublime user, I'd build it myself. I estimate a couple of days work to get all features into the client.

The only downside (?) is that it's not using Roslyn (yet).

@glennblock

@nosami very cool to see this. Shameless plug but scriptcs users would definitely love this.

@shirhatti
Member

@nosami I wasn't aware that NRefactory has started to use Roslyn. I agree with your assessment that the best solution is to wait for NRefactory to finish their porting work.
I will try to use your public API on my Sublime extensibility so as to best leverage your awesome work with OmniSharp. Can you link me to your API documentation?

@astralhpi Do you have any plans to implement this with moonrabbit/OmniSharpSublime ?

+cc @sayedihashimi @shanselman for thoughts?

@jchannon
Contributor
jchannon commented Aug 6, 2014

@shirhatti OmniSharpSublime already uses OmniSharp it just needs a bit of polish as @nosami and I had to hack it to get it working with Sublime

alt

@nosami
nosami commented Aug 6, 2014

@shirhatti I'm afraid I don't have any documentation but it's not too difficult to work out.

You just need to start the server using the instructions here https://github.com/nosami/OmniSharpServer

This is an early version of a POC that me and @PaulCampbell built for sublime -
https://github.com/PaulCampbell/OmniSharpSublimePlugin/blob/efb9fd8a66e5b75ac8647685b28edf86066331bc/OmniSharp.py

The @moonrabbit version is nicer code, but I think this illustrates better how to interact with the server. This code is using standard form posts (x-www-form-urlencoded) to make a request to the server, but you can also send the parameters as a JSON object if you prefer.

If you don't care about getting documentation for each completion result (uses MonoDoc on *nix which is slow) then you probably want to add :-

parameters['WantDocumentationForEveryCompletionResult'] = false

The OmniSharp code is broken up into a feature per folder (almost). You can figure out the requests by looking at the Request.cs in each folder, e.g. https://github.com/nosami/OmniSharpServer/blob/master/OmniSharp/AutoComplete/AutoCompleteRequest.cs

@jchannon
Contributor
jchannon commented Aug 6, 2014

Also we need to consider the current ST3 plugin wants a sln file but we
know it works for ASPNet vNext by just passing the folder path. This was
part of the hack we did to get it working

@sayedihashimi
Member

Adding @davidfowl to see if he has thoughts on this?

@jchannon
Contributor
jchannon commented Aug 7, 2014

I've created a PR for the ST3 plugin so we don't have to hack it to work OmniSharp/omnisharp-sublime#5

@jchannon
Contributor
jchannon commented Aug 7, 2014

I've been in touch with https://dotnetfiddle.net/ who provide intellisense in the browser. They use Roslyn apparently and I have managed to convince them to OSS their intellisense code so we can take a look https://twitter.com/sergey_litvinov/status/497391229068247041

@davidfowl

Omnisharp won't work by itself, you'll need to run the design time host since we don't use csproj files.

@nosami
nosami commented Aug 7, 2014

Omnisharp doesn't need csproj files either.

On Thu, Aug 7, 2014 at 4:23 PM, David Fowler notifications@github.com
wrote:

Omnisharp won't work by itself, you'll need to run the design time host
since we don't use csproj files.


Reply to this email directly or view it on GitHub
#12 (comment).

@jchannon
Contributor
jchannon commented Aug 7, 2014

@davidfowl we already have vnext nancy app working without csproj with omnisharp

@sayedihashimi
Member

Visual Studio uses this same Design Time Host that @davidfowl mentions. If we can hook that up 👆 o it's likely to be the best option.

We have worked on a prototype and make some progress already.

@Shirhatti can you give an update on DTH and describe what it will take to enable IntelliSense with it?

@davidfowl

It's not the best option it's really the only option. The design time host is the way to get the lost of resolved references, source files, compilation settings etc from a vnext project system. Anything else you do would be an estimation and would probably be inaccurate.

You can get the same effect by running through the vnext runtime's code paths but that's exactly what the design time host does.

@nosami
nosami commented Aug 7, 2014

@davidfowl Sounds great. I should integrate that with OmniSharp from the sound of it. I wondered how to deal with that.

@shirhatti
Member

Adding this for reference.
DTH output- https://gist.github.com/shirhatti/2a76b9cba1e9a9f0aed1

@nosami
nosami commented Aug 7, 2014

Does the DTH work outside of Windows?

@davidfowl

There's a bug somewhere because of a missing socket ctor. But we should be able to make that work well.

@sayedihashimi
Member

FYI my hope is that we can leverage DTH for most of the heavy lifting and then we include a thin layer to integrate into Sublime. That way others can look at the Sublime Extension and then add support in other editors. Hopefully we can make it really easy to snap ASP.NET vNext into any toolset.

@jchannon
Contributor
jchannon commented Aug 8, 2014

So do we need to make some decisions of the route we're taking and how we'll achieve intellisense, refactoring etc?

@davidfowl

The way I see it there's 3 major pieces:

  • The project system
  • The intellisense engine
  • The editor/ui

The project system has information about the relationships between projects, and has information about each project (references, configurations, source files etc). It can also give you errors and warnings. (Design time host)

The intellisense engine takes information from the project system and is aware of open buffers and can produce a set of "completions" for a particular type (and maybe other things like refactoring). (NRefactory/Rosyln Workspaces)

The editor can popup UI at the appropriate place and talk to the intellisense engine about the active buffer and project and show the right suggestions in the right place. (Sumblime python thingy)

@Mpdreamz
Mpdreamz commented Aug 8, 2014

Genuine question out of interest on the direction this discussion is going:

Is there going to be a "new OmniSharpServer" specifically for the vNext ecosystem blessed by the asp.net team or are we looking to integrate with OmniSharpServer ?

Not claiming to have the wisdom to know which direction is the best but my gut feeling is that integrating with OmniSharpServer should at least be explored.

@davidfowl

The only vNext specific piece is the design time host. Ideally the ominsharp server would have an adapter model for getting information from the project and we would just plug into it. Everything else should just work.

@sayedihashimi
Member

What's the best way for us to make progress here? How about a conf call or jabbr group chat?

FYI I'm on vacation this week so I'm a little slow 🐌 now but will pick up pace when I'm back.

@jchannon
Contributor

I'm easy but I'm away w/c 13th Aug but I should think @nosami is the main man for this 😄

@nosami
nosami commented Aug 13, 2014

Jabbr group chat sounds like a good idea to me.

@sayedihashimi
Member

Ok thanks I'm back from vacay 8/19, I will work with you guys when I get back on setting up the group jabber chat.

cc @davidfowl @Shirhatti @shanselman @madskristensen

@sayedihashimi
Member

Ok I will try and setup tome for us to meet on jabbr on Friday 8/29. Who are the required attendees? I'm thinking the following list.

How about 4PM Pacific Time on 8/29? If that time doesn't work please reply back with your time zone and available times.

@nosami
nosami commented Aug 22, 2014

It's fine with me although a little late. I'm on GMT time so that will be midnight here.

@jchannon
Contributor

Same as Jason too so would be a bit late and I need my beauty sleep 😉

@sayedihashimi
Member

OK how about 8/29 1PM Pacific Time? Is that too late? If so I'll look for some alternate times around 11AM next week. Which is best for you guys?

@nosami
nosami commented Aug 28, 2014

1PM Pacific Time is fine for me on any day other than Friday :)

@sayedihashimi
Member

I will find a time that works for @davidfowl and myself for next week and proppse here soon.

@sayedihashimi
Member

OK how is Wed 9/3 at 12PM Pacific Time? I've proposed that time to @davidfowl and @shanselman.

@shirhatti
Member

I can't do Wednesday mornings. I can do Tuesday or Thursday mornings. If Wednesday works for everybody else I'll sync up with @sayedihashimi offline

@jchannon
Contributor

Wed is fine for me

@nosami
nosami commented Aug 29, 2014

Wednesday is fine, as is any other day Mon-Thurs

@sayedihashimi
Member

@shirhatti that would be Wed afternoon for you, either 2PM or 3PM depending on timezone.

@nosami @jchannon what do you think of doing a Skype video chat? @shanselman was suggesting that as an option over jabbr. Thoughts?

@jchannon
Contributor

Yup fine by me 😄

@nosami
nosami commented Aug 29, 2014

Sure, Skype is fine.

@Mpdreamz

I didn't make the required list but would love to be able to eavesdrop, pitch in if at all possible. If there is a spot on the skype chat I would love to join.

@sayedihashimi
Member

@Mpdreamz this is a community effort so everyone is welcome. The required list was to identify the folks we can't make progress without.

@shanselman is there a limit on the number of attendees on Skype? How should these guys get the info to join?

@shanselman
Member

I think the limit is 25 people for a Skype Group call. Post your Skype names.

@sayedihashimi
Member

OK I think that should more than enough.

@sayedihashimi sayedihashimi added this to the 1.0 milestone Sep 2, 2014
@nosami
nosami commented Sep 2, 2014

Mine is jasonimison1

@sayedihashimi
Member

Mine is sayed.ibrahim.hashimi

@jchannon
Contributor
jchannon commented Sep 3, 2014

Mine is jchannonwinplc

@Mpdreamz
Mpdreamz commented Sep 3, 2014

mine is mpdreamz

@sayedihashimi
Member

@shirhatti @jchannon @nosami @Mpdreamz @shanselman @davidfowl @glennc I have posted meeting notes from today at https://github.com/ligershark/Kulture/wiki/Initial-meeting---2014.08.03. Feel free to edit that doc as you like.

I'm really excited about this. Let's see what we can build together.

@jchannon
Contributor
jchannon commented Sep 4, 2014

Regarding my action point, was your thought to pull in OmniSharpSublime into the Kulture plugin ie/make it a dependency?

@sayedihashimi
Member

@jchannon I don't think that it needs to be a dependency. We can add that to the install guide for readme.md.

@jchannon
Contributor
jchannon commented Sep 8, 2014

Done!

Do you think its worth setting a list of items that we definitely want from OmniSharpSublime then a list of "nice to haves"?

I've done PRs for it regarding making sure it has the latest OmniSharpServer version and I've done Find Usages for it (not merged as of yet) but was going to do something else next but then thought you guys might want something specific?

@bmsullivan
Contributor

I saw the info added to the readme about this and tried to get it working on my Mac yesterday. I managed to get the OmniSharpSublime server running and could see requests and responses from it in the Sublime console as I typed, but the responses didn't contain anything that looked like completion options.

Is this actually supposed to work with ASP.NET vNext yet, or is there more work to do there?

@Kuzirashi
Contributor

@bmsullivan I had to download latest version of OmniSharpServer instead of that one supplied with OmniSharpSublime repository and build it to got this working.

@bmsullivan
Contributor

@Kuzirashi Thanks, I'll try that!

@jchannon
Contributor
jchannon commented Sep 8, 2014

Yes there is outstanding PRs on OmniSharpSublime to make sure it uses latest OmnisharpServer. Fingers crossed it gets merged ASAP

@Kuzirashi
Contributor

@bmsullivan
I had also problems with running OmniSharpServer(missing symbolic link to library System.Core.Dll) on Ubuntu 14.04 so make sure that your fresh build of latest OmniSharpServer is actually runnable from command line via Mono.

@bmsullivan
Contributor

Updating to the latest OmniSharpServer did the trick! Thanks! I did notice that things look a bit incomplete (e.g. Tried to complete "Redirect" within a controller with no result. Not sure which isn't working: parent class methods or loading libraries). I presume that's just where things stand right now?

@sayedihashimi
Member

@jchannon thanks a lot! Regarding your question, could we discuss the prioritization of features in a new issue?

@jchannon
Contributor
jchannon commented Sep 9, 2014

Possibly. Check in activity monitor if mono sgen is running when you open
sublime. Also check the console in sublime to see the request response info
as that should show the completions.

On Tuesday, 9 September 2014, bmsullivan notifications@github.com wrote:

Updating to the latest OmniSharpServer did the trick! Thanks! I did notice
that things look a bit incomplete (e.g. Tried to complete "Redirect" within
a controller with no result. Not sure which isn't working: parent class
methods or loading libraries). I presume that's just where things stand
right now?

Reply to this email directly or view it on GitHub
#12 (comment).

@bmsullivan
Contributor

@jchannon - To be clear: a lot of the completions work. I get context-appropriate keywords, properties of user created classes, methods for common BCL classes like String, etc. What I'm not getting, specifically, are completions for members of the Mvc Controller class within my Controller-inherited class. I've also noticed some inconsistency in completing inherited members in subclasses of my own simple objects - old base class properties that have been deleted still appear in the completion list until a new member is added to the base class.

All the sort of stuff I would expect from a work in progress, for sure. Just curious I'm the only one seeing the behavior. If there's any way I can assist with the effort, I'd be happy to.

@jchannon
Contributor
jchannon commented Sep 9, 2014

@bmsullivan might be worth setting a simple repro up and speaking to @nosami

@markrendle

Anyone had any luck getting OmniSharpSublime working on Windows?

@jchannon
Contributor
jchannon commented Sep 9, 2014

I've not tried it

@nosami
nosami commented Sep 9, 2014

@bmsullivan If you're seeing stale completions, then the chances are that the sublime plugin isn't updating the server correctly. For example, in vim, every time a buffer switch is made, vim first updates the server with /updatebuffer to ensure it has the most update version of the previous buffer.

I don't use it, so not sure, but it sounds like a small fix on the client.

As for the Controller members, that should certainly work providing that the MVC assemblies were loaded by OmniSharp server when it started. Try starting the server manually and check the output as it does the initial solution load.

@bmsullivan
Contributor

@nosami Sorry to have taken so long to respond. Now that I look at what OmniSharp is loading, it makes sense. In ASP.NET vNext, NuGet references are stored globally (on my Mac, they're in ~/.kpm/packages) rather than in a packages directory alongside the solution. Is there any way to give OmniSharp an additional set of places to look for dlls?

If that's possible, it still seems like it's going to be a bit of a chore to get the right completions. If it knew where to look for the packages, it could look in all the project.json files found under the solution directory for their dependencies and versions, but those would only be top-level packages (e.g. I might have EntityFramework.InMemory in my dependencies section, but not EntityFramework), so I guess it would need to work its way through all the dependency chains by looking at the .nuspec files within the package folders.

Am I missing an easier way to do this?

Edit: After reading a bit more of the previous messages in this thread (shame on me for not doing so earlier), is that what integration with the Design Time Host is supposed to achieve?

@nosami
nosami commented Sep 27, 2014

@bmsullivan Yes, that's exactly what the DTH integration will achieve :)

https://github.com/nosami/OmniSharpServer/blob/master/OmniSharp/Solution/CSharpProject.cs#L65 <- This is pretty (very) crude, but it should automatically pick up dlls from your ~/.kpm/packages folder.

@bmsullivan
Contributor

@nosami Thanks! Looking at the source a bit more closely, I think the problem may be that I'm working without a solution file or a project file. It doesn't look like it will ever look for anything in the .kpm directory that's not specifically referenced in a project file. Am I seeing that right?

I think I may hack together something to handle my specific scenario since I've got a presentation on vNext coming up that I'd like to show this in.

@nosami
nosami commented Sep 28, 2014

@bmsullivan Yes, you're absolutely right. I have to confess to having not used vNext since the global package cache was introduced so didn't test that PR at all.

If you do hack something together, care to submit a PR? I get to spend very little time working on it at the moment. It only needs to be something temporary to tide people over until DTH integration.

@bmsullivan
Contributor

@nosami I'd be happy to! I got something working last night. It's quite naive and brute force, but it works for the simple scenario I want to demo. I'll try to make it slightly less brain-dead so that it doesn't affect non-vNext scenarios and submit a pull request this evening.

@bmsullivan
Contributor

@nosami Created a pull request for you (and anyone else on this thread who might be interested) at OmniSharp/omnisharp-server#108. As stated, it's likely very fragile, use at your own risk. :-)

@sayedihashimi
Member

The project has moved to https://github.com/OmniSharp/Kulture. If we should continue this conversation let's open a new issue there. Closing now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment