mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-04 06:15:20 +00:00 
			
		
		
		
	Add initialization option capabilities.* and index.maxInitializerLines
				
					
				
			indexer.cc: use index.maxInitializerLines instead of kInitializerMaxLines messages/initialize.cc: some ServerCapabilities are toggable: documentOnTypeFormattingProvider.firstTriggerCharacter foldingRangeProvider workspace.workspaceFolders.supported
This commit is contained in:
		
							parent
							
								
									8f9973f03c
								
							
						
					
					
						commit
						a833b0cb22
					
				@ -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"]
 | 
			
		||||
    //
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -29,8 +29,6 @@ using namespace clang;
 | 
			
		||||
namespace ccls {
 | 
			
		||||
namespace {
 | 
			
		||||
 | 
			
		||||
constexpr int kInitializerMaxLines = 3;
 | 
			
		||||
 | 
			
		||||
GroupMatch *multiVersionMatcher;
 | 
			
		||||
 | 
			
		||||
struct File {
 | 
			
		||||
@ -586,7 +584,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();
 | 
			
		||||
@ -1085,7 +1083,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());
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
@ -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,
 | 
			
		||||
@ -318,7 +306,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);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user