diff --git a/src/config.hh b/src/config.hh index 4c7eabbb..ca914dc6 100644 --- a/src/config.hh +++ b/src/config.hh @@ -54,6 +54,25 @@ struct Config { // member has changed. SerializeFormat cacheFormat = SerializeFormat::Binary; + struct ServerCap { + struct DocumentOnTypeFormattingOptions { + std::string firstTriggerCharacter = "}"; + std::vector moreTriggerCharacter; + } documentOnTypeFormattingProvider; + + // Set to false if you don't want folding ranges. + bool foldingRangeProvider = true; + + struct Workspace { + struct WorkspaceFolders { + // Set to false if you don't want workspace folders. + bool supported = true; + + bool changeNotifications = true; + } workspaceFolders; + } workspace; + } capabilities; + struct Clang { // Arguments that should be excluded, e.g. ["-fopenmp", "-Wall"] // @@ -219,6 +238,10 @@ struct Config { std::vector initialBlacklist; std::vector initialWhitelist; + // If a variable initializer/macro replacement-list has fewer than this many + // lines, include the initializer in detailed_name. + int maxInitializerLines = 5; + // If not 0, a file will be indexed in each tranlation unit that includes it. int multiVersion = 0; @@ -267,6 +290,13 @@ struct Config { int maxNum = 2000; } xref; }; +REFLECT_STRUCT(Config::ServerCap::DocumentOnTypeFormattingOptions, + firstTriggerCharacter, moreTriggerCharacter); +REFLECT_STRUCT(Config::ServerCap::Workspace::WorkspaceFolders, supported, + changeNotifications); +REFLECT_STRUCT(Config::ServerCap::Workspace, workspaceFolders); +REFLECT_STRUCT(Config::ServerCap, documentOnTypeFormattingProvider, + foldingRangeProvider, workspace); REFLECT_STRUCT(Config::Clang, excludeArgs, extraArgs, pathMappings, resourceDir); REFLECT_STRUCT(Config::ClientCapability, hierarchicalDocumentSymbolSupport, @@ -281,17 +311,17 @@ REFLECT_STRUCT(Config::Diagnostics, blacklist, onChange, onOpen, onSave, spellChecking, whitelist) REFLECT_STRUCT(Config::Highlight, largeFileSize, lsRanges, blacklist, whitelist) REFLECT_STRUCT(Config::Index, blacklist, comments, initialBlacklist, - initialWhitelist, multiVersion, multiVersionBlacklist, - multiVersionWhitelist, onChange, threads, trackDependency, - whitelist); + initialWhitelist, maxInitializerLines, multiVersion, + multiVersionBlacklist, multiVersionWhitelist, onChange, threads, + trackDependency, whitelist); REFLECT_STRUCT(Config::Request, timeout); REFLECT_STRUCT(Config::Session, maxNum); REFLECT_STRUCT(Config::WorkspaceSymbol, caseSensitivity, maxNum, sort); REFLECT_STRUCT(Config::Xref, maxNum); REFLECT_STRUCT(Config, compilationDatabaseCommand, compilationDatabaseDirectory, - cacheDirectory, cacheFormat, clang, client, codeLens, completion, - diagnostics, highlight, index, request, session, workspaceSymbol, - xref); + cacheDirectory, cacheFormat, capabilities, clang, client, + codeLens, completion, diagnostics, highlight, index, request, + session, workspaceSymbol, xref); extern Config *g_config; diff --git a/src/indexer.cc b/src/indexer.cc index bae9e568..03bcc9b1 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -41,8 +41,6 @@ using namespace clang; namespace ccls { namespace { -constexpr int kInitializerMaxLines = 3; - GroupMatch *multiVersionMatcher; struct File { @@ -600,7 +598,7 @@ public: if (L.isMacroID() || !SM.isBeforeInTranslationUnit(L, R.getBegin())) return; StringRef Buf = GetSourceInRange(SM, Lang, R); - Twine Init = Buf.count('\n') <= kInitializerMaxLines - 1 + Twine Init = Buf.count('\n') <= g_config->index.maxInitializerLines - 1 ? Buf.size() && Buf[0] == ':' ? Twine(" ", Buf) : Twine(" = ", Buf) : Twine(); @@ -1098,7 +1096,7 @@ public: var.def.short_name_size = Name.size(); StringRef Buf = GetSourceInRange(SM, Lang, R); var.def.hover = - Intern(Buf.count('\n') <= kInitializerMaxLines - 1 + Intern(Buf.count('\n') <= g_config->index.maxInitializerLines - 1 ? Twine("#define ", GetSourceInRange(SM, Lang, R)).str() : Twine("#define ", Name).str()); } diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 9f2948d6..6259e8d0 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -87,10 +87,8 @@ struct ServerCap { } codeLensProvider; bool documentFormattingProvider = true; bool documentRangeFormattingProvider = true; - struct DocumentOnTypeFormattingOptions { - std::string firstTriggerCharacter = "}"; - std::vector moreTriggerCharacter; - } documentOnTypeFormattingProvider; + Config::ServerCap::DocumentOnTypeFormattingOptions + documentOnTypeFormattingProvider; bool renameProvider = true; struct DocumentLinkOptions { bool resolveProvider = true; @@ -100,28 +98,18 @@ struct ServerCap { struct ExecuteCommandOptions { std::vector commands = {ccls_xref}; } executeCommandProvider; - struct Workspace { - struct WorkspaceFolders { - bool supported = true; - bool changeNotifications = true; - } workspaceFolders; - } workspace; + Config::ServerCap::Workspace workspace; }; REFLECT_STRUCT(ServerCap::CodeActionOptions, codeActionKinds); REFLECT_STRUCT(ServerCap::CodeLensOptions, resolveProvider); REFLECT_STRUCT(ServerCap::CompletionOptions, resolveProvider, triggerCharacters); REFLECT_STRUCT(ServerCap::DocumentLinkOptions, resolveProvider); -REFLECT_STRUCT(ServerCap::DocumentOnTypeFormattingOptions, - firstTriggerCharacter, moreTriggerCharacter); REFLECT_STRUCT(ServerCap::ExecuteCommandOptions, commands); REFLECT_STRUCT(ServerCap::SaveOptions, includeText); REFLECT_STRUCT(ServerCap::SignatureHelpOptions, triggerCharacters); REFLECT_STRUCT(ServerCap::TextDocumentSyncOptions, openClose, change, willSave, willSaveWaitUntil, save); -REFLECT_STRUCT(ServerCap::Workspace::WorkspaceFolders, supported, - changeNotifications); -REFLECT_STRUCT(ServerCap::Workspace, workspaceFolders); REFLECT_STRUCT(ServerCap, textDocumentSync, hoverProvider, completionProvider, signatureHelpProvider, definitionProvider, implementationProvider, typeDefinitionProvider, @@ -329,7 +317,15 @@ void Initialize(MessageHandler *m, InitializeParam ¶m, ReplyOnce &reply) { // Send initialization before starting indexers, so we don't send a // status update too early. - reply(InitializeResult{}); + { + InitializeResult result; + auto &c = result.capabilities; + c.documentOnTypeFormattingProvider = + g_config->capabilities.documentOnTypeFormattingProvider; + c.foldingRangeProvider = g_config->capabilities.foldingRangeProvider; + c.workspace = g_config->capabilities.workspace; + reply(result); + } // Set project root. EnsureEndsInSlash(project_path);