microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
228 stars 12 forks source link

[BUG] File Nesting Is not working for Class Library projects #1482

Open PeterMarinov opened 1 month ago

PeterMarinov commented 1 month ago

Describe the Issue

The Solution Explorer shipped with the C# DevKit already supports nesting, but it only works for Web projects. The feature is great as it allows developers to follow the single responsibility principle creating one c# class in a separate file, while still be able to group separate files/classes based of their high cohesion using a naming convention, e.g. all these classes have the same "Capture" group in the file name, e.g.

This feature already works for Web projects, but not for Class libraries.

If the csproj file has this declaration <Project Sdk="Microsoft.NET.Sdk.Web"> the nesting works. If the project is class library <Project Sdk="Microsoft.NET.Sdk"> , the nesting is not working. Looks like a quick fix, assuming you only need to enable same behavior for class libraries. That seems like a quick win

Suggestion for enhancement after the bug fix

VS Code's Explorer already supports file nesting as a setting called explorer.fileNesting. Documentation here. It's logical that a developer who uses VS Code and has this setting for the VS Code explorer will expect the same thing to work for C# DevKit's Solution Explorer. Suggestion is to provide a setting, which can read from these setting and apply them, but a quick win will be only to also enable file nesting for class libraries (it works in Web projects as of now).

Example of the setting below:

"explorer.fileNesting.enabled": true,
    "explorer.fileNesting.patterns": {
        "*.cs": "${capture}.*.cs",
        "I*.cs": "$(capture).cs"
    },

Steps To Reproduce

  1. Open *.sln file in VS Code using C# Dev Kit
  2. Create new Class Library project.
  3. Within the new Class library project, create a folder and create new Class and name it "Example"
  4. Create new Class in the same folder as step 3 and name it "Example.Request"
  5. Within the file editor, delete the Example part of the class name, so it's only named "Request". The file name will remain called "Example.Request.cs"
  6. Check how the file is displayed in Solution explorer

Expected Behavior

Solution Explorer should Nest the

image

Environment Information

Michael-Eng commented 2 weeks ago

As you have mentioned indirectly, this is not supported today.