Skip to content

Commit

Permalink
Add initialization option capabilities.* and index.maxInitializerLines
Browse files Browse the repository at this point in the history
indexer.cc: use index.maxInitializerLines instead of kInitializerMaxLines

messages/initialize.cc: some ServerCapabilities are toggable:

documentOnTypeFormattingProvider.firstTriggerCharacter
foldingRangeProvider
workspace.workspaceFolders.supported
  • Loading branch information
MaskRay committed Feb 10, 2019
1 parent aaa97fe commit 3bf921b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
42 changes: 36 additions & 6 deletions src/config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ struct Config {
// member has changed.
SerializeFormat cacheFormat = SerializeFormat::Binary;

struct ServerCap {
struct DocumentOnTypeFormattingOptions {
std::string firstTriggerCharacter = "}";
std::vector<const char *> 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"]
//
Expand Down Expand Up @@ -207,6 +226,10 @@ struct Config {
std::vector<std::string> initialBlacklist;
std::vector<std::string> 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;

Expand Down Expand Up @@ -255,6 +278,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,
Expand All @@ -269,17 +299,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;

Expand Down
6 changes: 2 additions & 4 deletions src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ using namespace clang;
namespace ccls {
namespace {

constexpr int kInitializerMaxLines = 3;

GroupMatch *multiVersionMatcher;

struct File {
Expand Down Expand Up @@ -586,7 +584,7 @@ class IndexDataConsumer : public index::IndexDataConsumer {
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();
Expand Down Expand Up @@ -1085,7 +1083,7 @@ class IndexPPCallbacks : public PPCallbacks {
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());
}
Expand Down
28 changes: 12 additions & 16 deletions src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ struct ServerCap {
} codeLensProvider;
bool documentFormattingProvider = true;
bool documentRangeFormattingProvider = true;
struct DocumentOnTypeFormattingOptions {
std::string firstTriggerCharacter = "}";
std::vector<const char *> moreTriggerCharacter;
} documentOnTypeFormattingProvider;
Config::ServerCap::DocumentOnTypeFormattingOptions
documentOnTypeFormattingProvider;
bool renameProvider = true;
struct DocumentLinkOptions {
bool resolveProvider = true;
Expand All @@ -89,28 +87,18 @@ struct ServerCap {
struct ExecuteCommandOptions {
std::vector<const char *> 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, declarationProvider, definitionProvider,
implementationProvider, typeDefinitionProvider,
Expand Down Expand Up @@ -318,7 +306,15 @@ void Initialize(MessageHandler *m, InitializeParam &param, 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);
Expand Down

0 comments on commit 3bf921b

Please sign in to comment.