diff --git a/src/ipc.cc b/src/ipc.cc index b1463cd9..90d6a12f 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -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; \ No newline at end of file +BaseIpcMessage::~BaseIpcMessage() = default; diff --git a/src/ipc.h b/src/ipc.h index aca8a91b..c0860649 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -22,6 +22,7 @@ enum class IpcId : int { TextDocumentDefinition, TextDocumentDocumentHighlight, TextDocumentHover, + TextDocumentFormatting, TextDocumentReferences, TextDocumentDocumentSymbol, TextDocumentDocumentLink, @@ -76,4 +77,4 @@ struct BaseIpcMessage { template struct IpcMessage : public BaseIpcMessage { IpcMessage() : BaseIpcMessage(T::kIpcId) {} -}; \ No newline at end of file +}; diff --git a/src/language_server_api.h b/src/language_server_api.h index cd139ede..c600e74f 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -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. diff --git a/src/messages/text_document_formatting.cc b/src/messages/text_document_formatting.cc new file mode 100644 index 00000000..ac177f54 --- /dev/null +++ b/src/messages/text_document_formatting.cc @@ -0,0 +1,20 @@ +#include "message_handler.h" + +namespace { +struct Ipc_TextDocumentFormatting + : public IpcMessage { + 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 { + lsRequestId id; + std::vector edits; +}; +MAKE_REFLECT_STRUCT(Out_TextDocumentFormatting, jsonrpc, id, edits); +} // namespace