dotnet / dotnet/vscode-csharp

No code actions available in @code section of Razor files

Open
#5,578 0 comments 0 reactions 0 assignees View on GitHub
OmniSharp Razor
Dominant language
TypeScript
Stars
3.1k
Forks
737
Avg merge
17h 56m
Merged PRs (30d)
21

Description

## Issue Description ##
When I declare a @code section in a Razor file, I don't get any code actions (lightbulb suggestions).

## Steps to Reproduce ##
1. Create a new BlazorWasm project:
`dotnet new blazorwasm -n wasm01`
2. Create a Models directory at the root and add a simple class there, using the Models namespace:

```csharp
namespace wasm01.Models;

public class Game
{
public int Id { get; set; }
public required string Name { get; set; }
}
```

4. Try to use the new class in Index.razor:
```razor
@page "/"

Index

Hello, world!

@code {
private Game game = new();
}
```

6. Put your cursor on the Game type.

## Expected Behavior ##
If you hover over the Game type you should get a lightbulb and if you do CTRL+. you should get code suggestions, as it happens in OmniSharp version 1.25.2:

![image](https://user-images.githubusercontent.com/2374270/217727488-cbe46420-a11c-48ed-a93f-42e7e78c6b54.png)

## Actual Behavior ##
There's no lightbulb suggesting the missing namespace. And, if you do CTRL+. (on Windows) it says "no code actions available":

![image](https://user-images.githubusercontent.com/2374270/217727087-05312bc5-e78b-432c-8b3f-3459f3bd5cc1.png)

## Logs ##

### OmniSharp log ###

Starting OmniSharp server at 2/8/2023, 9:41:24 PM
Target: d:\projects\wasm01

OmniSharp server started with .NET 7.0.102
.
Path: c:\Users\julio\.vscode\extensions\ms-dotnettools.csharp-1.25.4-win32-x64\.omnisharp\1.39.4-net6.0\OmniSharp.dll
PID: 38376

[info]: OmniSharp.Stdio.Host
Starting OmniSharp on Windows 10.0.22621.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
[info]: OmniSharp.Services.DotNetCliService
Using the 'dotnet' on the PATH.
[info]: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 2 MSBuild instance(s)
1: .NET Core SDK 7.0.102 17.4.1 - "C:\Program Files\dotnet\sdk\7.0.102\"
2: .NET Core SDK 7.0.101 17.4.0 - "C:\Program Files\dotnet\sdk\7.0.101\"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: .NET Core SDK 7.0.102 17.4.1 - "C:\Program Files\dotnet\sdk\7.0.102\"
[info]: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in 'd:\projects\wasm01'.
[info]: OmniSharp.Cake.CakeProjectSystem
Did not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
No solution files found in 'd:\projects\wasm01'
[info]: OmniSharp.MSBuild.ProjectManager
Queue project update for 'd:\projects\wasm01\wasm01.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in 'd:\projects\wasm01'.
[info]: OmniSharp.Script.ScriptProjectSystem
Did not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
Configuration finished.
[info]: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location 'd:\projects\wasm01' on host 20092.
[info]: OmniSharp.OmniSharpWorkspace
Miscellaneous file: d:\projects\wasm01\Pages\Index.razor__virtual.cs added to workspace
[info]: OmniSharp.MSBuild.ProjectManager
Loading project: d:\projects\wasm01\wasm01.csproj
[info]: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file 'd:\projects\wasm01\wasm01.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
Adding project 'd:\projects\wasm01\wasm01.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
Update project: wasm01
[info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
Solution initialized -> queue all documents for code analysis. Initial document count: 13.
[warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService
No symbol found. File: d:\projects\wasm01\Pages\Index.razor__virtual.cs, Line: 119, Column: 14.

### C# log ###
EMPTY

## Environment information ##

**VSCode version**: 1.75.0
**C# Extension**: 1.25.4

Dotnet Information
.NET SDK:
Version: 7.0.102
Commit: 4bbdd14480

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

Host:
Version: 7.0.2
Architecture: x64
Commit: d037e070eb

.NET SDKs installed:
8.0.101 [C:\Program Files\dotnet\sdk]
7.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

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|
|---|---|---|
|blazorwasm-companion|ms-dotnettools|1.1.4|
|copilot|GitHub|1.71.8269|
|csharp|ms-dotnettools|1.25.4|
|csharpextensions|kreativ-software|1.7.3|
|data-workspace-vscode|ms-mssql|0.4.0|
|gitlens|eamodio|13.2.0|
|mongodb-vscode|mongodb|0.10.0|
|mssql|ms-mssql|1.17.1|
|rest-client|humao|0.25.1|
|sql-bindings-vscode|ms-mssql|0.3.0|
|sql-database-projects-vscode|ms-mssql|0.21.0|
|vscode-dotnet-runtime|ms-dotnettools|1.6.0|
|vscode-icons|vscode-icons-team|12.2.0|;

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.