From a69698f45fadefd2cabba8d5aa1a8e93463a6d49 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Wed, 27 Mar 2019 17:47:49 +0000 Subject: [clangd] Support utf-8 offsets (rather than utf-16) as a protocol extension Summary: Still some pieces to go here: unit tests for new SourceCode functionality and a command-line flag to force utf-8 mode. But wanted to get early feedback. Reviewers: hokein Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58275 llvm-svn: 357102 --- clang-tools-extra/clangd/Protocol.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'clang-tools-extra/clangd/Protocol.h') diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h index 468ead8df17..7cf414123f1 100644 --- a/clang-tools-extra/clangd/Protocol.h +++ b/clang-tools-extra/clangd/Protocol.h @@ -338,6 +338,18 @@ SymbolKind adjustKindToCapability(SymbolKind Kind, // https://github.com/Microsoft/language-server-protocol/issues/344 SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind Kind); +// Determines the encoding used to measure offsets and lengths of source in LSP. +enum class OffsetEncoding { + // Any string is legal on the wire. Unrecognized encodings parse as this. + UnsupportedEncoding, + // Length counts code units of UTF-16 encoded text. (Standard LSP behavior). + UTF16, + // Length counts bytes of UTF-8 encoded text. (Clangd extension). + UTF8, +}; +llvm::json::Value toJSON(const OffsetEncoding &); +bool fromJSON(const llvm::json::Value &, OffsetEncoding &); + // This struct doesn't mirror LSP! // The protocol defines deeply nested structures for client capabilities. // Instead of mapping them all, this just parses out the bits we care about. @@ -369,6 +381,9 @@ struct ClientCapabilities { /// Client supports CodeAction return value for textDocument/codeAction. /// textDocument.codeAction.codeActionLiteralSupport. bool CodeActionStructure = false; + + /// Supported encodings for LSP character offsets. (clangd extension). + llvm::Optional> offsetEncoding; }; bool fromJSON(const llvm::json::Value &, ClientCapabilities &); -- cgit v1.2.3