Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Intellisense #12

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

C# Intellisense #12

shirhatti opened this issue Aug 5, 2014 · 79 comments
Milestone

Comments

@shirhatti
Copy link
Member

@shirhatti shirhatti commented Aug 5, 2014

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

@jchannon jchannon commented Aug 6, 2014

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

@shirhatti
Copy link
Member Author

@shirhatti shirhatti commented Aug 6, 2014

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

@shirhatti shirhatti commented Aug 6, 2014

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

@glennblock glennblock commented Aug 6, 2014

Nice progress @shirhatti!

@jchannon
Copy link
Contributor

@jchannon 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
Copy link

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

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

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

@glennblock glennblock commented Aug 6, 2014

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

@shirhatti
Copy link
Member Author

@shirhatti shirhatti commented Aug 6, 2014

@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
Copy link
Contributor

@jchannon 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
Copy link

@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
Copy link
Contributor

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

@sayedihashimi sayedihashimi commented Aug 7, 2014

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

@jchannon
Copy link
Contributor

@jchannon 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
Copy link
Contributor

@jchannon 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
Copy link

@davidfowl davidfowl commented Aug 7, 2014

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

@nosami
Copy link

@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
Copy link
Contributor

@jchannon jchannon commented Aug 7, 2014

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

@sayedihashimi
Copy link
Member

@sayedihashimi sayedihashimi commented Aug 7, 2014

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

@davidfowl davidfowl commented Aug 7, 2014

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

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

@shirhatti shirhatti commented Aug 7, 2014

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

@nosami
Copy link

@nosami nosami commented Aug 7, 2014

Does the DTH work outside of Windows?

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

@nosami nosami commented Sep 2, 2014

Mine is jasonimison1

@sayedihashimi
Copy link
Member

@sayedihashimi sayedihashimi commented Sep 2, 2014

Mine is sayed.ibrahim.hashimi

@jchannon
Copy link
Contributor

@jchannon jchannon commented Sep 3, 2014

Mine is jchannonwinplc

@Mpdreamz
Copy link

@Mpdreamz Mpdreamz commented Sep 3, 2014

mine is mpdreamz

@sayedihashimi
Copy link
Member

@sayedihashimi sayedihashimi commented Sep 4, 2014

@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
Copy link
Contributor

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

@sayedihashimi sayedihashimi commented Sep 6, 2014

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

@jchannon
Copy link
Contributor

@jchannon 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
Copy link
Contributor

@bmsullivan bmsullivan commented Sep 8, 2014

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

@Kuzirashi Kuzirashi commented Sep 8, 2014

@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
Copy link
Contributor

@bmsullivan bmsullivan commented Sep 8, 2014

@Kuzirashi Thanks, I'll try that!

@jchannon
Copy link
Contributor

@jchannon 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
Copy link
Contributor

@Kuzirashi Kuzirashi commented Sep 8, 2014

@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
Copy link
Contributor

@bmsullivan bmsullivan commented Sep 9, 2014

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

@sayedihashimi sayedihashimi commented Sep 9, 2014

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

@jchannon
Copy link
Contributor

@jchannon 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
Copy link
Contributor

@bmsullivan bmsullivan commented Sep 9, 2014

@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
Copy link
Contributor

@jchannon jchannon commented Sep 9, 2014

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

@markrendle
Copy link

@markrendle markrendle commented Sep 9, 2014

Anyone had any luck getting OmniSharpSublime working on Windows?

@jchannon
Copy link
Contributor

@jchannon jchannon commented Sep 9, 2014

I've not tried it

@nosami
Copy link

@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
Copy link
Contributor

@bmsullivan bmsullivan commented Sep 27, 2014

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

@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
Copy link
Contributor

@bmsullivan bmsullivan commented Sep 28, 2014

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

@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
Copy link
Contributor

@bmsullivan bmsullivan commented Sep 28, 2014

@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
Copy link
Contributor

@bmsullivan bmsullivan commented Sep 29, 2014

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

@sayedihashimi sayedihashimi commented Nov 1, 2014

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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.