dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.87k stars 675 forks source link

After entering a new line, the indentation isn't completed #7159

Open timheuer opened 5 months ago

timheuer commented 5 months ago

Type: Bug

Given a single line like:

var db = builder.AddPostgres("postgres")

And you hit enter after that line, in Visual Studio, it goes to a new line, but also indents with my default tab/spaces amount. In C# extension it does not indent, it just goes to the start of new line.

https://github.com/dotnet/vscode-csharp/assets/4821/e7781538-5eda-4d0f-9045-53fdd7265d84

Extension version: 2.31.16 VS Code version: Code - Insiders 1.90.0-insider (a0986b0f653c8309e8a957d53a0a5039239c6a5d, 2024-05-23T22:54:16.118Z) OS version: Windows_NT x64 10.0.22635 Modes:

System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 9 3900X 12-Core Processor (24 x 3793)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|127.92GB (83.85GB free)| |Process Argv|--crash-reporter-id 961e68ed-cec6-437f-8e5f-e44a8abbf88f| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscod805:30301674 vsaa593cf:30376535 py29gd2263:31024238 c4g48928:30535728 962ge761:30841072 pythongtdpath:30726887 welcomedialog:30812478 pythonidxpt:30768918 pythonnoceb:30776497 asynctok:30898717 dsvsc013:30777762 dsvsc014:30777825 dsvsc015:30821418 pythontestfixt:30866404 pythonregdiag2:30926734 pythonmypyd1:30859725 pythoncet0:30859736 2e7ec940:31000449 pythontbext0:30879054 accentitlementst:30870582 dsvsc016:30879898 dsvsc017:30880771 dsvsc018:30880772 cppperfnew:30980852 pythonait:30973460 showvideot:31016890 chatpanelt:31014475 bdiig495:31013172 a69g1124:31018687 dvdeprecation:31040973 pythonprt:31036556 dwnewjupyter:31046869 impr_priority:31052045 26j00206:31048877 ```
dibarbet commented 5 months ago

This is probably solvable by updating the indentationRules in the C# language-configuration.json. See https://code.visualstudio.com/api/language-extensions/language-configuration-guide#indentation-rules

It looks like the C# configuration that ships with VSCode by default does not specify any custom configurations, so it's likely just using the default rules. See https://github.com/microsoft/vscode/blob/main/extensions/csharp/language-configuration.json

We probably won't ever be perfect though, VS allows the language service to plug directly into indentation, but in VSCode we have to live with regex rules.

Moving to backlog for now

timheuer commented 5 months ago

@dibarbet I swear it didn't use to do this and in fact did auto-indent. Anything that might have changed can you think? It caught me so off guard recently that I don't remember this being the default editing experience before.