mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-29 11:01:57 +00:00
misc cleanup
This commit is contained in:
parent
2a3ee89349
commit
82596abc51
@ -4,15 +4,15 @@
|
||||
|
||||
# Includes
|
||||
# Windows
|
||||
#-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/rapidjson/include
|
||||
#-IC:/Program Files/LLVM/include
|
||||
-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/rapidjson/include
|
||||
-IC:/Program Files/LLVM/include
|
||||
# OSX
|
||||
-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/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/third_party
|
||||
#-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/build/clang+llvm-4.0.0-x86_64-apple-darwin/include
|
||||
|
||||
# Use libcxx
|
||||
#-stdlib=libc++
|
||||
|
@ -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 detail;
|
||||
|
||||
@ -249,13 +264,12 @@ NonElidedVector<lsCompletionItem> CompletionManager::CodeComplete(const lsTextDo
|
||||
std::cerr << "Code completion failed" << std::endl;
|
||||
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 ///
|
||||
|
||||
timer.Reset();
|
||||
ls_result.reserve(cx_results->NumResults);
|
||||
std::cerr << "Reserving results took " << timer.ElapsedMilliseconds() << "ms" << std::endl;
|
||||
|
||||
timer.Reset();
|
||||
for (int i = 0; i < cx_results->NumResults; ++i) {
|
||||
@ -281,26 +295,14 @@ NonElidedVector<lsCompletionItem> CompletionManager::CodeComplete(const lsTextDo
|
||||
// TODO: fill in more data
|
||||
lsCompletionItem ls_completion_item;
|
||||
|
||||
// kind/label/detail/docs
|
||||
ls_completion_item.kind = GetCompletionKind(result.CursorKind);
|
||||
|
||||
|
||||
// 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.label = BuildLabelString(result.CompletionString);
|
||||
ls_completion_item.detail = BuildDetailString(result.CompletionString);
|
||||
|
||||
// Get docs.
|
||||
ls_completion_item.documentation = clang::ToString(clang_getCompletionBriefComment(result.CompletionString));
|
||||
|
||||
// Set priority, and make some adjustments.
|
||||
// Priority
|
||||
int priority = clang_getCompletionPriority(result.CompletionString);
|
||||
|
||||
if (result.CursorKind == CXCursor_Destructor) {
|
||||
priority *= 100;
|
||||
//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);
|
||||
}
|
||||
std::cerr << "Building completion results took " << timer.ElapsedMilliseconds() << "ms" << std::endl;
|
||||
timer.ResetAndPrint("Building completion results");
|
||||
|
||||
timer.Reset();
|
||||
clang_disposeCodeCompleteResults(cx_results);
|
||||
std::cerr << "clang_disposeCodeCompleteResults took " << timer.ElapsedMilliseconds() << "ms" << std::endl;
|
||||
|
||||
// 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;
|
||||
//}
|
||||
timer.ResetAndPrint("clang_disposeCodeCompleteResults ");
|
||||
|
||||
return ls_result;
|
||||
//clang_codeCompleteAt()
|
||||
|
||||
// we should probably main two translation units, one for
|
||||
// serving current requests, and one that is reparsing (follow qtcreator)
|
||||
|
@ -168,19 +168,14 @@ void IndexMain(IndexRequestQueue* requests, IndexResponseQueue* responses) {
|
||||
|
||||
Timer time;
|
||||
IndexedFile file = Parse(request->path, request->args);
|
||||
std::cerr << "Parsing/indexing took " << time.ElapsedMilliseconds()
|
||||
<< "ms" << std::endl;
|
||||
time.ResetAndPrint("Parsing/indexing");
|
||||
|
||||
time.Reset();
|
||||
IndexUpdate update(file);
|
||||
IndexTranslationUnitResponse response(update);
|
||||
std::cerr << "Creating index update took " << time.ElapsedMilliseconds()
|
||||
<< "ms" << std::endl;
|
||||
time.ResetAndPrint("Creating index update/response");
|
||||
|
||||
time.Reset();
|
||||
responses->Enqueue(response);
|
||||
std::cerr << "Sending to server took " << time.ElapsedMilliseconds()
|
||||
<< "ms" << std::endl;
|
||||
time.ResetAndPrint("Sending update to server");
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,11 +207,9 @@ void AddCodeLens(std::vector<TCodeLens>* result,
|
||||
const char* singular,
|
||||
const char* plural) {
|
||||
TCodeLens code_lens;
|
||||
code_lens.range.start.line =
|
||||
loc.line - 1; // TODO: cleanup indexer to negate by 1.
|
||||
code_lens.range.start.character =
|
||||
loc.column - 1; // TODO: cleanup indexer to negate by 1.
|
||||
// TODO: store range information.
|
||||
code_lens.range.start.line = loc.line - 1;
|
||||
code_lens.range.start.character = loc.column - 1;
|
||||
// TODO: store range information.
|
||||
code_lens.range.end.line = code_lens.range.start.line;
|
||||
code_lens.range.end.character = code_lens.range.start.character;
|
||||
|
||||
@ -379,7 +372,7 @@ void QueryDbMainLoop(
|
||||
|
||||
Timer timer;
|
||||
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);
|
||||
break;
|
||||
}
|
||||
@ -620,8 +613,7 @@ void QueryDbMainLoop(
|
||||
|
||||
Timer time;
|
||||
db->ApplyIndexUpdate(&response->update);
|
||||
std::cerr << "Applying index update took " << time.ElapsedMilliseconds()
|
||||
<< "ms" << std::endl;
|
||||
time.ResetAndPrint("Applying index update");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,6 @@ std::vector<CompilationEntry> LoadCompilationEntriesFromDirectory(const std::str
|
||||
CXCompileCommand cx_command = clang_CompileCommands_getCommand(cx_commands, i);
|
||||
CompilationEntry entry;
|
||||
|
||||
// TODO: remove ComplationEntry::directory
|
||||
std::string directory = clang::ToString(clang_CompileCommand_getDirectory(cx_command));
|
||||
std::string relative_filename = clang::ToString(clang_CompileCommand_getFilename(cx_command));
|
||||
std::string absolute_filename = directory + "/" + relative_filename;
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "timer.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Timer::Timer() {
|
||||
Reset();
|
||||
}
|
||||
@ -8,6 +10,11 @@ void Timer::Reset() {
|
||||
start = Clock::now();
|
||||
}
|
||||
|
||||
void Timer::ResetAndPrint(const std::string& message) {
|
||||
std::cerr << message << " took " << ElapsedMilliseconds() << "ms" << std::endl;
|
||||
Reset();
|
||||
}
|
||||
|
||||
long long Timer::ElapsedMilliseconds() {
|
||||
std::chrono::time_point<Clock> end = Clock::now();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
|
||||
struct Timer {
|
||||
using Clock = std::chrono::high_resolution_clock;
|
||||
@ -10,6 +11,8 @@ struct Timer {
|
||||
|
||||
// Restart/reset the timer.
|
||||
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.
|
||||
long long ElapsedMilliseconds();
|
||||
|
Loading…
Reference in New Issue
Block a user