diff --git a/include/Protocol/Basic.h b/include/Protocol/Basic.h index eb3afef1..642e22df 100644 --- a/include/Protocol/Basic.h +++ b/include/Protocol/Basic.h @@ -2,186 +2,45 @@ #include #include -#include #include +#include namespace clice::protocol { -using Integer = int; -using UInteger = unsigned int; -using String = std::string; -using StringRef = std::string_view; - +// reflectable struct definition template -struct Combine : Ts... {}; +struct Record : Ts... {}; -class URI { -private: - String scheme; - String authority; - String body; +#define CLICE_RECORD(name, ...) \ + struct name##Body; \ + using name = Record<__VA_ARGS__, name##Body>; \ + struct name##Body -public: -}; +/// range in [-2^31, 2^31- 1] +using integer = std::int32_t; -using DocumentUri = String; +/// range in [0, 2^31- 1] +using uinteger = std::uint32_t; + +using string = std::string; + +using DocumentUri = std::string; -/// Position in a text document expressed as zero-based line and zero-based character offset. struct Position { - /// line position in a document (zero-based). - UInteger line; - - /// character offset on a line in a document (zero-based). - /// The meaning of this offset is determined by the negotiated `PositionEncodingKind`. - UInteger character; + uinteger line; + uinteger character; }; -/// A range in a text document expressed as (zero-based) start and end positions. struct Range { - /// The range's start position. Position start; - - /// The range's end position. Position end; }; -/// An item to transfer a text document from the client to the server. struct TextDocumentItem { - /// The text document's URI. DocumentUri uri; - - /// The text document's language identifier. - String languageId; - - /// The version number of this document (it will strictly increase after each change, including - /// undo/redo). - Integer version; - - /// The content of the opened text document. - String text; -}; - -/// Text documents are identified using a URI. -struct TextDocumentIdentifier { - /// The text document's URI. - DocumentUri uri; -}; - -/// A parameter literal used in requests to pass a text document and a position inside that document. -struct TextDocumentPositionParams { - /// The text document. - TextDocumentIdentifier textDocument; - - /// The position inside the text document. - Position position; -}; - -/// A textual edit applicable to a text document. -struct TextEdit { - /// The range of the text document to be manipulated. To insert text into a document create a - /// range where start === end. - Range range; - - /// The string to be inserted. For delete operations use an empty string. - String newText; -}; - -/// Represents a location inside a resource, such as a line inside a text file. -struct Location { - URI uri; - Range range; -}; - -/// Represents a link between a source and a target location. -struct LocationLink { - /// Span of the origin of this link. - Range originSelectionRange; - - /// The target resource identifier of this link. - URI targetUri; - - /// The full target range of this link. If the target for example is a symbol then target range is the - /// range enclosing this symbol not including leading/trailing whitespace but everything else - /// like comments. This information is typically used to highlight the range in the editor. - Range targetRange; - - /// The range that should be selected and revealed when this link is being followed, e.g the name of a - /// function. Must be contained by the the `targetRange`. See also `DocumentSymbol#range` - Range targetSelectionRange; -}; - -/// Represents a diagnostic, such as a compiler error or warning. -/// Diagnostic objects are only valid in the scope of a resource. -struct Diagnostic { - - /// Represents a related message and source code location for a diagnostic. - /// This should be used to point to code locations that cause or are related to - /// a diagnostics, e.g when duplicating a symbol in a scope. - struct DiagnosticRelatedInformation { - /// The location of this related diagnostic information. - Location location; - - /// The message of this related diagnostic information. - String message; - }; - - /// Structure to capture a description for an error code. - struct CodeDescription { - /// An URI where the code is described. - URI href; - }; - - /// The range at which the message applies. - Range range; - - /// The diagnostic's severity. Can be omitted. If omitted it is up to the - /// client to interpret diagnostics as error, warning, info or hint. - Integer severity; - - /// The diagnostic's code. Can be omitted. - Integer code; - - /// A human-readable string describing the source of this diagnostic, e.g. 'typescript' or 'super lint'. - String source; - - /// The diagnostic's message. - String message; - - /// An array of related diagnostic information, e.g. when symbol-names within a scope collide all - /// definitions can be marked via this property. - // TODO: std::vector relatedInformation; -}; - -/// Represents a reference to a command. -struct Command { - /// Title of the command, like `save`. - String title; - - /// The identifier of the actual command handler. - String command; - - /// Arguments that the command handler should be invoked with. - /// arguments?: LSPAny[]; -}; - -struct MarkupKind { - StringRef m_Value; - - MarkupKind(StringRef value) : m_Value(value) {} - - /// Plain text is supported as a content format - constexpr inline static StringRef PlainText = "plaintext"; - - /// Markdown is supported as a content format - constexpr inline static StringRef Markdown = "markdown"; -}; - -struct MarkupContent { - /// The type of the Markup - MarkupKind kind; - - /// The content itself - String value; + string languageId; + integer version; + string text; }; } // namespace clice::protocol diff --git a/include/Protocol/Lifecycle/Initialize.h b/include/Protocol/Lifecycle/Initialize.h index e69de29b..f82b619d 100644 --- a/include/Protocol/Lifecycle/Initialize.h +++ b/include/Protocol/Lifecycle/Initialize.h @@ -0,0 +1,7 @@ +#include "../Basic.h" + +namespace clice::protocol { + + + +} \ No newline at end of file diff --git a/include/Protocol/Message.h b/include/Protocol/Message.h index 94b0db47..e69de29b 100644 --- a/include/Protocol/Message.h +++ b/include/Protocol/Message.h @@ -1,73 +0,0 @@ -#include - -namespace clice::protocol { - -/// A request message to describe a request between the client and the server. -/// Every processed request must send a response back to the sender of the request. -template -struct Request { - String jsonrpc = "2.0"; - - /// The request id. - Integer id; - - /// The method to be invoked. - String method; - - /// The method's params. - Params params; -}; - -enum class ErrorCode : Integer { - ParseError = -32700, - InvalidRequest = -32600, - MethodNotFound = -32601, - InvalidParams = -32602, - InternalError = -32603, -}; - -struct ResponseError { - /// A number indicating the error type that occurred. - ErrorCode code; - - /// A string providing a short description of the error. - String message; - - /// A Primitive or Structured value that contains additional information about the error. - // TODO: std::optional data; -}; - -/// A Response Message sent as a result of a request. If a request doesn’t provide a result value -/// the receiver of a request still needs to return a response message to conform to the JSON-RPC -/// specification. The result property of the ResponseMessage should be set to null in this case to signal a -/// successful request. -template -struct Response { - String jsonrpc = "2.0"; - - /// The request id. - Integer id; - - /// The result of the request. - std::optional result; - - /// The error of the request. - std::optional error; -}; - -/// A notification message to inform the server that the client has successfully registered itself. -template -struct Registration { - String jsonrpc = "2.0"; - - /// The method to be invoked. - String method; - - /// The registration's id. - Integer id; - - /// The registration's options. - RegistrationOptions registerOptions; -}; - -} // namespace clice::protocol