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

Code Actions do not respect formatting options #759

Closed
DustinCampbell opened this issue Feb 8, 2017 · 4 comments
Closed

Code Actions do not respect formatting options #759

DustinCampbell opened this issue Feb 8, 2017 · 4 comments
Assignees

Comments

@DustinCampbell
Copy link
Contributor

From @rmunn on February 7, 2017 8:10

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview3-004056)

Product Information:
 Version:            1.0.0-preview3-004056
 Commit SHA-1 hash:  ccc4968bc3

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  14.04
 OS Platform: Linux
 RID:         ubuntu.14.04-x64

VS Code version: 1.9.0
C# Extension version: 1.6.2

Contents of omnisharp.json in root directory of my current project:

{
    "formattingOptions": {
        "useTabs": true
    }
}

Steps to reproduce

  1. Open a file that contains tab indentation.
  2. Type in a function name that doesn't exist, like DoSomething();
  3. Select the "Generate method" quick fix.

Expected behavior

OmniSharp generates a method matching the indentation of the current file:

tab-indents

Actual behavior

The method is generated with spaces, even though the file is indented with tabs (which VS Code was able to auto-detect) and the omnisharp.json config file specified using tab indentation:

space-indents

Any new lines of code that I write in the file, though, will contain tab indentation since VS Code has (correctly) detected that the file contains tabs. (I actually prefer spaces for indentation myself, but the project's coding standards require tabs, so that's what I'm using for this project).

Workaround

I can work around this by selecting the newly-created method, hitting Shift-Tab once to dedent it (which causes VS Code to convert its indentation to spaces), then hitting Tab once to indent it again, which adds a tab as it moves back to its original indentation. But I'd rather see OmniSharp detect the current indentation style of the file and match it -- or, failing that, at least respect the omnisharp.json settings.

Related bugs

The part where I say "I'd rather see OmniSharp detect the current indentation style of the file and match it" might be a completely new feature request, but the part where the omnisharp.json settings file seems to be ignored looks like it might be a regression of #834 and/or #927. Also, PR #1055 might be related.

Copied from original issue: dotnet/vscode-csharp#1191

@DustinCampbell
Copy link
Contributor Author

From @filipw on February 7, 2017 9:9

Thanks for the report - this is indeed a bug, but it is not a regression.
The other bugs you listed were dealing with document formatting using Omnisharp's code format endpoints, rather than applying code actions (which is the case here) - for example mangle up some code, right click, select Format Document - your tab settings should be used.

OmniSharp will absolutely try to detect your VS Code settings and apply accordingly, even without omnisharp.json (although the JSON file is given higher priority indeed).

Can you also list your settings for (unless you use defaults):

  • omnisharp.useEditorFormattingSettings
  • editor.insertSpaces
  • editor.detectIndentation

@DustinCampbell
Copy link
Contributor Author

From @rmunn on February 7, 2017 9:55

All three of those are set to the default values (true, true and true) for me. I haven't changed them in either my user settings, my workspace settings, or my omnisharp.json file.

@DustinCampbell
Copy link
Contributor Author

It looks to me like OmniSharp never sets the formatting options on its workspace, so features never automatically (like code actions) pick them up.

@DustinCampbell
Copy link
Contributor Author

From @filipw on February 7, 2017 15:34

Yes that's exactly what's happening.

I'm thinking the best/most flexible way to go forward would be to create a MEF extensibility point in Omnisharp.Abstractions that would allow different components such as Omnisharp.Roslyn.CSharpand perhaps in the future, loaded plugins too, to modify the workspace prior to it being initialized (similar to how project systems are discovered https://github.com/OmniSharp/omnisharp-roslyn/blob/dev/src/OmniSharp.Host/Startup.cs#L183-L199). This way we get a hook to set the formatting settings and other global workspace things early on.

This would also simplify a lot of code, as at the moment the formatting endpoints keep creating the formatting settings over and over too.

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

No branches or pull requests

2 participants