vim-lsp icon indicating copy to clipboard operation
vim-lsp copied to clipboard

Fix when textEdit type was InsertReplaceEdit

Open wordijp opened this issue 2 years ago • 1 comments

When using fuzzy match, when lsp returns InsertReplaceEdit, range was not found error. (I used volar-server when writing Vue)

  1. setup fuzzy match for asyncomplete.vim in vimrc
" vimrc
function! s:fuzzy_preprocessor(options, matches) abort
  let l:base = a:options["base"]

  " NOTE: There is an lsp with a '.' At the beginning when it is a member candidate.
  "       ex) volar-server
  if len(l:base) >= 2 && l:base[0] == '.'
    let l:base = l:base[1:]
    let a:options["startcol"] += 1
  endif

  let l:items = []
  for l:matches in values(a:matches)
    if len(l:base) > 0
      let l:items += filter(copy(l:matches['items']), '!empty(matchfuzzy([v:val["word"]], l:base))')
    else
      let l:items += l:matches['items']
    endif
  endfor

  call asyncomplete#preprocess_complete(a:options, l:items)
endfunction

let g:asyncomplete_preprocessor = [function('s:fuzzy_preprocessor')]
  1. try fuzzy match for vue code.
<script lang="ts" setup>
const a = [];
a.flt|
     ^
  try fuzzy match expand `filter`
</script>
  1. result completionItem json
{
  "label": "filter",
  "commitCharacters": [
    ".",
    ",",
    ";",
    "("
  ],
  "data": {
    "uri": "file:///e%3A/work/Web/vue/vue-typescript/src/App.vue.ts",
    "fileName": "e:/work/Web/vue/vue-typescript/src/App.vue.ts",
    "offset": 56,
    "originalItem": {
      "name": "filter",
      "kindModifiers": "declare",
      "sortText": "11",
      "kind": "method"
    }
  },
  "textEdit": {
    "replace": {
      "end": {
        "character": 5,
        "line": 2
      },
      "start": {
        "character": 2,
        "line": 2
      }
    },
    "newText": "filter",
    "insert": {
      "end": {
        "character": 5,
        "line": 2
      },
      "start": {
        "character": 2,
        "line": 2
      }
    }
  },
  "sortText": "11",
  "kind": 2,
  "detail": "(method) Array<any>.filter<any>(predicate: (value: any, index: number, array: any[]) => value is any, thisArg?: any): any[] (+1 overload)",
  "documentation": {
    "kind": "markdown",
    "value": "Returns the elements of an array that meet the condition specified in a callback function.\n\n*@param* `predicate` — A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.  \n\n*@param* `thisArg` — An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value."
  },
  "insertTextFormat": 1
}

wordijp avatar Jun 06 '22 12:06 wordijp

According to this issue, the choice of insert or replace is left to the client, so it is a protocol that is still starting to appear, so it was supported by replace, I think that the option to select insert is necessary in the future.

microsoft/language-server-protocol#1260

wordijp avatar Jun 06 '22 12:06 wordijp

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '22 03:08 stale[bot]

Thank you. This problem is fixed by https://github.com/prabirshrestha/vim-lsp/pull/1340

mattn avatar Aug 13 '22 02:08 mattn

OK, Thank you.

wordijp avatar Aug 13 '22 22:08 wordijp