Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inlay hints don't work #5149

Closed
Igorgro opened this issue Apr 3, 2022 · 4 comments
Closed

Inlay hints don't work #5149

Igorgro opened this issue Apr 3, 2022 · 4 comments

Comments

@Igorgro
Copy link

Igorgro commented Apr 3, 2022

Issue Description

I've enabled inlay hints using the following settings:

"csharp.inlayHints.parameters.enabled": true,
"csharp.inlayHints.types.enabled": true,
"csharp.inlayHints.types.forImplicitVariableTypes": true,
"csharp.inlayHints.parameters.forLiteralParameters": true,

but inlay hints don't work and there are number of repated messages in Omnisharp logs

Steps to Reproduce

  1. Install .NET on ArchLinux using dotnet-install.sh
  2. Create sample program like this:
    namespace Demo
    {
        class Program
        {
            static int add(int a, int b)
            {
                return a+b;
            }
            static void Main(string[] args)
            {
                var a = 10;
                add(1, a);
            }
        }
    }
  3. See no inlay hints and errors in the OmniSharp logs

Expected Behavior

Inlay hints woking for both variable types and argument names

Actual Behavior

In inlay hints are shown

Logs

OmniSharp log

[fail]: OmniSharp.Stdio.Host
        ************  Response (49.7946ms) ************ 
{
  "Request_seq": 1427,
  "Command": "/inlayHint",
  "Running": true,
  "Success": false,
  "Message": "\"System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'index')\\n   at Microsoft.CodeAnalysis.Text.SourceText.LineInfo.get_Item(Int32 index)\\n   at OmniSharp.Extensions.TextExtensions.GetPositionFromLineAndOffset(SourceText text, Int32 lineNumber, Int32 offset) in /Users/runner/work/1/s/src/OmniSharp.Roslyn/Extensions/TextExtensions.cs:line 28\\n   at OmniSharp.Extensions.TextExtensions.GetSpanFromRange(SourceText text, Range range) in /Users/runner/work/1/s/src/OmniSharp.Roslyn/Extensions/TextExtensions.cs:line 55\\n   at OmniSharp.Roslyn.CSharp.Services.InlayHints.InlayHintService.Handle(InlayHintRequest request) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/InlayHints/InlayHintService.cs:line 56\\n   at OmniSharp.Endpoint.EndpointHandler`2.GetFirstNotEmptyResponseFromHandlers(ExportHandler`2[] handlers, TRequest request) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 218\\n   at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 234\\n   at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 143\\n   at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in /Users/runner/work/1/s/src/OmniSharp.Stdio/Host.cs:line 258\"",
  "Body": null,
  "Seq": 134756,
  "Type": "response"
}

C# log

Environment information

VSCode version: 1.66.0
C# Extension: 1.24.3

Mono Information OmniSharp using built-in mono
Dotnet Information Version: 6.0.101 Commit: ef49f6213a

Runtime:
OS Name: arch
OS Version:
OS Platform: Linux
RID: arch-x64
Base Path: /usr/share/dotnet/sdk/6.0.101/

Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc

.NET SDKs installed:
5.0.404 [/usr/share/dotnet/sdk]
6.0.101 [/usr/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.13 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
ansible redhat 0.8.1
beautify HookyQR 1.5.0
csharp ms-dotnettools 1.24.3
git-graph mhutchie 1.30.0
gitlab-workflow GitLab 3.42.0
gitlens eamodio 12.0.5
gitmoji-vscode seatonjiang 1.1.2
hexeditor ms-vscode 1.9.5
jupyter ms-toolsai 2022.3.1000901801
jupyter-keymap ms-toolsai 1.0.0
live-server ms-vscode 0.2.12
material-icon-theme PKief 4.15.0
material-product-icons PKief 1.2.0
python ms-python 2022.4.0
resxpress PrateekMahendrakar 4.5.0
trailing-spaces shardulm94 0.3.1
vscode-docker ms-azuretools 1.21.0
vscode-eslint dbaeumer 2.2.2
vscode-jest Orta 4.2.1
vscode-npm-script eg2 0.3.24
vscode-openapi 42Crunch 4.9.3
vscode-taskexplorer spmeesseman 2.9.1
vscode-xml redhat 0.20.0
vscode-yaml redhat 1.6.0
vscord LeonardSSH 4.5.0
@filipw
Copy link
Contributor

filipw commented Apr 3, 2022

These settings currently only enable inlay hints at the VS Code level, but not in OmniSharp server. You need to separately enable them in the server component. In the future they will be synchronized.

For now, the simplest way is to do one of the following:

  • create (or edit existing) omnisharp.json file located in %USERPROFILE%/.omnisharp/ (affects all projects globally)
  • create (or edit existing) omnisharp.json file located in the working directory which OmniSharp has been pointed at (affects current project only)

in this file, you can enable inlay hints by setting

{
 "roslynExtensionsOptions": {
    "inlayHintsOptions": {
        "enableForParameters": true,
        "forLiteralParameters": true,
        "forIndexerParameters": true,
        "forObjectCreationParameters": true,
        "forOtherParameters": true,
        "suppressForParametersThatDifferOnlyBySuffix": false,
        "suppressForParametersThatMatchMethodIntent": false,
        "suppressForParametersThatMatchArgumentName": false,
        "enableForTypes": true,
        "forImplicitVariableTypes": true,
        "forLambdaParameterTypes": true,
        "forImplicitObjectCreation": true
    }
  }
}

More on the server configuration options can be found here https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options

@Igorgro
Copy link
Author

Igorgro commented Apr 3, 2022

Thank you! After applying this settings everything works well.

@filipw
Copy link
Contributor

filipw commented Apr 4, 2022

Thanks for confirming

@filipw filipw closed this as completed Apr 4, 2022
@Igorgro
Copy link
Author

Igorgro commented Apr 4, 2022

In the future they will be synchronized

Maybe this issue should be stay opened to track that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants