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

Extension not suggesting to use explicit type instead of var #3907

Closed
jffaust opened this issue Jul 11, 2020 · 4 comments
Closed

Extension not suggesting to use explicit type instead of var #3907

jffaust opened this issue Jul 11, 2020 · 4 comments

Comments

@jffaust
Copy link

jffaust commented Jul 11, 2020

Issue Description

I have a couple of variables declaration using var instead of the explicit type. In Visual Studio, Omnisharp would suggest me to use the explicit type instead and I could make the change automatically by using the keyboard shortcut (Ctrl+.).

This was super useful and I can't figure out how to make it work inside VS Code. I was not able to find any documentation, issues or articles related to this so I'm creating a new issue.

In this specific case I was doing a LINQ group by and I wanted to be able to use the explicit type and then go look at the type definition for IGrouping.

Steps to Reproduce

var myCustomObject = new CustomObject();

Expected Behavior

Suggest the option to use the explicit type when using the code actions keyboard shortcut.

Actual Behavior

Missing suggestion:
image
image

Environment information

VSCode version: 1.46.1
C# Extension: 1.22.1

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.301 Commit: 7feb845744

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.301\

Host (useful for support):
Version: 3.1.5
Commit: 65cd789777

.NET Core SDKs installed:
3.1.301 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
auto-run-command gabrielgrinberg 1.6.0
azure-account ms-vscode 0.8.11
csharp ms-dotnettools 1.22.1
githistory donjayamanne 0.6.5
powershell-preview ms-vscode 2020.6.1
prettier-vscode esbenp 5.1.3
vscode-azurefunctions ms-azuretools 0.23.0
vscode-icons vscode-icons-team 10.1.1
vscode-nuget-package-manager jmrog 1.1.6
@cartermp
Copy link

cartermp commented Jul 14, 2020

This is driven from a .editorconfig where conventions for var vs. explicit types are configured. Roslyn uses that to determine when to suggest style changes. Is .editorconfig in use for your codebase?
image

You can get started here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#implicit-and-explicit-types

@jffaust
Copy link
Author

jffaust commented Jul 16, 2020

That's exactly what I was looking for :)

Thanks a lot :)

@jffaust jffaust closed this as completed Jul 16, 2020
@romerobrjp
Copy link

This is driven from a .editorconfig where conventions for var vs. explicit types are configured. Roslyn uses that to determine when to suggest style changes. Is .editorconfig in use for your codebase?
image

You can get started here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#implicit-and-explicit-types

Didn't work for me =/

@JoeRobich
Copy link
Member

@rom5jp You need to also set "omnisharp.enableRoslynAnalyzers" to "true" in the VS Code preferences if you haven't already.

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

4 participants