-
Notifications
You must be signed in to change notification settings - Fork 420
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
Added support for .editorconfig #1526
Added support for .editorconfig #1526
Conversation
This is awesome, thank you so much! I think this will enable a lot of people to switch from Visual Studio to VSCode or even VIM via Omnisharp. Is there an existing issue to open up the APIs on Roslyns side? |
Are there additional changes required in omnisharp-vscode extension? I've looked through and I saw that you've added additional option "EnableEditorConfigSupport" which I suppose needs to be passed from mentioned extension as well, so I guess it does indeed need an update. Is this planned by you or someone else? |
@Hoffs quickly checked, and it should be enough to enable it via |
I see, well I tested another way by adding an option to the extension (similar to enableRoslynAnalyzers), but what I've found out is that code actions don't work correctly. It seems OmniSharp server is returning what I believe incorrect identifier: {
"Identifier": "NamingStyleCodeFixProvider",
"Name": "Fix Name Violation: _mapper"
} Where as in tests comitted here the request to fix it is sent in same fashion as the message: var runRequest = new RunCodeActionRequest
{
Line = 2,
Column = 31,
FileName = testFile.FileName,
Identifier = "Create and initialize field 'xxx_something'",
WantsTextChanges = false,
WantsAllCodeActionOperations = true,
Buffer = testFile.Content.Code
}; where other test suggest that identifier is identical to text Assert.Contains(getResponse.CodeActions, f => f.Name == "Create and initialize field 'xxx_something'"); Similarly other actions return identifier in same style. {
"Identifier": "Encapsulate field: 'mapper' (and use property)",
"Name": "Encapsulate field: 'mapper' (and use property)"
} So my guess is that the |
yes the intent is the feature is opt-in in the beginning (until we gather more feedback and polish it off)
That's a good catch, however this is not really caused by this PR. The code fixes that use |
Actually I had a quick look and this is caused by a sigh null reference in the Roslyn code, will need to dig a bit deeper 😅 |
Yeah, code action does fail due to NullReference, just was guessing that identifier bit was the cause
|
@Hoffs can you check again after the latest commits? it should be fixed now |
Just did, it worked this time |
{ | ||
[MetadataAttribute] | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class ExportWorkspaceServiceFactoryWithAssemblyQualifiedNameAttribute : ExportAttribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @savpek needed to pull this in 😀
used the same name so that there are no conflicts
OptionSet Process(OptionSet currentOptionSet, OmniSharpOptions omniSharpOptions); | ||
OptionSet Process(OptionSet currentOptionSet, OmniSharpOptions omniSharpOptions, IOmniSharpEnvironment omnisharpEnvironment); | ||
|
||
int Order { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public api change... but I guess we don't publish packages yet... so we're good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. this will be one of the key extensibility points of OmniSharp so we have to get it right, hopefully now it's good, it's changed 3 times already to facilitate various features 😀we do have 3 feature implementations on top of it already too
{ | ||
[Shared] | ||
[ExportWorkspaceServiceFactoryWithAssemblyQualifiedName("Microsoft.CodeAnalysis.Features", "Microsoft.CodeAnalysis.CodeActions.WorkspaceServices.ISymbolRenamedCodeActionOperationFactoryWorkspaceService")] | ||
public class OmniSharpSymbolRenamedCodeActionOperationFactoryWorkspaceServiceFactory : IWorkspaceServiceFactory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to explain what is going on here - we need to do this because NamingStyleCodeFixProvider
internally tries to resolve ISymbolRenamedCodeActionOperationFactoryWorkspaceService
. That doesn't ship together with Roslyn but instead is only implemented inside Microsoft.VisualStudio.LanguageServices
, which we can't really reference (it has the whole tree of VS specific GUI dependencies).
On the other hand, ISymbolRenamedCodeActionOperationFactoryWorkspaceService
is internal, so implementing is by hand requires a bit twisting
16bed31
to
9f14f15
Compare
Do note that we're currently in the progress of changing how dotnet-format works. We've been working to update Roslyn to support .editorconfig parsing natively in the compiler and thus won't be reliant on the VS parsing library. I'm not sure what that means for PR, as much as be aware we consider dotnet-format to be an example of how not to do it. 😄 |
@jasonmalinowski unfortunately OmniSharp has to flex quite a lot to make things work in different places (this is just another case) - we've been chasing various internal APIs of Roslyn for a long time, so I think we'll just keep adapting as things change, as always 😀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code and tests look good! Will take it for a spin tomorrow, great work! 💪
@filipw The good news is this time we actually thought about you all and are happy to make changes accordingly. 😄 |
Had a chance to play with this. Works really great and it's super powerful when analyzers support is enabled! Thank you! |
@filipw Note that @jasonmalinowski and I have some time scheduled tomorrow to go over the new APIs and talk about how OmniSharp should use them. Might be nice if you could hold off merging until then... :) |
we can of course wait for the APIs but personally I'd like to be able to already use this from the |
…r formatting to crash when editor config options application doesn't work
9f14f15
to
7842db3
Compare
rebased on top of latest master |
When is this expected to release or rather when is the next planned release of ombisharp-roslyn? |
Thanks, but how it's work? I installed the latest build I can't get warning:
|
My root folder
|
@ExceptionGit thanks - I have created a new issue based on your comment #1551 We actually use an external component - |
This is really great, thanks @filipw! After some experimentation however, it seems like Example: // Program.cs
public class Program
{
public string Something { get; set; }
} # .editorconfig
root = true
[*.cs]
indent_size = 3 // omnisharp.json
{
"FormattingOptions": {
"EnableEditorConfigSupport": true,
"IndentationSize": 2
},
"RoslynExtensionsOptions": {
"EnableAnalyzersSupport": true,
"LocationPaths": [
"C:/Users/Nick/.omnisharp/roslynator"
]
}
} If I now Removing the Similar things occur with newlines, where roslynator applies |
Enable support for EditorConfig in OmniSharp. Since omnisharp-roslyn version 1.33.0, OmniSharp has had this support. * https://github.com/OmniSharp/omnisharp-roslyn/blob/master/CHANGELOG.md#1330---2019-07-01 * PowerShell#7357 * OmniSharp/omnisharp-roslyn#1526
can someone help me ?, I have added the file
also enabled the option {
"omnisharp.enableEditorConfigSupport": true
} in I wait for the following result:
|
This PR adds support for
.editorconfig
.It spans across multiple features:
.editorconfig
(i.e. indentation, spacing, new lines etc).editorconfig
(i.e. prefer var over concrete types etc).editorconfig
(i.e. camel casing or pascal casing of members, prefixes etc).editorconfig
.editorconfig
rules are also respected by the invoked analyzers, the invoked refactoring and code fixes. In other words, they manifest themselves through analyzers and in code generation.At the moment, changes to
.editorconfig
related to formatting are recomputed in real time, for other features they require omnisharp restart.The implementation is reflection based since the APIs are not public in Roslyn, however this is a very important feature, that we have waited years for, and is one of the most upvoted feature requests, so as much as we try to avoid it, I think reflection is acceptable here.
The approach is adapted from how https://github.com/dotnet/format works (although it only deals with formatting, not with code style/naming conventions/analyzers).
Fixes #950
Fixes #1242
Fixes #31
Fixes dotnet/vscode-csharp#1726