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

Pass editor tab/indentation settings to OmniSharp #1055

Merged
merged 4 commits into from
Dec 19, 2016

Conversation

filipw
Copy link
Contributor

@filipw filipw commented Dec 18, 2016

This should fix #834 and related issues.

This PR ensures that we pass VS Code editor.* settings related to tabs/indentation into OmniSharp (through environment variables, which OmniSharp already supports - no changes needed there). This way, when invoking commands such as Format Document, we will respect the user set up in his VS Code, rather than imposing OmniSharp defaults (spaces over tabs, 4 spaces indentation).

This feature can be opt out from by setting omnisharp.useEditorFormattingSettings to false.

Additionally, OmniSharp has its own tab vs spaces and indentation rules that can be controlled using omnisharp.json. If this file is present in the current working directory, it will still take precedence as it was in the past - no change there.

@DustinCampbell
Copy link
Member

This will also address #93.

Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

Nice change! I just had a question about whether the options could/should be specified as command-line arguments.

@@ -193,6 +202,7 @@ function launchWindows(launchPath: string, cwd: string, args: string[]): LaunchR
}

let argsCopy = args.slice(0); // create copy of args
//argsCopy.push('--debug');
Copy link
Member

Choose a reason for hiding this comment

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

Why is this added and commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops my dirty attaching of a debugger 😞

envVars['formattingOptions:useTabs'] = !editorConfig.get('insertSpaces', true);
envVars['formattingOptions:tabSize'] = editorConfig.get('tabSize', 4);
envVars['formattingOptions:indentationSize'] = editorConfig.get('tabSize', 4);
}
Copy link
Member

Choose a reason for hiding this comment

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

Can't these just be passed as additional arguments? I though OmniSharp's configuration builder would pick these up from the command line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes they can - in fact I believe restore packages is passed like that already if I recall correctly. I can change that for consistency, there is no real reason to use environment variables indeed

Copy link
Member

Choose a reason for hiding this comment

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

That's what I thought -- thanks! Yeah, go ahead and pass them as args for consistency. I have no idea what the logic is for options overriding in the configuration middleware that OmniSharp uses. E.g. do command line args override environment variable or vice versa? I just ran into something similar with MSBuild, so it was on my mind. Hence, the question. 😄

@filipw
Copy link
Contributor Author

filipw commented Dec 19, 2016

Updated the PR to pass the formatting options using command line instead of env vars.

OmniSharp now starts like this, with your editor settings passed in:

OmniSharp: -s c:\code\csharp-scripting-demos\dotnetcli-and-debug --hostPID 3408 --stdio DotNet:enablePackageRestore=false --encoding utf-8 -v formattingOptions:useTabs=true formattingOptions:tabSize=2 formattingOptions:indentationSize=2

If you opt out of the formatting settings sharing, then it will start same as before i.e.:

OmniSharp: -s c:\code\csharp-scripting-demos\dotnetcli-and-debug --hostPID 4024 --stdio DotNet:enablePackageRestore=false --encoding utf-8 -v

@filipw
Copy link
Contributor Author

filipw commented Dec 19, 2016

I also created a wiki page https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration%20Options - might be useful if folks have questions in the future

Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

Looks great! Love that it's even smaller.

@DustinCampbell DustinCampbell added this to the 1.6 milestone Dec 19, 2016
@DustinCampbell DustinCampbell merged commit 4628a74 into dotnet:master Dec 19, 2016
@filipw
Copy link
Contributor Author

filipw commented Dec 19, 2016

thanks!

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.

editor.formatOnType does not respect editor.insertSpaces setting
3 participants