misc cleanup

This commit is contained in:
Jacob Dufault 2017-03-30 21:13:58 -07:00
parent 2a3ee89349
commit 82596abc51
6 changed files with 48 additions and 62 deletions

View File

@ -4,15 +4,15 @@
# Includes # Includes
# Windows # Windows
#-IC:/Users/jacob/Desktop/superindex/indexer/third_party -IC:/Users/jacob/Desktop/superindex/indexer/third_party
#-IC:/Users/jacob/Desktop/superindex/indexer/third_party/doctest -IC:/Users/jacob/Desktop/superindex/indexer/third_party/doctest
#-IC:/Users/jacob/Desktop/superindex/indexer/third_party/rapidjson/include -IC:/Users/jacob/Desktop/superindex/indexer/third_party/rapidjson/include
#-IC:/Program Files/LLVM/include -IC:/Program Files/LLVM/include
# OSX # OSX
-I/Users/jdufault/Personal/super-clang-index/third_party #-I/Users/jdufault/Personal/super-clang-index/third_party
-I/Users/jdufault/Personal/super-clang-index/third_party/doctest #-I/Users/jdufault/Personal/super-clang-index/third_party/doctest
-I/Users/jdufault/Personal/super-clang-index/third_party/rapidjson/include #-I/Users/jdufault/Personal/super-clang-index/third_party/rapidjson/include
-I/Users/jdufault/Personal/super-clang-index/build/clang+llvm-4.0.0-x86_64-apple-darwin/include #-I/Users/jdufault/Personal/super-clang-index/build/clang+llvm-4.0.0-x86_64-apple-darwin/include
# Use libcxx # Use libcxx
#-stdlib=libc++ #-stdlib=libc++

View File

@ -94,6 +94,21 @@ lsCompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) {
} }
} }
std::string BuildLabelString(CXCompletionString completion_string) {
std::string label;
int num_chunks = clang_getNumCompletionChunks(completion_string);
for (unsigned i = 0; i < num_chunks; ++i) {
CXCompletionChunkKind kind = clang_getCompletionChunkKind(completion_string, i);
if (kind == CXCompletionChunk_TypedText) {
label += clang::ToString(clang_getCompletionChunkText(completion_string, i));
break;
}
}
return label;
}
std::string BuildDetailString(CXCompletionString completion_string) { std::string BuildDetailString(CXCompletionString completion_string) {
std::string detail; std::string detail;
@ -249,13 +264,12 @@ NonElidedVector<lsCompletionItem> CompletionManager::CodeComplete(const lsTextDo
std::cerr << "Code completion failed" << std::endl; std::cerr << "Code completion failed" << std::endl;
return ls_result; return ls_result;
} }
std::cerr << "clang_codeCompleteAt took " << timer.ElapsedMilliseconds() << "ms; got " << cx_results->NumResults << " results" << std::endl; timer.ResetAndPrint("clangCodeCompleteAt");
std::cerr << "Got " << cx_results->NumResults << " results" << std::endl;
// TODO: for comments we could hack the unsaved buffer and transform // into /// // TODO: for comments we could hack the unsaved buffer and transform // into ///
timer.Reset();
ls_result.reserve(cx_results->NumResults); ls_result.reserve(cx_results->NumResults);
std::cerr << "Reserving results took " << timer.ElapsedMilliseconds() << "ms" << std::endl;
timer.Reset(); timer.Reset();
for (int i = 0; i < cx_results->NumResults; ++i) { for (int i = 0; i < cx_results->NumResults; ++i) {
@ -281,26 +295,14 @@ NonElidedVector<lsCompletionItem> CompletionManager::CodeComplete(const lsTextDo
// TODO: fill in more data // TODO: fill in more data
lsCompletionItem ls_completion_item; lsCompletionItem ls_completion_item;
// kind/label/detail/docs
ls_completion_item.kind = GetCompletionKind(result.CursorKind); ls_completion_item.kind = GetCompletionKind(result.CursorKind);
ls_completion_item.label = BuildLabelString(result.CompletionString);
// Get the primary text to insert.
int num_chunks = clang_getNumCompletionChunks(result.CompletionString);
for (unsigned i = 0; i < num_chunks; ++i) {
CXCompletionChunkKind kind = clang_getCompletionChunkKind(result.CompletionString, i);
if (kind == CXCompletionChunk_TypedText) {
ls_completion_item.label += clang::ToString(clang_getCompletionChunkText(result.CompletionString, i));
break;
}
}
ls_completion_item.detail = BuildDetailString(result.CompletionString); ls_completion_item.detail = BuildDetailString(result.CompletionString);
// Get docs.
ls_completion_item.documentation = clang::ToString(clang_getCompletionBriefComment(result.CompletionString)); ls_completion_item.documentation = clang::ToString(clang_getCompletionBriefComment(result.CompletionString));
// Set priority, and make some adjustments. // Priority
int priority = clang_getCompletionPriority(result.CompletionString); int priority = clang_getCompletionPriority(result.CompletionString);
if (result.CursorKind == CXCursor_Destructor) { if (result.CursorKind == CXCursor_Destructor) {
priority *= 100; priority *= 100;
//std::cerr << "Bumping[destructor] " << ls_completion_item.label << std::endl; //std::cerr << "Bumping[destructor] " << ls_completion_item.label << std::endl;
@ -321,29 +323,12 @@ NonElidedVector<lsCompletionItem> CompletionManager::CodeComplete(const lsTextDo
ls_result.push_back(ls_completion_item); ls_result.push_back(ls_completion_item);
} }
std::cerr << "Building completion results took " << timer.ElapsedMilliseconds() << "ms" << std::endl; timer.ResetAndPrint("Building completion results");
timer.Reset();
clang_disposeCodeCompleteResults(cx_results); clang_disposeCodeCompleteResults(cx_results);
std::cerr << "clang_disposeCodeCompleteResults took " << timer.ElapsedMilliseconds() << "ms" << std::endl; timer.ResetAndPrint("clang_disposeCodeCompleteResults ");
// Score completions by priority.
/*
timer.Reset();
std::sort(
ls_result.begin(), ls_result.end(),
[](const lsCompletionItem& a, const lsCompletionItem& b) {
return a.priority_ < b.priority_;
});
std::cerr << "Sorting completion results took " << timer.ElapsedMilliseconds() << "ms" << std::endl;
*/
//std::cerr << std::endl;
//for (auto& result : ls_result) {
// std::cerr << "SORTED priority=" << result.priority_ << ", sortText=" << result.sortText << ", label=" << result.label << std::endl;
//}
return ls_result; return ls_result;
//clang_codeCompleteAt()
// we should probably main two translation units, one for // we should probably main two translation units, one for
// serving current requests, and one that is reparsing (follow qtcreator) // serving current requests, and one that is reparsing (follow qtcreator)

View File

@ -168,19 +168,14 @@ void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) {
Timer time; Timer time;
IndexedFile file = Parse(request->path, request->args); IndexedFile file = Parse(request->path, request->args);
std::cerr << "Parsing/indexing took " << time.ElapsedMilliseconds() time.ResetAndPrint("Parsing/indexing");
<< "ms" << std::endl;
time.Reset();
IndexUpdate update(file); IndexUpdate update(file);
IndexTranslationUnitResponse response(update); IndexTranslationUnitResponse response(update);
std::cerr << "Creating index update took " << time.ElapsedMilliseconds() time.ResetAndPrint("Creating index update/response");
<< "ms" << std::endl;
time.Reset();
responses->Enqueue(response); responses->Enqueue(response);
std::cerr << "Sending to server took " << time.ElapsedMilliseconds() time.ResetAndPrint("Sending update to server");
<< "ms" << std::endl;
} }
} }
@ -212,10 +207,8 @@ void AddCodeLens(std::vector<TCodeLens>* result,
const char* singular, const char* singular,
const char* plural) { const char* plural) {
TCodeLens code_lens; TCodeLens code_lens;
code_lens.range.start.line = code_lens.range.start.line = loc.line - 1;
loc.line - 1; // TODO: cleanup indexer to negate by 1. code_lens.range.start.character = loc.column - 1;
code_lens.range.start.character =
loc.column - 1; // TODO: cleanup indexer to negate by 1.
// TODO: store range information. // TODO: store range information.
code_lens.range.end.line = code_lens.range.start.line; code_lens.range.end.line = code_lens.range.start.line;
code_lens.range.end.character = code_lens.range.start.character; code_lens.range.end.character = code_lens.range.start.character;
@ -379,7 +372,7 @@ void QueryDbMainLoop(
Timer timer; Timer timer;
response.Write(std::cout); response.Write(std::cout);
std::cerr << "Writing completion results to stdout took " << timer.ElapsedMilliseconds() << "ms" << std::endl; timer.ResetAndPrint("Writing completion results");
//SendOutMessageToClient(language_client, response); //SendOutMessageToClient(language_client, response);
break; break;
} }
@ -620,8 +613,7 @@ void QueryDbMainLoop(
Timer time; Timer time;
db->ApplyIndexUpdate(&response->update); db->ApplyIndexUpdate(&response->update);
std::cerr << "Applying index update took " << time.ElapsedMilliseconds() time.ResetAndPrint("Applying index update");
<< "ms" << std::endl;
} }
} }

View File

@ -143,7 +143,6 @@ std::vector<CompilationEntry> LoadCompilationEntriesFromDirectory(const std::str
CXCompileCommand cx_command = clang_CompileCommands_getCommand(cx_commands, i); CXCompileCommand cx_command = clang_CompileCommands_getCommand(cx_commands, i);
CompilationEntry entry; CompilationEntry entry;
// TODO: remove ComplationEntry::directory
std::string directory = clang::ToString(clang_CompileCommand_getDirectory(cx_command)); std::string directory = clang::ToString(clang_CompileCommand_getDirectory(cx_command));
std::string relative_filename = clang::ToString(clang_CompileCommand_getFilename(cx_command)); std::string relative_filename = clang::ToString(clang_CompileCommand_getFilename(cx_command));
std::string absolute_filename = directory + "/" + relative_filename; std::string absolute_filename = directory + "/" + relative_filename;

View File

@ -1,5 +1,7 @@
#include "timer.h" #include "timer.h"
#include <iostream>
Timer::Timer() { Timer::Timer() {
Reset(); Reset();
} }
@ -8,6 +10,11 @@ void Timer::Reset() {
start = Clock::now(); start = Clock::now();
} }
void Timer::ResetAndPrint(const std::string& message) {
std::cerr << message << " took " << ElapsedMilliseconds() << "ms" << std::endl;
Reset();
}
long long Timer::ElapsedMilliseconds() { long long Timer::ElapsedMilliseconds() {
std::chrono::time_point<Clock> end = Clock::now(); std::chrono::time_point<Clock> end = Clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <chrono> #include <chrono>
#include <string>
struct Timer { struct Timer {
using Clock = std::chrono::high_resolution_clock; using Clock = std::chrono::high_resolution_clock;
@ -10,6 +11,8 @@ struct Timer {
// Restart/reset the timer. // Restart/reset the timer.
void Reset(); void Reset();
// Resets timer and prints a message like "<foo> took 5ms"
void ResetAndPrint(const std::string& message);
// Return the number of milliseconds since the timer was last reset. // Return the number of milliseconds since the timer was last reset.
long long ElapsedMilliseconds(); long long ElapsedMilliseconds();