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

Add option to run with a custom mono installation #2425

Merged
merged 5 commits into from
Jul 24, 2018

Conversation

shana
Copy link

@shana shana commented Jul 19, 2018

👋

When useGlobalMono is set to always or auto, the launcher uses whatever mono it finds in the path, which may or may not be a usable mono version for omnisharp. The user may have a suitable mono installation for omnisharp somewhere else, but not set as the default system one, or they may want to have omnisharp launched with a specific mono for omnisharp for debugging purposes. In my case, I have:

drwxr-xr-x  4.2.2.30
drwxr-xr-x  4.6.2.16
drwxr-xr-x  4.8.1.0
drwxr-xr-x  5.12.0.226_1
drwxr-xr-x  5.14.0.169_1
drwxr-xr-x  5.4.1.6
drwxr-xr-x  5.8.1.0_1

and I switch between them often, depending on what I need to do. Having vscode tied to whatever happens to be currently set on my system is really brittle, and if I need to have vscode use a particular mono version because of some mono bug, it's hard.

This PR adds a monoPath configuration option, and changes the launcher so that the environment variables PATH and MONO_GAC_PREFIX are changed to include the monoPath value, if set, when launching mono. If the monoPath option isn't set, it behaves as normal (also if useGlobalMono is set to never). I figured maybe this is useful for other people out there too 😃

When `useGlobalMono` is set to `always` or `auto`, the launcher uses whatever
mono it finds in the path, which may or may not be a usable mono version for
omnisharp. The user may have a suitable mono installation for omnisharp
somewhere else, but not set as the default system one, or they may want to
have omnisharp launched with a specific mono for omnisharp for debugging
purposes.

This adds a `monoPath` configuration option, and changes the launcher so that
the environment variables PATH and MONO_GAC_PREFIX are changed to include the
`monoPath` value, if set, when launching mono.
@dnfclas
Copy link

dnfclas commented Jul 19, 2018

CLA assistant check
All CLA requirements met.

@akshita31
Copy link
Contributor

akshita31 commented Jul 19, 2018

@shana Thank you for taking the time to contribute to the repo.
I notice that the integration tests are failing somehow. The timeout suggests that there is a problem with starting the "OmniSharp" process. Did you try running the integration tests on your machine?
You could run them by using npm run test:integration.

@rchande
Copy link

rchande commented Jul 19, 2018

@shana Thanks for your contribution! Looks good to me, once tests pass.

@codecov
Copy link

codecov bot commented Jul 20, 2018

Codecov Report

Merging #2425 into master will decrease coverage by 0.04%.
The diff coverage is 72.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2425      +/-   ##
==========================================
- Coverage   63.73%   63.68%   -0.05%     
==========================================
  Files          88       88              
  Lines        3998     4007       +9     
  Branches      564      567       +3     
==========================================
+ Hits         2548     2552       +4     
- Misses       1290     1292       +2     
- Partials      160      163       +3
Flag Coverage Δ
#integration 52.92% <55.55%> (-0.07%) ⬇️
#unit 84.71% <100%> (+0.05%) ⬆️
Impacted Files Coverage Δ
src/omnisharp/server.ts 72.43% <100%> (+0.7%) ⬆️
src/omnisharp/loggingEvents.ts 100% <100%> (ø) ⬆️
src/omnisharp/options.ts 100% <100%> (ø) ⬆️
src/observers/OmnisharpLoggerObserver.ts 100% <100%> (ø) ⬆️
src/omnisharp/launcher.ts 53.22% <37.5%> (-0.95%) ⬇️
src/omnisharp/delayTracker.ts 68.42% <0%> (-5.27%) ⬇️
src/omnisharp/requestQueue.ts 72.72% <0%> (-3.04%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 16c5546...69ba549. Read the comment docs.

@shana
Copy link
Author

shana commented Jul 20, 2018

Thanks for the review! Looks like the return value from the settings file was null instead of undefined, which meant the block overriding the env vars was always running, and I imagine screwing up the environment for spawning omnisharp in the process. I ran the integration tests locally with an up to date default system mono with no monoPath override, and with an older system mono and the monoPath override, and everything passes locally.

Can't really add much coverage for the integration tests though, not without bundling mono just for that purpose :/

@@ -306,14 +312,15 @@ function launchNix(launchPath: string, cwd: string, args: string[]): LaunchResul
};
}

function launchNixMono(launchPath: string, monoVersion: string, cwd: string, args: string[]): LaunchResult {
function launchNixMono(launchPath: string, monoVersion: string, cwd: string, args: string[], environment: NodeJS.ProcessEnv): LaunchResult {
let argsCopy = args.slice(0); // create copy of details args
argsCopy.unshift(launchPath);
argsCopy.unshift("--assembly-loader=strict");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some logging here, like printing the mono launch path, just like we print the version?

We create the log event here from the launch result: https://github.com/OmniSharp/omnisharp-vscode/blob/master/src/omnisharp/server.ts#L324. We might also return a monoLaunchPath in the launch result and display it here: https://github.com/OmniSharp/omnisharp-vscode/blob/master/src/observers/OmnisharpLoggerObserver.ts#L58. We will have to add the appropriate property to OmnisharpLaunch event here: https://github.com/OmniSharp/omnisharp-vscode/blob/master/src/omnisharp/loggingEvents.ts#L30.
Basically to do logging in omnisharp-vscode, we post the events into an event stream to which some observers subscribe. Whenever we post an event to the event stream, all the observers are invoked and take action appropriately. Does that make sense ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I hacked up some manual logging directly to a separate window just so I could see what was going on while I was putting this together, but adding some more information to the event stream probably makes sense, I can give that a try.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akshita31 I added some logging and in the process tweaked the test method a bit to avoid growing the if block, let me know if that's what you had in mind.

@@ -321,7 +321,7 @@ export class OmniSharpServer {

try {
let launchResult = await launchOmniSharp(cwd, args, launchInfo, this.platformInfo, options);
this.eventStream.post(new ObservableEvents.OmnisharpLaunch(launchResult.monoVersion, launchResult.command, launchResult.process.pid));
this.eventStream.post(new ObservableEvents.OmnisharpLaunch(launchResult.monoVersion, launchResult.command, launchResult.process.pid, options.monoPath));
Copy link
Contributor

@akshita31 akshita31 Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if the LaunchResult returned the monoLaunchPath(if any) that it used, instead of passing the options.monoPath here. That is because the launcher is the one that must decide whatever mono launch path should be used and here we are always assuming that if a monoPath is set that will be the one used by the launcher.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, that makes way more sense, not sure how I missed that. ☕️ ☕️ ☕️

Also no reason why the logging object should have optional arguments, fix that.
@shana
Copy link
Author

shana commented Jul 24, 2018

@akshita31 Logging fixed! 😄

@akshita31
Copy link
Contributor

@shana Thank you so much for patiently going through the feedback.
If you like, you can do a changelog update in a separate PR, otherwise I will do that.
Thanks again for taking time to make the repo better!

@akshita31 akshita31 merged commit b77d89f into dotnet:master Jul 24, 2018
@shana
Copy link
Author

shana commented Jul 26, 2018

@akshita31 Sorry, I didn't see your comment. Yay merge! I was not aware of the need to update the changelog manually, how does that work? It's just adding a new entry for the change?

@akshita31
Copy link
Contributor

@shana Yes that is right.

rchande pushed a commit to rchande/omnisharp-vscode that referenced this pull request Jul 31, 2018
This reverts commit b77d89f, reversing
changes made to 16c5546.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants