mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-03 22:04:24 +00:00 
			
		
		
		
	$ccls/publishSemanticHighlighting: support both line/character-style and position-style ranges
This commit is contained in:
		
							parent
							
								
									d604fc38dc
								
							
						
					
					
						commit
						4612aa062b
					
				@ -144,6 +144,9 @@ struct Config {
 | 
			
		||||
 | 
			
		||||
  // Semantic highlighting
 | 
			
		||||
  struct Highlight {
 | 
			
		||||
    // true: LSP line/character; false: position
 | 
			
		||||
    bool lsRanges = false;
 | 
			
		||||
 | 
			
		||||
    // Like index.{whitelist,blacklist}, don't publish semantic highlighting to
 | 
			
		||||
    // blacklisted files.
 | 
			
		||||
    std::vector<std::string> blacklist;
 | 
			
		||||
@ -230,7 +233,7 @@ MAKE_REFLECT_STRUCT(Config::Diagnostics,
 | 
			
		||||
                    onParse,
 | 
			
		||||
                    onType,
 | 
			
		||||
                    whitelist)
 | 
			
		||||
MAKE_REFLECT_STRUCT(Config::Highlight, blacklist, whitelist)
 | 
			
		||||
MAKE_REFLECT_STRUCT(Config::Highlight, lsRanges, blacklist, whitelist)
 | 
			
		||||
MAKE_REFLECT_STRUCT(Config::Index,
 | 
			
		||||
                    attributeMakeCallsToCtor,
 | 
			
		||||
                    blacklist,
 | 
			
		||||
 | 
			
		||||
@ -336,12 +336,14 @@ void EmitSemanticHighlighting(DB *db,
 | 
			
		||||
  Out_CclsPublishSemanticHighlighting out;
 | 
			
		||||
  out.params.uri = lsDocumentUri::FromPath(wfile->filename);
 | 
			
		||||
  // Transform lsRange into pair<int, int> (offset pairs)
 | 
			
		||||
  {
 | 
			
		||||
  if (!g_config->highlight.lsRanges) {
 | 
			
		||||
    std::vector<std::pair<lsRange, Out_CclsPublishSemanticHighlighting::Symbol *>>
 | 
			
		||||
      scratch;
 | 
			
		||||
    for (auto &entry : grouped_symbols)
 | 
			
		||||
    for (auto &entry : grouped_symbols) {
 | 
			
		||||
      for (auto &range : entry.second.lsRanges)
 | 
			
		||||
        scratch.emplace_back(range, &entry.second);
 | 
			
		||||
      entry.second.lsRanges.clear();
 | 
			
		||||
    }
 | 
			
		||||
    std::sort(scratch.begin(), scratch.end(),
 | 
			
		||||
      [](auto &l, auto &r) { return l.first.start < r.first.start; });
 | 
			
		||||
    const auto &buf = wfile->buffer_content;
 | 
			
		||||
@ -375,7 +377,7 @@ void EmitSemanticHighlighting(DB *db,
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for (auto &entry : grouped_symbols)
 | 
			
		||||
    if (entry.second.ranges.size())
 | 
			
		||||
    if (entry.second.ranges.size() || entry.second.lsRanges.size())
 | 
			
		||||
      out.params.symbols.push_back(std::move(entry.second));
 | 
			
		||||
  pipeline::WriteStdout(kMethodType_CclsPublishSemanticHighlighting, out);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -76,15 +76,9 @@ struct Out_CclsPublishSemanticHighlighting
 | 
			
		||||
  std::string method = "$ccls/publishSemanticHighlighting";
 | 
			
		||||
  Params params;
 | 
			
		||||
};
 | 
			
		||||
MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Symbol,
 | 
			
		||||
                    stableId,
 | 
			
		||||
                    parentKind,
 | 
			
		||||
                    kind,
 | 
			
		||||
                    storage,
 | 
			
		||||
                    ranges);
 | 
			
		||||
MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Params,
 | 
			
		||||
                    uri,
 | 
			
		||||
                    symbols);
 | 
			
		||||
MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Symbol, stableId,
 | 
			
		||||
                    parentKind, kind, storage, ranges, lsRanges);
 | 
			
		||||
MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Params, uri, symbols);
 | 
			
		||||
MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting,
 | 
			
		||||
                    jsonrpc,
 | 
			
		||||
                    method,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user