Add structures to support document formatting

This commit is contained in:
Daniel Martín 2017-12-25 14:08:36 +01:00
parent 5680ff2592
commit abc2edf05f
4 changed files with 44 additions and 2 deletions

View File

@ -34,6 +34,8 @@ const char* IpcIdToString(IpcId id) {
return "textDocument/documentHighlight";
case IpcId::TextDocumentHover:
return "textDocument/hover";
case IpcId::TextDocumentFormatting:
return "textDocument/formatting";
case IpcId::TextDocumentReferences:
return "textDocument/references";
case IpcId::TextDocumentDocumentSymbol:
@ -89,4 +91,4 @@ const char* IpcIdToString(IpcId id) {
BaseIpcMessage::BaseIpcMessage(IpcId method_id) : method_id(method_id) {}
BaseIpcMessage::~BaseIpcMessage() = default;
BaseIpcMessage::~BaseIpcMessage() = default;

View File

@ -22,6 +22,7 @@ enum class IpcId : int {
TextDocumentDefinition,
TextDocumentDocumentHighlight,
TextDocumentHover,
TextDocumentFormatting,
TextDocumentReferences,
TextDocumentDocumentSymbol,
TextDocumentDocumentLink,
@ -76,4 +77,4 @@ struct BaseIpcMessage {
template <typename T>
struct IpcMessage : public BaseIpcMessage {
IpcMessage() : BaseIpcMessage(T::kIpcId) {}
};
};

View File

@ -273,6 +273,25 @@ struct lsTextDocumentPositionParams {
};
MAKE_REFLECT_STRUCT(lsTextDocumentPositionParams, textDocument, position);
struct lsFormattingOptions {
// Size of a tab in spaces.
int tabSize;
// Prefer spaces over tabs.
bool insertSpaces;
};
MAKE_REFLECT_STRUCT(lsFormattingOptions, tabSize, insertSpaces);
struct lsTextDocumentFormattingParams {
// The text document.
lsTextDocumentIdentifier textDocument;
// The format options, like tabs or spaces.
lsFormattingOptions formattingOptions;
};
MAKE_REFLECT_STRUCT(lsTextDocumentFormattingParams,
textDocument,
formattingOptions);
struct lsTextEdit {
// The range of the text document to be manipulated. To insert
// text into a document create a range where start === end.

View File

@ -0,0 +1,20 @@
#include "message_handler.h"
namespace {
struct Ipc_TextDocumentFormatting
: public IpcMessage<Ipc_TextDocumentFormatting> {
const static IpcId kIpcId = IpcId::TextDocumentFormatting;
lsRequestId id;
lsTextDocumentFormattingParams params;
};
MAKE_REFLECT_STRUCT(Ipc_TextDocumentFormatting, id, params);
REGISTER_IPC_MESSAGE(Ipc_TextDocumentFormatting);
struct Out_TextDocumentFormatting
: public lsOutMessage<Out_TextDocumentFormatting> {
lsRequestId id;
std::vector<lsTextEdit> edits;
};
MAKE_REFLECT_STRUCT(Out_TextDocumentFormatting, jsonrpc, id, edits);
} // namespace