OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.72k stars 417 forks source link

OmniSharp LSP Server does not auto import even if enableImportCompletion is `true` #2573

Open AnhQuanTrl opened 9 months ago

AnhQuanTrl commented 9 months ago

For some context, I am using OmniSharp Roslyn in conjunction with Neovim and LspConfig. Here are my omnisharp.json:

{
  "FormattingOptions": {
    "EnableEditorConfigSupport": true,
    "OrganizeImports": true
  },
  "RoslynExtensionsOptions": {
    "enableImportCompletion": true,
    "enableAnalyzersSupport": false
  }
}

Here is my client completion capabilities:

completion = {
  completionItem = {
    commitCharactersSupport = true,
    deprecatedSupport = true,
    documentationFormat = { "markdown", "plaintext" },
    insertReplaceSupport = true,
    insertTextModeSupport = {
      valueSet = { 1, 2 }
    },
    labelDetailsSupport = true,
    preselectSupport = true,
    resolveSupport = {
      properties = { "documentation", "detail", "additionalTextEdits", "sortText", "filterText", "insertText", "text
Edit", "insertTextFormat", "insertTextMode" }
    },
    snippetSupport = true,
    tagSupport = {
      valueSet = { 1 }
    }
  },
  completionItemKind = {
    valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }
  },
  completionList = {
    itemDefaults = { "commitCharacters", "editRange", "insertTextFormat", "insertTextMode", "data" }
  },
  contextSupport = true,
  dynamicRegistration = false,
  insertTextMode = 1
},

The client did advertise that it support additionalTextEdits which according to the LSP Specification must be specified.

Problem: When I tried to complete item with nvim-cmp, I check the log and indeed there is a textDocument/completion request and there is also a response. As such the editor still can complete the code but it does not auto import missing namespace if the class is not yet imported. Looking at the server response, I saw only textEdit in the response but no additionalTextEdits. For example, here is one of the CompletionItem returned:

 {      commitCharacters = { " ", "{", "}", "[", "]", "(", ")", ".", ",", ":", ";", "+", "-", "*", "/", "%", "&", "|", "^", "!", "~", "=", "<", ">", "?", "@", "#", "'", '"', "\\" },      data = {        ["$$__handler_id__$$"] = "2658541e-6e9d-4e48-804c-73397cf54e23",        Item1 = 11,        Item2 = 3985      },      detail = "NodaTime",      insertTextFormat = 1,      kind = 22,      label = "Instant",      sortText = "1~Instant NodaTime",      textEdit = {        newText = "Instant",        range = {          ["end"] = {            character = 12,            line = 13          },          start = {            character = 11,            line = 13          }        }      }    },

Every other features I tried so far works fine, including the Organize Import feature so it is probably not because of the client configuration. Thank you for taking your time to address this issue.