jmederosalvarado / roslyn.nvim

Roslyn LSP plugin for neovim
MIT License
192 stars 33 forks source link

Is there anyway to get `inlay_hint` for current server state? #5

Closed cpea2506 closed 2 months ago

cpea2506 commented 7 months ago

I try to enable inlay_hint via on_attach callback and it doesn't seem to work. I'm not sure it is enable by default or must be toggle via settings.

if client.server_capabilities.inlayHintProvider then
    vim.lsp.inlay_hint.enable(bufnr, true)
end

I also try to get the result of of the function below but it returns {}

vim.lsp.inlay_hint.get({ bufnr = 0 })
jmederosalvarado commented 7 months ago

Inlay hints probably need to be enabled on the server side using settings. These are the settings supported by the roslyn language server, modifying those would probably work, would be good to accept it as part of plugin setup. Feel free to open a PR, otherwise I'll try to do it when I have some time.

SchnozzleCat commented 3 months ago

Inlay hints probably need to be enabled on the server side using settings. These are the settings supported by the roslyn language server, modifying those would probably work, would be good to accept it as part of plugin setup. Feel free to open a PR, otherwise I'll try to do it when I have some time.

I'm trying to set this up at the moment, but I'm unsure what I should be passing to the settings object.

Should I be passing an object that matches the state of the settings in the package.json? e.g. csharp.inlayHints.enableInlayHintsForTypes=true

Or should I be using the internal roslyn setting that is passed to the server? e.g. RoslynExtensionsOptions:InlayHintsOptions:EnableForTypes=true

SchnozzleCat commented 3 months ago

After digging into the LSP code, the actual option types for inlay hints should be as follows:

"inlay_hints.dotnet_enable_inlay_hints_for_parameters",
"inlay_hints.dotnet_enable_inlay_hints_for_literal_parameters",
"inlay_hints.dotnet_enable_inlay_hints_for_indexer_parameters",
"inlay_hints.dotnet_enable_inlay_hints_for_object_creation_parameters",
"inlay_hints.dotnet_enable_inlay_hints_for_other_parameters",
"inlay_hints.dotnet_suppress_inlay_hints_for_parameters_that_differ_only_by_suffix",
"inlay_hints.dotnet_suppress_inlay_hints_for_parameters_that_match_method_intent",
"inlay_hints.dotnet_suppress_inlay_hints_for_parameters_that_match_argument_name",
"inlay_hints.csharp_enable_inlay_hints_for_types",
"inlay_hints.csharp_enable_inlay_hints_for_implicit_variable_types",
"inlay_hints.csharp_enable_inlay_hints_for_lambda_parameter_types",
"inlay_hints.csharp_enable_inlay_hints_for_implicit_object_creation",

However, doing the following still gives no inlay hints:

require("roslyn").setup({
    settings = {
      inlay_hints = {
        dotnet_enable_inlay_hints_for_parameters = true,
        csharp_enable_inlay_hints_for_types = true,
      }
    },
})
cpea2506 commented 2 months ago

@SchnozzleCat

I just found the correct setup, for list of settings and default values, take a look at this https://github.com/jmederosalvarado/roslyn.nvim/pull/17#issuecomment-1864205742

I will mark this issue as completed, thanks for you all responses.

require("roslyn").setup({
    settings = {
        ["csharp|inlay_hints"] = {
            ["csharp_enable_inlay_hints_for_implicit_object_creation"] = true,
            ["csharp_enable_inlay_hints_for_implicit_variable_types"] = true,
            ["csharp_enable_inlay_hints_for_lambda_parameter_types"] = true,
            ["csharp_enable_inlay_hints_for_types"] = true,
            ["dotnet_enable_inlay_hints_for_indexer_parameters"] = true,
            ["dotnet_enable_inlay_hints_for_literal_parameters"] = true,
            ["dotnet_enable_inlay_hints_for_object_creation_parameters"] = true,
            ["dotnet_enable_inlay_hints_for_other_parameters"] = true,
            ["dotnet_enable_inlay_hints_for_parameters"] = true,
            ["dotnet_suppress_inlay_hints_for_parameters_that_differ_only_by_suffix"] = true,
            ["dotnet_suppress_inlay_hints_for_parameters_that_match_argument_name"] = true,
            ["dotnet_suppress_inlay_hints_for_parameters_that_match_method_intent"] = true,
        },
    },
})
Screenshot 2024-04-14 at 16 35 24