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

Disable Razor inlay hints

Open chenyuAC opened this issue 3 months ago • 3 comments

Type: Bug

Issue Description

Inlay hints suddenly appears for cshtml files, there is no settings to control this.

Steps to Reproduce

Open cshtml file with variable set in block scope.

Image

Expected Behavior

A setting can be used to enable or disable inlay hints for razor syntax

Actual Behavior

No setting can be found to enable or disable inlay hints for razor syntax

Image

Extension version: 2.90.60 VS Code version: Code 1.104.0 (Universal) (f220831ea2d946c0dcb0f3eaa480eb435a2c1260, 2025-09-10T06:46:18.035Z) OS version: Darwin arm64 23.6.0 Modes:

Environment Information

VSCode version: 1.104.0 C# Extension: 2.90.60 Using OmniSharp: false

Dotnet Information

Host: Version: 9.0.9 Architecture: arm64 Commit: 893c2ebbd4 RID: osx-arm64

.NET SDKs installed: No SDKs were found.

.NET runtimes installed: Microsoft.AspNetCore.App 9.0.9 [/Users/chenyu/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/9.0.9~arm64~aspnetcore/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 9.0.9 [/Users/chenyu/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/9.0.9~arm64~aspnetcore/shared/Microsoft.NETCore.App]

Other architectures found: x64 [/usr/local/share/dotnet/x64]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

Visual Studio Code Extensions
Extension Author Version Folder Name
claude-code Anthropic 1.0.110 anthropic.claude-code-1.0.110
csdevkit ms-dotnettools 1.50.51 ms-dotnettools.csdevkit-1.50.51-darwin-arm64
csharp ms-dotnettools 2.90.60 ms-dotnettools.csharp-2.90.60-darwin-arm64
debugpy ms-python 2025.10.0 ms-python.debugpy-2025.10.0-darwin-arm64
gitlens eamodio 17.4.1 eamodio.gitlens-17.4.1
jupyter ms-toolsai 2025.8.0 ms-toolsai.jupyter-2025.8.0-darwin-arm64
jupyter-keymap ms-toolsai 1.1.2 ms-toolsai.jupyter-keymap-1.1.2
jupyter-renderers ms-toolsai 1.3.0 ms-toolsai.jupyter-renderers-1.3.0
live-server ms-vscode 0.4.16 ms-vscode.live-server-0.4.16
prisma Prisma 6.16.1 prisma.prisma-6.16.1
python ms-python 2025.14.0 ms-python.python-2025.14.0-darwin-arm64
remote-explorer ms-vscode 0.5.0 ms-vscode.remote-explorer-0.5.0
remote-ssh ms-vscode-remote 0.120.0 ms-vscode-remote.remote-ssh-0.120.0
remote-ssh-edit ms-vscode-remote 0.87.0 ms-vscode-remote.remote-ssh-edit-0.87.0
ruff charliermarsh 2025.26.0 charliermarsh.ruff-2025.26.0-darwin-arm64
theme-check-vscode Shopify 3.9.10 shopify.theme-check-vscode-3.9.10
vscode-apollo apollographql 2.6.3 apollographql.vscode-apollo-2.6.3
vscode-dotnet-runtime ms-dotnettools 2.3.7 ms-dotnettools.vscode-dotnet-runtime-2.3.7
vscode-jupyter-cell-tags ms-toolsai 0.1.9 ms-toolsai.vscode-jupyter-cell-tags-0.1.9
vscode-jupyter-slideshow ms-toolsai 0.1.6 ms-toolsai.vscode-jupyter-slideshow-0.1.6
vscode-pylance ms-python 2025.7.1 ms-python.vscode-pylance-2025.7.1
vscode-python-envs ms-python 1.6.0 ms-python.vscode-python-envs-1.6.0-darwin-arm64
vscode-xml redhat 0.29.0 redhat.vscode-xml-0.29.0-darwin-arm64
C# Settings
Setting Value
preferCSharpExtension false
compilerDiagnosticScope openFiles
analyzerDiagnosticScope openFiles
enableXamlTools true
useServerGC true
System Info
Item Value
CPUs Apple M1 Pro (10 x 2400)
GPU Status 2d_canvas: enabled
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: enabled_on
trees_in_viz: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 5, 3, 4
Memory (System) 16.00GB (0.07GB free)
Process Argv --crash-reporter-id 2e0cf04f-cb8f-4798-9602-74bd02d39e04
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
996jf627:31283433
pythonrdcb7:31342333
usemplatestapi:31297334
aj953862:31281341
nesew2to5:31336538
agentclaude:31350858
82j33506:31327384
nes-set-on:31351930
testaa123cf:31335227
6abeh943:31336334
0927b901:31350571
ovsp_t:31383296
aa_t:31379598
0cj2b977:31352657
0574c672:31362109
asdad:31365766
cloudbuttont:31379625
todos-1:31384886
control-prompt:31370222
42190218_ostrepl:31382710
trigger-command-fix:31379601
auto_model_enabled:31385282

chenyuAC avatar Sep 15 '25 03:09 chenyuAC

@chenyuAC you should be able to control inlay hints via a language specific setting. For example in your settings.json you can put

"[aspnetcorerazor]": {
    "editor.inlayHints.enabled": "off"
}

which should turn off inlay hints just for Razor files.

However Razor currently does not have options for how the hints are displayed (like the ones in your screenshot) and does not appear to respect the settings for C# in C# blocks either.

dibarbet avatar Sep 15 '25 17:09 dibarbet

Razor is a little stuck here between the IDE that has an inlay hints option, and C# which has its own that default to off (the "show for types" and "show for parameters" at least). If we honoured the C# settings then users hit the hotkey and "nothing happens." So we assume that if the client asks for inlay hints, it's because the user wants to see inlay hints, based on either the setting or the hotkey.

Having said that, we could probably try to do something a little better here, and try to honour the other settings at least, or maybe don't override the type and parameter settings if at least one of them is set.

For the most part though, the setting @dibarbet posted above is the way to go.

davidwengier avatar Sep 18 '25 23:09 davidwengier

Also keep in mind there's yet another "source of truth" in .editorconfig files:

csharp_style_var_elsewhere = true:silent
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent

I guess it's an issue of multiple overlapping configurations.

Workaround mentioned above works like a charm, thanks. (Though I suggest one uses "[aspnetcorerazor]": { "editor.inlayHints.enabled": "offUnlessPressed" } so I can at least see other hints if I want to, using ctrl+alt.)

lonix1 avatar Oct 14 '25 03:10 lonix1