Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdufault committed Feb 22, 2018
1 parent 566b508 commit 01fe19f
Show file tree
Hide file tree
Showing 43 changed files with 479 additions and 457 deletions.
7 changes: 4 additions & 3 deletions src/cache_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ struct RealCacheManager : ICacheManager {
if (!file_content || !serialized_indexed_content)
return nullptr;

return Deserialize(config_->cacheFormat, path, *serialized_indexed_content,*file_content,
IndexFile::kMajorVersion);
return Deserialize(config_->cacheFormat, path, *serialized_indexed_content,
*file_content, IndexFile::kMajorVersion);
}

std::string GetCachePath(const std::string& source_file) {
Expand Down Expand Up @@ -91,7 +91,8 @@ struct FakeCacheManager : ICacheManager {
std::unique_ptr<IndexFile> RawCacheLoad(const std::string& path) override {
for (const FakeCacheEntry& entry : entries_) {
if (entry.path == path) {
return Deserialize(SerializeFormat::Json, path, entry.json, "<empty>", nullopt);
return Deserialize(SerializeFormat::Json, path, entry.json, "<empty>",
nullopt);
}
}

Expand Down
118 changes: 73 additions & 45 deletions src/clang_complete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,59 +161,87 @@ void BuildCompletionItemTexts(std::vector<lsCompletionItem>& out,
int num_chunks = clang_getNumCompletionChunks(completion_string);
for (int i = 0; i < num_chunks; ++i) {
CXCompletionChunkKind kind =
clang_getCompletionChunkKind(completion_string, i);
clang_getCompletionChunkKind(completion_string, i);

std::string text;
switch (kind) {
case CXCompletionChunk_LeftParen: text = '('; break;
case CXCompletionChunk_RightParen: text = ')'; break;
case CXCompletionChunk_LeftBracket: text = '['; break;
case CXCompletionChunk_RightBracket: text = ']'; break;
case CXCompletionChunk_LeftBrace: text = '{'; break;
case CXCompletionChunk_RightBrace: text = '}'; break;
case CXCompletionChunk_LeftAngle: text = '<'; break;
case CXCompletionChunk_RightAngle: text = '>'; break;
case CXCompletionChunk_Comma: text = ", "; break;
case CXCompletionChunk_Colon: text = ':'; break;
case CXCompletionChunk_SemiColon: text = ';'; break;
case CXCompletionChunk_Equal: text = '='; break;
case CXCompletionChunk_HorizontalSpace: text = ' '; break;
case CXCompletionChunk_VerticalSpace: text = ' '; break;

case CXCompletionChunk_ResultType:
result_type =
ToString(clang_getCompletionChunkText(completion_string, i));
continue;
case CXCompletionChunk_LeftParen:
text = '(';
break;
case CXCompletionChunk_RightParen:
text = ')';
break;
case CXCompletionChunk_LeftBracket:
text = '[';
break;
case CXCompletionChunk_RightBracket:
text = ']';
break;
case CXCompletionChunk_LeftBrace:
text = '{';
break;
case CXCompletionChunk_RightBrace:
text = '}';
break;
case CXCompletionChunk_LeftAngle:
text = '<';
break;
case CXCompletionChunk_RightAngle:
text = '>';
break;
case CXCompletionChunk_Comma:
text = ", ";
break;
case CXCompletionChunk_Colon:
text = ':';
break;
case CXCompletionChunk_SemiColon:
text = ';';
break;
case CXCompletionChunk_Equal:
text = '=';
break;
case CXCompletionChunk_HorizontalSpace:
text = ' ';
break;
case CXCompletionChunk_VerticalSpace:
text = ' ';
break;

case CXCompletionChunk_TypedText:
case CXCompletionChunk_Placeholder:
case CXCompletionChunk_Text:
case CXCompletionChunk_Informative:
text = ToString(clang_getCompletionChunkText(completion_string, i));
case CXCompletionChunk_ResultType:
result_type =
ToString(clang_getCompletionChunkText(completion_string, i));
continue;

for (auto i = out_first; i < out.size(); ++i) {
// first typed text is used for filtering
if (kind == CXCompletionChunk_TypedText && !out[i].filterText)
out[i].filterText = text;
case CXCompletionChunk_TypedText:
case CXCompletionChunk_Placeholder:
case CXCompletionChunk_Text:
case CXCompletionChunk_Informative:
text = ToString(clang_getCompletionChunkText(completion_string, i));

if (kind == CXCompletionChunk_Placeholder)
out[i].parameters_.push_back(text);
}
break;
for (auto i = out_first; i < out.size(); ++i) {
// first typed text is used for filtering
if (kind == CXCompletionChunk_TypedText && !out[i].filterText)
out[i].filterText = text;

case CXCompletionChunk_CurrentParameter:
// We have our own parsing logic for active parameter. This doesn't seem
// to be very reliable.
continue;
if (kind == CXCompletionChunk_Placeholder)
out[i].parameters_.push_back(text);
}
break;

case CXCompletionChunk_Optional: {
CXCompletionString nested =
clang_getCompletionChunkCompletionString(completion_string, i);
// duplicate last element, the recursive call will complete it
out.push_back(out.back());
BuildCompletionItemTexts(out, nested, include_snippets);
continue;
}
case CXCompletionChunk_CurrentParameter:
// We have our own parsing logic for active parameter. This doesn't seem
// to be very reliable.
continue;

case CXCompletionChunk_Optional: {
CXCompletionString nested =
clang_getCompletionChunkCompletionString(completion_string, i);
// duplicate last element, the recursive call will complete it
out.push_back(out.back());
BuildCompletionItemTexts(out, nested, include_snippets);
continue;
}
}

for (auto i = out_first; i < out.size(); ++i)
Expand Down
2 changes: 1 addition & 1 deletion src/clang_cursor.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "position.h"
#include "nt_string.h"
#include "position.h"

#include <clang-c/Index.h>
#include <optional.h>
Expand Down
12 changes: 8 additions & 4 deletions src/clang_translation_unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,27 @@ std::unique_ptr<ClangTranslationUnit> ClangTranslationUnit::Create(
auto make_msg = [&]() {
return "Please try running the following, identify which flag causes the "
"issue, and report a bug. cquery will then filter the flag for you "
" automatically:\n$ " + StringJoin(args, " ") + " -fsyntax-only";
" automatically:\n$ " +
StringJoin(args, " ") + " -fsyntax-only";
};

switch (error_code) {
case CXError_Success:
return MakeUnique<ClangTranslationUnit>(cx_tu);
case CXError_Failure:
LOG_S(ERROR) << "libclang generic failure for " << filepath << ". " << make_msg();
LOG_S(ERROR) << "libclang generic failure for " << filepath << ". "
<< make_msg();
return nullptr;
case CXError_Crashed:
LOG_S(ERROR) << "libclang crashed for " << filepath << ". " << make_msg();
return nullptr;
case CXError_InvalidArguments:
LOG_S(ERROR) << "libclang had invalid arguments for " << filepath << ". " << make_msg();
LOG_S(ERROR) << "libclang had invalid arguments for " << filepath << ". "
<< make_msg();
return nullptr;
case CXError_ASTReadError:
LOG_S(ERROR) << "libclang had ast read error for " << filepath << ". " << make_msg();
LOG_S(ERROR) << "libclang had ast read error for " << filepath << ". "
<< make_msg();
return nullptr;
}

Expand Down
8 changes: 4 additions & 4 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ struct Config {
int includeMaxPathSize = 30;

// Whitelist that file paths will be tested against. If a file path does not
// end in one of these values, it will not be considered for auto-completion.
// An example value is { ".h", ".hpp" }
// end in one of these values, it will not be considered for
// auto-completion. An example value is { ".h", ".hpp" }
//
// This is significantly faster than using a regex.
std::vector<std::string> includeSuffixWhitelist = {".h", ".hpp", ".hh"};
Expand All @@ -154,8 +154,8 @@ struct Config {
bool attributeMakeCallsToCtor = true;

// If a translation unit's absolute path matches any EMCAScript regex in the
// whitelist, or does not match any regex in the blacklist, it will be indexed.
// To only index files in the whitelist, add ".*" to the blacklist.
// whitelist, or does not match any regex in the blacklist, it will be
// indexed. To only index files in the whitelist, add ".*" to the blacklist.
// `std::regex_search(path, regex, std::regex_constants::match_any)`
//
// Example: `ash/.*\.cc`
Expand Down
5 changes: 3 additions & 2 deletions src/file_consumer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ IndexFile* FileConsumer::TryConsumeFile(CXFile file,

// No result in local; we need to query global.
bool did_insert = shared_->Mark(file_name);

// We did not take the file from global. Cache that we failed so we don't try
// again and return nullptr.
if (!did_insert) {
Expand All @@ -75,7 +75,8 @@ IndexFile* FileConsumer::TryConsumeFile(CXFile file,
}

// Read the file contents, if we fail then we cannot index the file.
optional<std::string> contents = GetFileContents(file_name, file_contents_map);
optional<std::string> contents =
GetFileContents(file_name, file_contents_map);
if (!contents) {
*is_first_ownership = false;
return nullptr;
Expand Down
46 changes: 24 additions & 22 deletions src/import_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ ShouldParse FileNeedsParse(
return ShouldParse::NoSuchFile;

optional<int64_t> last_cached_modification =
timestamp_manager->GetLastCachedModificationTime(cache_manager.get(), path);
timestamp_manager->GetLastCachedModificationTime(cache_manager.get(),
path);

// File has been changed.
if (!last_cached_modification ||
Expand Down Expand Up @@ -236,8 +237,9 @@ CacheLoadResult TryLoadFromCache(
PerformanceImportFile perf;

std::vector<Index_DoIdMap> result;
result.push_back(Index_DoIdMap(cache_manager->TakeOrLoad(path_to_index), cache_manager, perf,
is_interactive, false /*write_to_disk*/));
result.push_back(Index_DoIdMap(cache_manager->TakeOrLoad(path_to_index),
cache_manager, perf, is_interactive,
false /*write_to_disk*/));
for (const std::string& dependency : previous_index->dependencies) {
// Only load a dependency if it is not already loaded.
//
Expand All @@ -257,8 +259,9 @@ CacheLoadResult TryLoadFromCache(
if (!dependency_index)
continue;

result.push_back(Index_DoIdMap(std::move(dependency_index), cache_manager, perf,
is_interactive, false /*write_to_disk*/));
result.push_back(Index_DoIdMap(std::move(dependency_index), cache_manager,
perf, is_interactive,
false /*write_to_disk*/));
}

QueueManager::instance()->do_id_map.EnqueueAll(std::move(result));
Expand Down Expand Up @@ -344,7 +347,7 @@ void ParseFile(Config* config,

LOG_S(INFO) << "Parsing " << path_to_index;
std::vector<FileContents> file_contents = PreloadFileContents(
request.cache_manager, entry, request.contents, path_to_index);
request.cache_manager, entry, request.contents, path_to_index);

std::vector<Index_DoIdMap> result;
PerformanceImportFile perf;
Expand Down Expand Up @@ -375,8 +378,8 @@ void ParseFile(Config* config,
// When main thread does IdMap request it will request the previous index if
// needed.
LOG_S(INFO) << "Emitting index result for " << new_index->path;
result.push_back(Index_DoIdMap(std::move(new_index), request.cache_manager, perf,
request.is_interactive,
result.push_back(Index_DoIdMap(std::move(new_index), request.cache_manager,
perf, request.is_interactive,
true /*write_to_disk*/));
}

Expand All @@ -401,8 +404,8 @@ bool IndexMain_DoParse(
entry.filename = request->path;
entry.args = request->args;
ParseFile(config, working_files, file_consumer_shared, timestamp_manager,
modification_timestamp_fetcher, import_manager,
indexer, request.value(), entry);
modification_timestamp_fetcher, import_manager, indexer,
request.value(), entry);
return true;
}

Expand Down Expand Up @@ -477,7 +480,8 @@ bool IndexMain_LoadPreviousIndex() {
if (!response)
return false;

response->previous = response->cache_manager->TryTakeOrLoad(response->current->path);
response->previous =
response->cache_manager->TryTakeOrLoad(response->current->path);
LOG_IF_S(ERROR, !response->previous)
<< "Unable to load previous index for already imported index "
<< response->current->path;
Expand Down Expand Up @@ -584,14 +588,13 @@ void Indexer_Main(Config* config,
// IndexMain_DoCreateIndexUpdate so we don't starve querydb from doing any
// work. Running both also lets the user query the partially constructed
// index.
did_work = IndexMain_DoParse(
config, working_files, file_consumer_shared,
timestamp_manager, &modification_timestamp_fetcher,
import_manager, indexer.get()) ||
did_work;
did_work =
IndexMain_DoParse(config, working_files, file_consumer_shared,
timestamp_manager, &modification_timestamp_fetcher,
import_manager, indexer.get()) ||
did_work;

did_work = IndexMain_DoCreateIndexUpdate(timestamp_manager) ||
did_work;
did_work = IndexMain_DoCreateIndexUpdate(timestamp_manager) || did_work;

did_work = IndexMain_LoadPreviousIndex() || did_work;

Expand Down Expand Up @@ -743,10 +746,9 @@ TEST_SUITE("ImportPipeline") {
}

bool PumpOnce() {
return IndexMain_DoParse(&config, &working_files, &file_consumer_shared,
&timestamp_manager,
&modification_timestamp_fetcher, &import_manager,
indexer.get());
return IndexMain_DoParse(
&config, &working_files, &file_consumer_shared, &timestamp_manager,
&modification_timestamp_fetcher, &import_manager, indexer.get());
}

void MakeRequest(const std::string& path,
Expand Down
11 changes: 5 additions & 6 deletions src/include_complete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ lsCompletionItem BuildCompletionItem(Config* config,
bool is_stl) {
lsCompletionItem item;
item.label = ElideLongPath(config, path);
item.detail = path; // the include path, used in de-duplicating
item.detail = path; // the include path, used in de-duplicating
item.textEdit = lsTextEdit();
item.textEdit->newText = path;
item.insertTextFormat = lsInsertTextFormat::PlainText;
Expand Down Expand Up @@ -142,16 +142,16 @@ void IncludeComplete::InsertCompletionItem(const std::string& absolute_path,
completion_items[it->second].detail.length() > item.detail.length())
absolute_path_to_completion_item[absolute_path] = completion_items.size();
} else {
lsCompletionItem& inserted_item = completion_items[inserted_paths[item.detail]];
lsCompletionItem& inserted_item =
completion_items[inserted_paths[item.detail]];
// Update |use_angle_brackets_|, prefer quotes.
if (!item.use_angle_brackets_)
inserted_item.use_angle_brackets_ = false;
}
}

void IncludeComplete::AddFile(const std::string& absolute_path) {
if (!EndsWithAny(absolute_path,
config_->completion.includeSuffixWhitelist))
if (!EndsWithAny(absolute_path, config_->completion.includeSuffixWhitelist))
return;
if (match_ && !match_->IsMatch(absolute_path))
return;
Expand Down Expand Up @@ -183,8 +183,7 @@ void IncludeComplete::InsertIncludesFromDirectory(std::string directory,
GetFilesInFolder(
directory, true /*recursive*/, false /*add_folder_to_path*/,
[&](const std::string& path) {
if (!EndsWithAny(path,
config_->completion.includeSuffixWhitelist))
if (!EndsWithAny(path, config_->completion.includeSuffixWhitelist))
return;
if (match_ && !match_->IsMatch(directory + path))
return;
Expand Down
Loading

0 comments on commit 01fe19f

Please sign in to comment.