[clangd-dev] Confusing error message for invalid rangeLength in didChange request

Björn Linse via clangd-dev clangd-dev at lists.llvm.org
Sun Aug 4 04:02:47 PDT 2019


While working on implementing proper UTF-16 support for a LSP client,
I received this very confusing error message:

stderr E[12:26:16.762] Failed to update
/home/bjorn/dev/neovim/src/nvim/ui.c: Change's rangeLength (24)
doesn't match the computed range length (24).

Note both lengths are the same. I think this is caused by the
following code in
https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clangd/DraftStore.cpp

    // EndIndex and StartIndex are in bytes, but Change.rangeLength is in UTF-16
    // code units.
    ssize_t ComputedRangeLength =
        lspLength(Contents.substr(*StartIndex, *EndIndex - *StartIndex));

     if (Change.rangeLength && ComputedRangeLength != *Change.rangeLength)
      return llvm::make_error<llvm::StringError>(
           llvm::formatv("Change's rangeLength ({0}) doesn't match the "
                         "computed range length ({1}).",
                        *Change.rangeLength, *EndIndex - *StartIndex),
          llvm::errc::invalid_argument);

The *EndIndex - *StartIndex should rather be ComputedRangeLength in
the error message I think.

Best,
Björn


More information about the clangd-dev mailing list