vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

ASP.NET Razor formatter removes duplicate spaces in a string value

Open RomanKoff opened this issue 6 months ago • 2 comments

Type: Bug

Issue Description

If you specify multiple spaces in a row in the value of a string variable and apply code formatting, the double spaces will be replaced with a single space. This is unacceptable.

Before: var s1 = " test test ";

After formating: var s1 = " test test ";

https://github.com/user-attachments/assets/1422da2d-07e8-4b71-8d58-3659ced767c2

RomanKoff avatar May 30 '25 11:05 RomanKoff

Thanks for the report @RomanKoff, unfortunately I can't repro the issue, and judging from the video it seems like for whatever reason that code is not being seen as C#. You can see in the video how, when you place the cursor to the left of test it highlights the word, but that doesn't happen inside string literals.

Would it be possible for you to share more details of your setup? What version of the extension are you using? Do you have the OmniSharp setting turned on? Could you share the whole Razor file that you're editing in the video?

If it's easier, running the "Razor: Report a Razor issue" command in VS Code should capture all of the relevant details for us.

davidwengier avatar Jun 04 '25 11:06 davidwengier

Extensions:

  • .NET Install Tool
  • C#
  • C# Dev Kit
  • HTML CSS Support
  • HTMLHint
  • IntelliSense for CSS class names in HTML
  • SCSS IntelliSense
  • Visual Studio Keymap
  • vscode-typograf
  • XML

settings.json

{
    "editor.codeLens": false,
    "editor.foldingMaximumRegions": 10000,
    "editor.fontSize": 17,
    "editor.largeFileOptimizations": false,
    "editor.lineHeight": 1.5,
    "editor.linkedEditing": true,
    "editor.minimap.showSlider": "always",
    "editor.scrollbar.horizontal": "visible",
    "editor.scrollbar.vertical": "visible",
    "editor.wordWrap": "wordWrapColumn",
    "editor.wordWrapColumn": 120,
    "explorer.confirmDelete": false,
    "explorer.confirmDragAndDrop": false,
    "files.hotExit": "off",
    "git.openRepositoryInParentFolders": "never",
    "html.format.wrapLineLength": 0,
    "redhat.telemetry.enabled": false,
    "window.newWindowDimensions": "offset",
    "workbench.colorTheme": "Default Light Modern",
    "workbench.list.openMode": "doubleClick",
    "workbench.sideBar.location": "right",
    "workbench.startupEditor": "none",
    "workbench.tree.indent": 16,
    "[xml]": {
        "editor.autoClosingBrackets": "never",
        "files.trimFinalNewlines": true
    },
    "editor.unicodeHighlight.invisibleCharacters": false,
    "editor.unicodeHighlight.ambiguousCharacters": false,
    "security.workspace.trust.untrustedFiles": "open",
    "explorer.confirmPasteNative": false,
    "[csharp]": {
        "editor.acceptSuggestionOnCommitCharacter": false
    },
}

RomanKoff avatar Jun 04 '25 15:06 RomanKoff