diff --git a/include/AST/FilterASTVisitor.h b/include/AST/FilterASTVisitor.h index 41b7e9c0..d040d5b8 100644 --- a/include/AST/FilterASTVisitor.h +++ b/include/AST/FilterASTVisitor.h @@ -1,6 +1,6 @@ #pragma once -#include "Basic/SourceCode.h" +#include "AST/SourceCode.h" #include "Compiler/AST.h" #include "clang/AST/RecursiveASTVisitor.h" diff --git a/include/Basic/SourceCode.h b/include/AST/SourceCode.h similarity index 98% rename from include/Basic/SourceCode.h rename to include/AST/SourceCode.h index f7b9ffbe..800884aa 100644 --- a/include/Basic/SourceCode.h +++ b/include/AST/SourceCode.h @@ -1,6 +1,6 @@ #pragma once -#include "AST/SourceLocation.h" +#include "SourceLocation.h" #include "clang/Lex/Token.h" #include "llvm/ADT/FunctionExtras.h" diff --git a/include/Basic/Basic.h b/include/Basic/Basic.h deleted file mode 100644 index 4a902fbd..00000000 --- a/include/Basic/Basic.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -#include "llvm/ADT/StringRef.h" - -namespace clice::proto { - -/// range in [-2^31, 2^31- 1] -using integer = std::int32_t; - -/// range in [0, 2^31- 1] -using uinteger = std::uint32_t; - -using string = std::string; - -using string_literal = llvm::StringLiteral; - -template -using array = std::vector; - -using DocumentUri = std::string; - -using URI = std::string; - -struct None {}; - -} // namespace clice::proto diff --git a/include/Basic/Document.h b/include/Basic/Document.h deleted file mode 100644 index 91e4c19e..00000000 --- a/include/Basic/Document.h +++ /dev/null @@ -1,122 +0,0 @@ -#pragma once - -#include "Location.h" - -namespace clice::proto { - -struct TextDocumentSyncKind : refl::Enum { - using Enum::Enum; - - enum Kind : std::uint8_t { - /// Documents should not be synced at all. - None = 0, - - /// Documents are synced by always sending the full content of the document. - Full = 1, - - /// Documents are synced by sending the full content on open. After that only - /// incremental updates to the document are sent. - Incremental = 2, - }; -}; - -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). - uinteger version; - - /// The content of the opened text document. - string text; -}; - -struct TextDocumentIdentifier { - /// The text document's URI. - DocumentUri uri; -}; - -struct VersionedTextDocumentIdentifier { - /// The text document's URI. - DocumentUri uri; - /// The version number of this document. - /// - /// The version number of a document will increase after each change, - /// including undo/redo. The number doesn't need to be consecutive. - integer version; -}; - -/// An event describing a change to a text document. If only a text is provided -/// it is considered to be the full content of the document. -struct TextDocumentContentChangeEvent { - /// The range of the document that changed. - Range range; - - /// The new text for the provided range. - string text; -}; - -struct DidChangeTextDocumentParams { - /// The document that did change. The version number points - /// to the version after all provided content changes have - /// been applied. - VersionedTextDocumentIdentifier textDocument; - - /// The actual content changes. The content changes describe single state - /// changes to the document. So if there are two content changes c1 (at - /// array index 0) and c2 (at array index 1) for a document in state S then - /// c1 moves the document from S to S' and c2 from S' to S''. So c1 is - /// computed on the state S and c2 is computed on the state S'. - /// - /// To mirror the content of a document using change events use the following - /// approach: - /// - start with the same initial content - /// - apply the 'textDocument/didChange' notifications in the order you - /// receive them. - /// - apply the `TextDocumentContentChangeEvent`s in a single notification - /// in the order you receive them. - std::vector contentChanges; -}; - -struct TextDocumentPositionParams { - /// The text document. - TextDocumentIdentifier textDocument; - - /// The position inside the text document. - Position position; -}; - -using MarkupKind = string; - -struct MarkupContent { - /// The type of the Markup. - MarkupKind kind = "markdown"; - - /// The content itself. - string value; -}; - -struct DidOpenTextDocumentParams { - /// The document that was opened. - TextDocumentItem textDocument; -}; - -struct DidSaveTextDocumentParams { - /// The document that was saved. - TextDocumentIdentifier textDocument; - - /// Optional the content when saved. Depends on the includeText value - /// when the save notifcation was requested. - string text; -}; - -struct DidCloseTextDocumentParams { - /// The document that was closed. - TextDocumentIdentifier textDocument; -}; - -} // namespace clice::proto diff --git a/include/Basic/Lifecycle.h b/include/Basic/Lifecycle.h deleted file mode 100644 index d5cf4c57..00000000 --- a/include/Basic/Lifecycle.h +++ /dev/null @@ -1,195 +0,0 @@ -#pragma once - -#include "Workspace.h" -#include "Feature/Lookup.h" -#include "Feature/DocumentHighlight.h" -#include "Feature/DocumentLink.h" -#include "Feature/Hover.h" -#include "Feature/CodeLens.h" -#include "Feature/FoldingRange.h" -#include "Feature/DocumentSymbol.h" -#include "Feature/SemanticTokens.h" -#include "Feature/InlayHint.h" -#include "Feature/CodeCompletion.h" -#include "Feature/SignatureHelp.h" -#include "Feature/CodeAction.h" -#include "Feature/Formatting.h" - -namespace clice::proto { - -struct ClientCapabilities { - /// General client capabilities. - struct { - /// The position encodings supported by the client. Client and server - /// have to agree on the same position encoding to ensure that offsets - /// (e.g. character position in a line) are interpreted the same on both - /// side. - /// - /// To keep the protocol backwards compatible the following applies: if - /// the value 'utf-16' is missing from the array of position encodings - /// servers can assume that the client supports UTF-16. UTF-16 is - /// therefore a mandatory encoding. - /// - /// If omitted it defaults to ['utf-16']. - /// - /// Implementation considerations: since the conversion from one encoding - /// into another requires the content of the file / line the conversion - /// is best done where the file is read which is usually on the server - /// side. - std::vector positionEncodings = {PositionEncodingKind::UTF16}; - } general; -}; - -struct InitializeParams { - /// Information about the client. - struct { - /// The name of the client as defined by the client. - std::string name; - - /// The client's version as defined by the client. - std::string version; - } clientInfo; - - /// The capabilities provided by the client (editor or tool). - ClientCapabilities capabilities; - - /// The workspace folders configured in the client when the server starts. - /// This property is only available if the client supports workspace folders. - /// It can be `null` if the client supports workspace folders but none are - /// configured. - std::vector workspaceFolders; -}; - -struct SemanticTokensOptions { - /// The legend used by the server. - struct SemanticTokensLegend { - /// The token types a server uses. - std::vector tokenTypes; - - /// The token modifiers a server uses. - std::vector tokenModifiers; - } legend; - - /// Server supports providing semantic tokens for a specific range - /// of a document. - bool range = false; - - /// Server supports providing semantic tokens for a full document. - bool full = true; -}; - -struct SemanticTokens { - /// The actual tokens. - std::vector data; -}; - -/// A set of predefined range kinds. -enum class FoldingRangeKind { - /// Folding range for a comment. - Comment, - - /// Folding range for imports or includes. - Imports, - - /// Folding range for a region. - Region, -}; - -/// Represents a folding range. To be valid, start and end line must be bigger -/// than zero and smaller than the number of lines in the document. Clients -/// are free to ignore invalid ranges. -struct FoldingRange { - /// The zero-based start line of the range to fold. The folded area starts - /// after the line's last character. To be valid, the end must be zero or - /// larger and smaller than the number of lines in the document. - uint32_t startLine; - - /// The zero-based character offset from where the folded range starts. If - /// not defined, defaults to the length of the start line. - std::optional startCharacter; - - /// The zero-based end line of the range to fold. The folded area ends with - /// the line's last character. To be valid, the end must be zero or larger - /// and smaller than the number of lines in the document. - uint32_t endLine; - - /// The zero-based character offset before the folded range ends. If not - /// defined, defaults to the length of the end line. - std::optional endCharacter; - - /// Describes the kind of the folding range such as `comment` or `region`. - /// The kind is used to categorize folding ranges and used by commands like - /// 'Fold all comments'. See [FoldingRangeKind](#FoldingRangeKind) for an - /// enumeration of standardized kinds. - FoldingRangeKind kind; - - /// The text that the client should show when the specified range is - /// collapsed. If not defined or not supported by the client, a default - /// will be chosen by the client. - /// - /// @since 3.17.0 - proposed - std::optional collapsedText; -}; - -/// Server Capability. -struct ServerCapabilities { - /// The position encoding the server picked from the encodings offered - /// by the client via the client capability `general.positionEncodings`. - /// - /// If the client didn't provide any position encodings the only valid - /// value that a server can return is 'utf-16'. - /// - /// If omitted it defaults to 'utf-16'. - PositionEncodingKind positionEncoding = PositionEncodingKind::UTF16; - - /// Defines how text documents are synced. Is either a detailed structure - /// defining each notification or for backwards compatibility the - /// TextDocumentSyncKind number. If omitted it defaults to - /// `TextDocumentSyncKind.None`. - TextDocumentSyncKind textDocumentSync = TextDocumentSyncKind::None; - - /// The server provides go to declaration support. - LookupOptions declarationProvider = {}; - - /// The server provides goto definition support. - LookupOptions definitionProvider = {}; - - /// The server provides goto type definition support. - LookupOptions typeDefinitionProvider = {}; - - /// The server provides goto implementation support. - LookupOptions implementationProvider = {}; - - /// The server provides find references support. - LookupOptions referencesProvider = {}; - - /// The server provides call hierarchy support. - LookupOptions callHierarchyProvider = {}; - - /// The server provides type hierarchy support. - LookupOptions typeHierarchyProvider = {}; - - /// The server provides semantic tokens support. - SemanticTokensOptions semanticTokensProvider; - - /// The server provides folding provider support. - bool foldingRangeProvider = true; -}; - -struct InitializeResult { - /// The capabilities the language server provides. - ServerCapabilities capabilities; - - /// Information about the server. - struct { - /// The name of the server as defined by the server. - std::string name; - - /// The server's version as defined by the server. - std::string version; - } serverInfo; -}; - -struct InitializedParams {}; - -} // namespace clice::proto diff --git a/include/Basic/Location.h b/include/Basic/Location.h deleted file mode 100644 index d6692499..00000000 --- a/include/Basic/Location.h +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include "Basic.h" -#include "Support/Enum.h" - -namespace clice::proto { - -/// A set of predefined position encoding kinds. -struct PositionEncodingKind : refl::Enum { - using Enum::Enum; - - constexpr inline static std::string_view UTF8 = "utf-8"; - constexpr inline static std::string_view UTF16 = "utf-16"; - constexpr inline static std::string_view UTF32 = "utf-32"; - - constexpr inline static std::array All = {UTF8, UTF16, UTF32}; -}; - -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; -}; - -constexpr bool operator== (const proto::Position& lhs, const proto::Position rhs) { - return lhs.character == rhs.character && lhs.line == rhs.line; -} - -constexpr auto operator<=> (const proto::Position& lhs, const proto::Position rhs) { - return std::tie(lhs.line, lhs.character) <=> std::tie(rhs.line, rhs.character); -} - -struct Range { - /// The range's start position. - Position start; - - /// The range's end position. - Position end; -}; - -struct Location { - DocumentUri uri; - - Range range; -}; - -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; -}; - -} // namespace clice::proto - diff --git a/include/Basic/Markdown.h b/include/Basic/Markdown.h deleted file mode 100644 index 2d7fde63..00000000 --- a/include/Basic/Markdown.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -namespace clice { - -class Markdown { -public: - Markdown parse(llvm::StringRef content); - -private: -}; - -} // namespace clice diff --git a/include/Basic/Workspace.h b/include/Basic/Workspace.h deleted file mode 100644 index bd59faf0..00000000 --- a/include/Basic/Workspace.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "Basic.h" - -namespace clice::proto { - -struct WorkspaceFolder { - /// The associated URI for this workspace folder. - URI uri; - - /// The name of the workspace folder. Used to refer to this workspace folder - /// in the user interface. - std::string name; -}; - -struct DidChangeWatchedFilesParams {}; - -} // namespace clice::proto diff --git a/include/Compiler/AST.h b/include/Compiler/AST.h index 67b1e875..5fa4e557 100644 --- a/include/Compiler/AST.h +++ b/include/Compiler/AST.h @@ -1,9 +1,8 @@ #pragma once #include "Directive.h" -#include "Basic/SourceCode.h" +#include "AST/SourceCode.h" #include "AST/Resolver.h" -#include "Basic/SourceCode.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendActions.h" diff --git a/include/Feature/CodeAction.h b/include/Feature/CodeAction.h index 99185266..3f59c932 100644 --- a/include/Feature/CodeAction.h +++ b/include/Feature/CodeAction.h @@ -1,9 +1,2 @@ #pragma once -#include "Basic/Document.h" - -namespace clice::proto { - -struct CodeActionParams {}; - -} // namespace clice::proto diff --git a/include/Feature/CodeLens.h b/include/Feature/CodeLens.h index 175c7904..3f59c932 100644 --- a/include/Feature/CodeLens.h +++ b/include/Feature/CodeLens.h @@ -1,7 +1,2 @@ -#include "Basic/Document.h" +#pragma once -namespace clice::proto { - -struct CodeLensParams {}; - -} // namespace clice::proto diff --git a/include/Feature/DocumentHighlight.h b/include/Feature/DocumentHighlight.h index 49453ad2..2d863e71 100644 --- a/include/Feature/DocumentHighlight.h +++ b/include/Feature/DocumentHighlight.h @@ -1,9 +1,3 @@ #pragma once -#include "Basic/Document.h" - -namespace clice::proto { - -using DocumentHighlightParams = TextDocumentPositionParams; - -} +namespace clice::proto {} diff --git a/include/Feature/DocumentLink.h b/include/Feature/DocumentLink.h index 8e2be9b1..6f70f09b 100644 --- a/include/Feature/DocumentLink.h +++ b/include/Feature/DocumentLink.h @@ -1,9 +1 @@ #pragma once - -#include "Basic/Document.h" - -namespace clice::proto { - -struct DocumentLinkParams {}; - -} // namespace clice::proto diff --git a/include/Feature/DocumentSymbol.h b/include/Feature/DocumentSymbol.h index 8f198e05..1d8189b6 100644 --- a/include/Feature/DocumentSymbol.h +++ b/include/Feature/DocumentSymbol.h @@ -1,7 +1,7 @@ #pragma once -#include "Basic/Document.h" -#include "Basic/SourceCode.h" +#include "Server/Protocol.h" +#include "AST/SourceCode.h" #include "Index/Shared.h" #include "Support/JSON.h" diff --git a/include/Feature/FoldingRange.h b/include/Feature/FoldingRange.h index 62e1d019..104372cb 100644 --- a/include/Feature/FoldingRange.h +++ b/include/Feature/FoldingRange.h @@ -1,6 +1,6 @@ #pragma once -#include "Basic/SourceCode.h" +#include "AST/SourceCode.h" #include "Index/Shared.h" #include "Support/Enum.h" diff --git a/include/Feature/Formatting.h b/include/Feature/Formatting.h index 486a8e66..6f70f09b 100644 --- a/include/Feature/Formatting.h +++ b/include/Feature/Formatting.h @@ -1,11 +1 @@ #pragma once - -#include "Basic/Document.h" - -namespace clice::proto { - -struct DocumentFormattingParams {}; - -struct DocumentRangeFormattingParams {}; - -} // namespace clice::proto diff --git a/include/Feature/Hover.h b/include/Feature/Hover.h index a3e644af..9a7ea04d 100644 --- a/include/Feature/Hover.h +++ b/include/Feature/Hover.h @@ -1,7 +1,7 @@ #pragma once #include "AST/SymbolKind.h" -#include "Basic/SourceCode.h" +#include "AST/SourceCode.h" #include "Index/Shared.h" namespace clice { diff --git a/include/Feature/InlayHint.h b/include/Feature/InlayHint.h index f4589e99..c91da7a2 100644 --- a/include/Feature/InlayHint.h +++ b/include/Feature/InlayHint.h @@ -1,7 +1,7 @@ #pragma once -#include "Basic/Document.h" -#include "Basic/SourceCode.h" +#include "Server/Protocol.h" +#include "AST/SourceCode.h" #include "Index/Shared.h" #include "Support/JSON.h" diff --git a/include/Feature/Lookup.h b/include/Feature/Lookup.h index 0c1ee055..778b062b 100644 --- a/include/Feature/Lookup.h +++ b/include/Feature/Lookup.h @@ -1,4 +1,6 @@ -#include "Basic/Document.h" +#pragma once + +#include "Server/Protocol.h" #include "Support/Struct.h" #include "AST/SymbolKind.h" diff --git a/include/Feature/SemanticTokens.h b/include/Feature/SemanticTokens.h index 516e8589..855bcb30 100644 --- a/include/Feature/SemanticTokens.h +++ b/include/Feature/SemanticTokens.h @@ -1,7 +1,7 @@ #pragma once #include "AST/SymbolKind.h" -#include "Basic/SourceCode.h" +#include "AST/SourceCode.h" #include "Index/Shared.h" namespace clice { diff --git a/include/Feature/SignatureHelp.h b/include/Feature/SignatureHelp.h index 3d69d006..80041fac 100644 --- a/include/Feature/SignatureHelp.h +++ b/include/Feature/SignatureHelp.h @@ -1,6 +1,9 @@ #pragma once -#include "Basic/Location.h" +#include +#include + +#include "llvm/ADT/StringRef.h" namespace clice { @@ -10,7 +13,7 @@ namespace config { struct SignatureHelpOption {}; -} // namespace config +} // namespace config namespace feature { @@ -18,10 +21,9 @@ struct SignatureHelpItem {}; using SignatureHelpResult = std::vector; -SignatureHelpResult signatureHelp(CompilationParams& params, - const config::SignatureHelpOption& option); +SignatureHelpResult signatureHelp(CompilationParams ¶ms, + const config::SignatureHelpOption &option); -} // namespace feature - -} // namespace clice +} // namespace feature +} // namespace clice diff --git a/include/Index/SymbolIndex.h b/include/Index/SymbolIndex.h index 6713b256..3d119d7d 100644 --- a/include/Index/SymbolIndex.h +++ b/include/Index/SymbolIndex.h @@ -4,7 +4,7 @@ #include "ArrayView.h" #include "AST/SymbolKind.h" #include "AST/RelationKind.h" -#include "Basic/SourceCode.h" +#include "AST/SourceCode.h" #include "Support/JSON.h" namespace clice { diff --git a/include/Server/IncludeGraph.h b/include/Server/IncludeGraph.h index 912d090b..3d1f1879 100644 --- a/include/Server/IncludeGraph.h +++ b/include/Server/IncludeGraph.h @@ -3,7 +3,7 @@ #include "Config.h" #include "Protocol.h" #include "Async/Async.h" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" #include "Compiler/Command.h" #include "Compiler/Compilation.h" #include "Support/JSON.h" diff --git a/include/Server/Indexer.h b/include/Server/Indexer.h index 9ffa7b39..c2709cc1 100644 --- a/include/Server/Indexer.h +++ b/include/Server/Indexer.h @@ -6,6 +6,7 @@ #include "Compiler/Command.h" #include "Index/FeatureIndex.h" #include "llvm/ADT/StringSet.h" +#include "Feature/Lookup.h" namespace clice { diff --git a/include/Server/Protocol.h b/include/Server/Protocol.h index 707ecbe6..2f9cd2f4 100644 --- a/include/Server/Protocol.h +++ b/include/Server/Protocol.h @@ -1,6 +1,392 @@ #pragma once -#include "Basic/Lifecycle.h" +#include +#include +#include + +#include "Support/Enum.h" +#include "llvm/ADT/StringRef.h" + +namespace clice::proto { + +using integer = std::int32_t; + +/// range in [0, 2^31- 1] +using uinteger = std::uint32_t; + +using string = std::string; + +using string_literal = llvm::StringLiteral; + +template +using array = std::vector; + +using DocumentUri = std::string; + +using URI = std::string; + +struct None {}; + +/// A set of predefined position encoding kinds. +struct PositionEncodingKind : refl::Enum { + using Enum::Enum; + + constexpr inline static std::string_view UTF8 = "utf-8"; + constexpr inline static std::string_view UTF16 = "utf-16"; + constexpr inline static std::string_view UTF32 = "utf-32"; + + constexpr inline static std::array All = {UTF8, UTF16, UTF32}; +}; + +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; +}; + +constexpr bool operator== (const proto::Position& lhs, const proto::Position rhs) { + return lhs.character == rhs.character && lhs.line == rhs.line; +} + +constexpr auto operator<=> (const proto::Position& lhs, const proto::Position rhs) { + return std::tie(lhs.line, lhs.character) <=> std::tie(rhs.line, rhs.character); +} + +struct Range { + /// The range's start position. + Position start; + + /// The range's end position. + Position end; +}; + +struct Location { + DocumentUri uri; + + Range range; +}; + +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; +}; + +struct TextDocumentSyncKind : refl::Enum { + using Enum::Enum; + + enum Kind : std::uint8_t { + /// Documents should not be synced at all. + None = 0, + + /// Documents are synced by always sending the full content of the document. + Full = 1, + + /// Documents are synced by sending the full content on open. After that + /// only + /// incremental updates to the document are sent. + Incremental = 2, + }; +}; + +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). + uinteger version; + + /// The content of the opened text document. + string text; +}; + +struct TextDocumentIdentifier { + /// The text document's URI. + DocumentUri uri; +}; + +struct VersionedTextDocumentIdentifier { + /// The text document's URI. + DocumentUri uri; + /// The version number of this document. + /// + /// The version number of a document will increase after each change, + /// including undo/redo. The number doesn't need to be consecutive. + integer version; +}; + +/// An event describing a change to a text document. If only a text is provided +/// it is considered to be the full content of the document. +struct TextDocumentContentChangeEvent { + /// The range of the document that changed. + Range range; + + /// The new text for the provided range. + string text; +}; + +struct DidChangeTextDocumentParams { + /// The document that did change. The version number points + /// to the version after all provided content changes have + /// been applied. + VersionedTextDocumentIdentifier textDocument; + + /// The actual content changes. The content changes describe single state + /// changes to the document. So if there are two content changes c1 (at + /// array index 0) and c2 (at array index 1) for a document in state S then + /// c1 moves the document from S to S' and c2 from S' to S''. So c1 is + /// computed on the state S and c2 is computed on the state S'. + /// + /// To mirror the content of a document using change events use the following + /// approach: + /// - start with the same initial content + /// - apply the 'textDocument/didChange' notifications in the order you + /// receive them. + /// - apply the `TextDocumentContentChangeEvent`s in a single notification + /// in the order you receive them. + std::vector contentChanges; +}; + +struct TextDocumentPositionParams { + /// The text document. + TextDocumentIdentifier textDocument; + + /// The position inside the text document. + Position position; +}; + +using MarkupKind = string; + +struct MarkupContent { + /// The type of the Markup. + MarkupKind kind = "markdown"; + + /// The content itself. + string value; +}; + +struct DidOpenTextDocumentParams { + /// The document that was opened. + TextDocumentItem textDocument; +}; + +struct DidSaveTextDocumentParams { + /// The document that was saved. + TextDocumentIdentifier textDocument; + + /// Optional the content when saved. Depends on the includeText value + /// when the save notifcation was requested. + string text; +}; + +struct DidCloseTextDocumentParams { + /// The document that was closed. + TextDocumentIdentifier textDocument; +}; + +} // namespace clice::proto + +namespace clice::proto { + +struct WorkspaceFolder { + /// The associated URI for this workspace folder. + URI uri; + + /// The name of the workspace folder. Used to refer to this workspace folder + /// in the user interface. + std::string name; +}; + +struct DidChangeWatchedFilesParams {}; + +struct ClientCapabilities { + /// General client capabilities. + struct { + /// The position encodings supported by the client. Client and server + /// have to agree on the same position encoding to ensure that offsets + /// (e.g. character position in a line) are interpreted the same on both + /// side. + /// + /// To keep the protocol backwards compatible the following applies: if + /// the value 'utf-16' is missing from the array of position encodings + /// servers can assume that the client supports UTF-16. UTF-16 is + /// therefore a mandatory encoding. + /// + /// If omitted it defaults to ['utf-16']. + /// + /// Implementation considerations: since the conversion from one encoding + /// into another requires the content of the file / line the conversion + /// is best done where the file is read which is usually on the server + /// side. + std::vector positionEncodings = {PositionEncodingKind::UTF16}; + } general; +}; + +struct InitializeParams { + /// Information about the client. + struct { + /// The name of the client as defined by the client. + std::string name; + + /// The client's version as defined by the client. + std::string version; + } clientInfo; + + /// The capabilities provided by the client (editor or tool). + ClientCapabilities capabilities; + + /// The workspace folders configured in the client when the server starts. + /// This property is only available if the client supports workspace folders. + /// It can be `null` if the client supports workspace folders but none are + /// configured. + std::vector workspaceFolders; +}; + +struct SemanticTokensOptions { + /// The legend used by the server. + struct SemanticTokensLegend { + /// The token types a server uses. + std::vector tokenTypes; + + /// The token modifiers a server uses. + std::vector tokenModifiers; + } legend; + + /// Server supports providing semantic tokens for a specific range + /// of a document. + bool range = false; + + /// Server supports providing semantic tokens for a full document. + bool full = true; +}; + +struct SemanticTokens { + /// The actual tokens. + std::vector data; +}; + +/// A set of predefined range kinds. +enum class FoldingRangeKind { + /// Folding range for a comment. + Comment, + + /// Folding range for imports or includes. + Imports, + + /// Folding range for a region. + Region, +}; + +/// Represents a folding range. To be valid, start and end line must be bigger +/// than zero and smaller than the number of lines in the document. Clients +/// are free to ignore invalid ranges. +struct FoldingRange { + /// The zero-based start line of the range to fold. The folded area starts + /// after the line's last character. To be valid, the end must be zero or + /// larger and smaller than the number of lines in the document. + uint32_t startLine; + + /// The zero-based character offset from where the folded range starts. If + /// not defined, defaults to the length of the start line. + std::optional startCharacter; + + /// The zero-based end line of the range to fold. The folded area ends with + /// the line's last character. To be valid, the end must be zero or larger + /// and smaller than the number of lines in the document. + uint32_t endLine; + + /// The zero-based character offset before the folded range ends. If not + /// defined, defaults to the length of the end line. + std::optional endCharacter; + + /// Describes the kind of the folding range such as `comment` or `region`. + /// The kind is used to categorize folding ranges and used by commands like + /// 'Fold all comments'. See [FoldingRangeKind](#FoldingRangeKind) for an + /// enumeration of standardized kinds. + FoldingRangeKind kind; + + /// The text that the client should show when the specified range is + /// collapsed. If not defined or not supported by the client, a default + /// will be chosen by the client. + /// + /// @since 3.17.0 - proposed + std::optional collapsedText; +}; + +/// Server Capability. +struct ServerCapabilities { + /// The position encoding the server picked from the encodings offered + /// by the client via the client capability `general.positionEncodings`. + /// + /// If the client didn't provide any position encodings the only valid + /// value that a server can return is 'utf-16'. + /// + /// If omitted it defaults to 'utf-16'. + PositionEncodingKind positionEncoding = PositionEncodingKind::UTF16; + + /// Defines how text documents are synced. Is either a detailed structure + /// defining each notification or for backwards compatibility the + /// TextDocumentSyncKind number. If omitted it defaults to + /// `TextDocumentSyncKind.None`. + TextDocumentSyncKind textDocumentSync = TextDocumentSyncKind::None; + + /// The server provides go to declaration support. + bool declarationProvider = true; + + /// The server provides goto definition support. + bool definitionProvider = true; + + /// The server provides goto type definition support. + bool typeDefinitionProvider = true; + + /// The server provides goto implementation support. + bool implementationProvider = true; + + /// The server provides find references support. + bool referencesProvider = true; + + /// The server provides call hierarchy support. + bool callHierarchyProvider = true; + + /// The server provides type hierarchy support. + bool typeHierarchyProvider = true; + + /// The server provides semantic tokens support. + SemanticTokensOptions semanticTokensProvider; + + /// The server provides folding provider support. + bool foldingRangeProvider = true; +}; + +struct InitializeResult { + /// The capabilities the language server provides. + ServerCapabilities capabilities; + + /// Information about the server. + struct { + /// The name of the server as defined by the server. + std::string name; + + /// The server's version as defined by the server. + std::string version; + } serverInfo; +}; + +struct InitializedParams {}; + +} // namespace clice::proto namespace clice::proto { diff --git a/include/Basic/SourceConverter.h b/include/Server/SourceConverter.h similarity index 98% rename from include/Basic/SourceConverter.h rename to include/Server/SourceConverter.h index 43561b0d..53f377a6 100644 --- a/include/Basic/SourceConverter.h +++ b/include/Server/SourceConverter.h @@ -1,7 +1,7 @@ #pragma once -#include "Basic/Location.h" -#include "Basic/SourceCode.h" +#include "Server/Protocol.h" +#include "AST/SourceCode.h" #include "clang/Basic/SourceLocation.h" namespace clice { diff --git a/include/Support/Struct.h b/include/Support/Struct.h index 2aa45756..70ec1b6e 100644 --- a/include/Support/Struct.h +++ b/include/Support/Struct.h @@ -12,10 +12,10 @@ namespace clice::refl { namespace impl { struct Any { - constexpr Any(std::size_t); + consteval Any(std::size_t); template - constexpr operator T () const; + consteval operator T () const; }; template diff --git a/include/Test/CTest.h b/include/Test/CTest.h index 3dbba896..108d8391 100644 --- a/include/Test/CTest.h +++ b/include/Test/CTest.h @@ -1,6 +1,7 @@ #pragma once #include "Test.h" +#include "Server/Protocol.h" #include "Compiler/Compilation.h" namespace clice::testing { diff --git a/include/Test/IndexTester.h b/include/Test/IndexTester.h index 6f971b1a..62610607 100644 --- a/include/Test/IndexTester.h +++ b/include/Test/IndexTester.h @@ -1,6 +1,6 @@ #include "Test/CTest.h" #include "Index/SymbolIndex.h" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" namespace clice::testing { diff --git a/include/Test/Test.h b/include/Test/Test.h index b1fedcaa..0d63b298 100644 --- a/include/Test/Test.h +++ b/include/Test/Test.h @@ -1,7 +1,6 @@ #pragma once #include "gtest/gtest.h" -#include "Basic/Location.h" #include "Support/JSON.h" #include "Support/Format.h" #include "Support/Compare.h" diff --git a/scripts/build-full-llvm.sh b/scripts/build-full-llvm.sh new file mode 100755 index 00000000..fe635e74 --- /dev/null +++ b/scripts/build-full-llvm.sh @@ -0,0 +1,11 @@ +cmake \ + -G Ninja -S ./llvm \ + -B build-llvm \ + -DLLVM_USE_LINKER=lld \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \ + -DLLVM_ENABLE_RUNTIMES=compiler-rt +cmake --build build-llvm +cmake --install build-llvm diff --git a/src/Basic/SourceCode.cpp b/src/AST/SourceCode.cpp similarity index 97% rename from src/Basic/SourceCode.cpp rename to src/AST/SourceCode.cpp index ae712cd7..b61b54a5 100644 --- a/src/Basic/SourceCode.cpp +++ b/src/AST/SourceCode.cpp @@ -1,4 +1,4 @@ -#include "Basic/SourceCode.h" +#include "AST/SourceCode.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" diff --git a/src/Compiler/Preamble.cpp b/src/Compiler/Preamble.cpp index e1e816e9..4bc9a8ec 100644 --- a/src/Compiler/Preamble.cpp +++ b/src/Compiler/Preamble.cpp @@ -1,5 +1,5 @@ #include "Compiler/Preamble.h" -#include "Basic/SourceCode.h" +#include "AST/SourceCode.h" #include "Support/Format.h" namespace clice { diff --git a/src/Feature/CodeCompletion.cpp b/src/Feature/CodeCompletion.cpp index 2cfb3d43..4ace76cd 100644 --- a/src/Feature/CodeCompletion.cpp +++ b/src/Feature/CodeCompletion.cpp @@ -1,5 +1,4 @@ #include "AST/SymbolKind.h" -#include "Basic/SourceConverter.h" #include "Compiler/Compilation.h" #include "Feature/CodeCompletion.h" #include "clang/Sema/CodeCompleteConsumer.h" diff --git a/src/Feature/DocumentSymbol.cpp b/src/Feature/DocumentSymbol.cpp index 338b887d..7f7ea2ff 100644 --- a/src/Feature/DocumentSymbol.cpp +++ b/src/Feature/DocumentSymbol.cpp @@ -1,5 +1,5 @@ #include "AST/FilterASTVisitor.h" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" #include "Compiler/Compilation.h" #include "Feature/DocumentSymbol.h" diff --git a/src/Feature/InlayHint.cpp b/src/Feature/InlayHint.cpp index 9acb8ad6..f8e7e2f9 100644 --- a/src/Feature/InlayHint.cpp +++ b/src/Feature/InlayHint.cpp @@ -1,5 +1,5 @@ #include "AST/FilterASTVisitor.h" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" #include "Compiler/Compilation.h" #include "Feature/InlayHint.h" diff --git a/src/Index/SymbolIndex.cpp b/src/Index/SymbolIndex.cpp index 2d06feb5..b9cf18bc 100644 --- a/src/Index/SymbolIndex.cpp +++ b/src/Index/SymbolIndex.cpp @@ -3,7 +3,7 @@ #include "Index/Index.h" #include "Index/USR.h" #include "AST/Semantic.h" -#include "Basic/SourceCode.h" +#include "AST/SourceCode.h" #include "Index/SymbolIndex.h" #include "Support/Binary.h" #include "Support/Compare.h" diff --git a/src/Server/Feature.cpp b/src/Server/Feature.cpp index c2c9c279..076114dc 100644 --- a/src/Server/Feature.cpp +++ b/src/Server/Feature.cpp @@ -1,4 +1,3 @@ -#include "Basic/SourceConverter.h" #include "Server/Server.h" namespace clice { diff --git a/src/Server/LSPConverter.cpp b/src/Server/LSPConverter.cpp index d7af9bdb..6e1c38be 100644 --- a/src/Server/LSPConverter.cpp +++ b/src/Server/LSPConverter.cpp @@ -1,5 +1,5 @@ #include "Server/LSPConverter.h" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" namespace clice { diff --git a/src/Server/Lifecycle.cpp b/src/Server/Lifecycle.cpp index 3a22b2f9..f40b1316 100644 --- a/src/Server/Lifecycle.cpp +++ b/src/Server/Lifecycle.cpp @@ -1,4 +1,4 @@ -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" #include "Server/Server.h" #include "Support/FileSystem.h" diff --git a/src/Basic/SourceConverter.cpp b/src/Server/SourceConverter.cpp similarity index 98% rename from src/Basic/SourceConverter.cpp rename to src/Server/SourceConverter.cpp index de7dad58..9ab8862b 100644 --- a/src/Basic/SourceConverter.cpp +++ b/src/Server/SourceConverter.cpp @@ -1,6 +1,5 @@ -#include "Basic/Location.h" -#include "Basic/SourceCode.h" -#include "Basic/SourceConverter.h" +#include "Server/Protocol.h" +#include "Server/SourceConverter.h" #include "Support/FileSystem.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/StringExtras.h" diff --git a/unittests/AST/Selection.cpp b/unittests/AST/Selection.cpp index 7ab2aae0..da947005 100644 --- a/unittests/AST/Selection.cpp +++ b/unittests/AST/Selection.cpp @@ -1,5 +1,5 @@ #include "src/AST/Selection.cpp" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" #include "Test/CTest.h" diff --git a/unittests/Basic/SourceCode.cpp b/unittests/AST/SourceCode.cpp similarity index 97% rename from unittests/Basic/SourceCode.cpp rename to unittests/AST/SourceCode.cpp index 3ab015ff..787591d7 100644 --- a/unittests/Basic/SourceCode.cpp +++ b/unittests/AST/SourceCode.cpp @@ -1,5 +1,5 @@ #include "Test/Test.h" -#include "Basic/SourceCode.h" +#include "AST/SourceCode.h" namespace clice::testing { diff --git a/unittests/Compiler/Directive.cpp b/unittests/Compiler/Directive.cpp index 1ef3ef47..d8f5d0ac 100644 --- a/unittests/Compiler/Directive.cpp +++ b/unittests/Compiler/Directive.cpp @@ -1,5 +1,5 @@ #include "Test/CTest.h" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" namespace clice::testing { diff --git a/unittests/Compiler/Preamble.cpp b/unittests/Compiler/Preamble.cpp index 0814721e..d9cf7a1a 100644 --- a/unittests/Compiler/Preamble.cpp +++ b/unittests/Compiler/Preamble.cpp @@ -1,5 +1,5 @@ #include "Test/Test.h" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" #include "Compiler/Preamble.h" #include "Compiler/Compilation.h" diff --git a/unittests/Feature/DocumentSymbol.cpp b/unittests/Feature/DocumentSymbol.cpp index 7322ef94..e8171762 100644 --- a/unittests/Feature/DocumentSymbol.cpp +++ b/unittests/Feature/DocumentSymbol.cpp @@ -1,5 +1,5 @@ #include "Test/CTest.h" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" #include "Feature/DocumentSymbol.h" namespace clice::testing { diff --git a/unittests/Feature/InlayHint.cpp b/unittests/Feature/InlayHint.cpp index fe7b4b76..1a09fbd9 100644 --- a/unittests/Feature/InlayHint.cpp +++ b/unittests/Feature/InlayHint.cpp @@ -1,6 +1,6 @@ #include "Test/CTest.h" #include "Feature/InlayHint.h" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" namespace clice::testing { diff --git a/unittests/Index/USR.cpp b/unittests/Index/USR.cpp index 7d0d69d8..5d2f901d 100644 --- a/unittests/Index/USR.cpp +++ b/unittests/Index/USR.cpp @@ -1,4 +1,4 @@ -#include "Basic/Location.h" +#include "Server/Protocol.h" #include "Support/Logger.h" #include "Test/CTest.h" #include "Index/USR.h" diff --git a/unittests/Basic/SourceConverter.cpp b/unittests/Server/SourceConverter.cpp similarity index 98% rename from unittests/Basic/SourceConverter.cpp rename to unittests/Server/SourceConverter.cpp index cf621f55..f7769d59 100644 --- a/unittests/Basic/SourceConverter.cpp +++ b/unittests/Server/SourceConverter.cpp @@ -1,5 +1,5 @@ #include "Test/CTest.h" -#include "Basic/SourceConverter.h" +#include "Server/SourceConverter.h" namespace clice::testing {