Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the threads comment in config.hh w/ the actual core count used #600

Open
wants to merge 79 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift click to select a range
c8a55c8
Update wiki links and delete comparison with cquery
MaskRay Jan 4, 2019
c37417b
completion: if preamble size changes, rebuild it
MaskRay Jan 13, 2019
d556a08
Add -log-file=stderr and make it default
MaskRay Jan 21, 2019
6a51722
Drop support for clang 6
MaskRay Jan 21, 2019
1f0a509
Implement initialization option compilationDatabaseCommand on Windows
MaskRay Jan 21, 2019
e9a9fc8
cmake: delete SYSTEM_CLANG and auto-download mechanism
MaskRay Jan 22, 2019
cfac08b
Fix completion result sorting in VSCode (#210)
Riatre Jan 30, 2019
8a1177d
Log {Request,Notification}Message, and timestamp change due to depend…
MaskRay Jan 29, 2019
065071c
textDocument/signatureHelp: enable documentation
Riatre Oct 13, 2018
983b403
Fix is_local for vars with non-auto storage period
Riatre Oct 15, 2018
4fd6e11
Compute CompletionItemKind from Declaration instead of CursorKind
MaskRay Feb 2, 2019
f54a350
GetFallback: append clang.extraArgs
MaskRay Feb 10, 2019
7bc952e
Add initialization option `capabilities.*` and index.maxInitializerLines
MaskRay Feb 10, 2019
4f9e7b2
indexer: change Pos computation from byte offset to UTF-8 encoded cod…
MaskRay Feb 16, 2019
7e0d8a4
Use DiagnosticRelatedInformation if client supports publishDiagnostic…
LeszekSwirski Feb 21, 2019
f700ac7
Add cache.{hierarchicalPath,retainInMemory}
MaskRay Feb 21, 2019
9438be3
indexer: index TemplateTypeParmDecl and ParmVarDecl in declarations f…
MaskRay Feb 22, 2019
dd9d210
Make hover more detailed (e.g. include inheritance info)
MaskRay Feb 22, 2019
cafd2d4
Change Pos::line from int16_t to uint16_t
MaskRay Feb 23, 2019
3863b66
working_files: normalize \r\n and \n to \n
MaskRay Mar 2, 2019
bae9ecf
Add .github/ISSUE_TEMPLATE
MaskRay Mar 2, 2019
75684f0
textDocument/rename: mitigate edits in the same place and edits in ma…
MaskRay Mar 2, 2019
fcfd0dd
stdin: synthesize an "exit" NotificationMessage in abnormal termination
MaskRay Mar 4, 2019
38f4a8a
Make clang.excludeArgs accept glob patterns
MaskRay Mar 5, 2019
be391ee
Misc
MaskRay Mar 3, 2019
09b6f64
cmake: add option to use system rapidjson if exists
MaskRay Mar 9, 2019
5c9b055
Add excludeRole to documentSymbol and override declaration's range/se…
MaskRay Mar 9, 2019
bbb28c9
cmake: use {LLVM,Clang}Config.cmake
MaskRay Mar 10, 2019
c74d3df
If the workspace folder is a symlink, convert paths relative to it (#…
MaskRay Mar 10, 2019
89ec8ed
Add initialization option index.name.suppressUnwrittenScope (default:…
MaskRay Mar 10, 2019
4d68101
Change containers of Query*::Def fields from std::vector to ccls::Vec
MaskRay Mar 15, 2019
5853071
Enhance the output of --version with Git describe results. (#342)
madscientist Mar 24, 2019
752012f
Add initialization option index.initialNoLinkage: false
MaskRay Mar 25, 2019
193eacc
Adapt clang rC357037: removal of setVirtualFileSystem
MaskRay Mar 27, 2019
539ca22
Add error checking of object deserialization; ignore non-object initi…
MaskRay Mar 29, 2019
1d3fba2
Set RetainRemappedFileBuffers to true
MaskRay Mar 29, 2019
b1bcd0e
Set RetainCommentsFromSystemHeaders to true
MaskRay Apr 12, 2019
ea8baa6
Adapt clang rC358696: removal of OutputIsBinary
MaskRay Apr 19, 2019
137a9cd
Append '/' before populating folder.dot_ccls
Riatre Apr 28, 2019
bd0006a
JsonWriter: write "null" if VersionedTextDocumentIdentifier.version i…
MaskRay Apr 30, 2019
4dd97d4
Refactor FindEntry and use best-fit .ccls
MaskRay Apr 29, 2019
d472ffc
Adapt llvm rL360179: Option may have multiple OptionCategory's
MaskRay May 8, 2019
7f291c6
Set Diag::concerned if any of its Notes is concerned
MaskRay May 12, 2019
d55fd00
utils.hh: work around MSVC STL bug
MaskRay Jun 18, 2019
2d11cc2
threaded_queue.hh: fix -Wpessimizing-move (#409)
torokati44 Jun 18, 2019
6d0a096
Adapt rL364464: clang::FrontendAction::Execute returns llvm::Error in…
MaskRay Jun 27, 2019
73b75a2
pipeline: report changed arg
MaskRay Jun 27, 2019
e89e310
project: support %cu directive and strip -M* options
MaskRay Jun 28, 2019
0ca7d35
Only add include directories for LLVM, clang & rapidjson if they are …
dcermak Jun 27, 2019
034bd16
Change RequestId::value from int to std::string to allow non-numeric …
Riatre Jul 16, 2019
7e7a120
$ccls/fileInfo: optionally dump dependencies, includes and skipped_ra…
MaskRay Jul 20, 2019
d965bcd
Support indexing non-existent files in index.onChange:true mode
MaskRay Jul 20, 2019
9ff1897
project: improve ComputeGuessScore heuristics
MaskRay Jul 20, 2019
6528dcb
Construct SourceManager with UserFilesAreVolatile
MaskRay Jul 31, 2019
5200f43
Support override CLANG_RESOURCE_DIR
zhsj Aug 11, 2019
373e502
project: allow absolute compilationDatabaseDirectory
MaskRay Aug 17, 2019
1ca8d45
textDocument/definition: don't jump to the type definition
MaskRay Aug 22, 2019
91abea0
:boom: Rename FunctionName -> functionName, VarName -> var_name
MaskRay Aug 22, 2019
d2b904a
indexer: llvm::sys::fs::UniqueID -> clang::FileID
MaskRay Aug 22, 2019
a655ca9
indexer: disable warnings and skip processed function bodies
MaskRay Aug 22, 2019
718e2be
project: strip -Xclang <arg>
MaskRay Sep 12, 2019
330e633
completion: don't reuse cache if the buffer line has changed
MaskRay Sep 27, 2019
eabce35
Add initialization option completion.placeholder; change client.snipp…
MaskRay Oct 7, 2019
050a16c
Fix some clang-tidy warnings
MaskRay Oct 11, 2019
464ccd6
Infer -target and --driver-mode from argv[0]
MaskRay Nov 1, 2019
a7a982a
cmake: support CLANG_LINK_CLANG_DYLIB
MaskRay Nov 1, 2019
468a2fb
indexer: fix getAdjustedDecl for explicit instantiations; fix incorre…
MaskRay Nov 9, 2019
bd609e8
initialize: implement serverInfo (LSP 3.15.0)
nemethf Nov 11, 2019
cef0203
indexer: add name for anonymous Enum
Nov 15, 2019
86e340c
Adapt llvmorg-10-init-12036-g3b9715cb2193: handleDeclOccurence -> han…
MaskRay Dec 17, 2019
98f25b5
textDocument/documentSymbol: support unopened files (#548)
jlahoda Dec 22, 2019
ed64919
position: support line numbers larger than INT16_MAX (but <= UINT16_M…
adizero Dec 27, 2019
e2284a3
project: decrease score if .c is matched against .hh (#549)
MaskRay Dec 22, 2019
64e3e8f
Set indexer threads' priority to ThreadPriority::Background (#538)
eklitzke Dec 3, 2019
1834f81
Adapt D73392 - split of llvm/Support/Allocator.h
MaskRay Jan 25, 2020
b4af654
Adapt llvmorg-11-init-1314-g777180a32b6: StringRef's conversion to st…
MaskRay Jan 29, 2020
41e7d6a
Simplify: hide unrelated options
condy0919 Feb 10, 2020
5a08ff9
Add missing headers to adapt llvmorg-11-init-5501-g213aea4c583 and ll…
MaskRay Mar 12, 2020
f3a9ede
Update the threads comment in config.hh w/ the actual core count used
eklitzke Mar 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add cache.{hierarchicalPath,retainInMemory}
cache.hierarchicalPath: store cache files as $directory/a/b/c.cc.blob to
work around NAME_MAX limitation.

cache.retainInMemory: after this number of loads, keep a copy of file
index in memory. If set to 1, it avoids cache corruption if the index
file is changed after the initial load, which may happen if several
language clients open the same project and share the same cache
directory.

Also rename cacheDirectory cacheFormat to cache.{directory,format}
  • Loading branch information
MaskRay committed Nov 10, 2019
commit f700ac7b4c97bdcf01a71d24b5b2e81d43982530
56 changes: 40 additions & 16 deletions src/config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 28,41 @@ struct Config {
std::string compilationDatabaseCommand;
// Directory containing compile_commands.json.
std::string compilationDatabaseDirectory;
// Cache directory for indexed files, either absolute or relative to the
// project root.
// If empty, cache will be stored in memory.
std::string cacheDirectory = ".ccls-cache";
// Cache serialization format.
//
// "json" generates `cacheDirectory/.../xxx.json` files which can be pretty
// printed with jq.
//
// "binary" uses a compact binary serialization format.
// It is not schema-aware and you need to re-index whenever an internal struct
// member has changed.
SerializeFormat cacheFormat = SerializeFormat::Binary;

struct Cache {
// Cache directory for indexed files, either absolute or relative to the
// project root.
//
// If empty, retainInMemory will be set to 1 and cache will be stored in
// memory.
std::string directory = ".ccls-cache";

// Cache serialization format.
//
// "json" generates $directory/.../xxx.json files which can be pretty
// printed with jq.
//
// "binary" uses a compact binary serialization format.
// It is not schema-aware and you need to re-index whenever an internal
// struct member has changed.
SerializeFormat format = SerializeFormat::Binary;

// If false, store cache files as $directory/@a@b/c.cc.blob
//
// If true, $directory/a/b/c.cc.blob. If cache.directory is absolute, make
// sure different projects use different cache.directory as they would have
// conflicting cache files for system headers.
bool hierarchicalPath = false;

// After this number of loads, keep a copy of file index in memory (which
// increases memory usage). During incremental updates, the index subtracted
// will come from the in-memory copy, instead of the on-disk file.
//
// The initial load or a save action is counted as one load.
// 0: never retain; 1: retain after initial load; 2: retain after 2 loads
// (initial load first save)
int retainInMemory = 2;
} cache;

struct ServerCap {
struct DocumentOnTypeFormattingOptions {
Expand Down Expand Up @@ -280,6 302,8 @@ struct Config {
int maxNum = 2000;
} xref;
};
REFLECT_STRUCT(Config::Cache, directory, format, hierarchicalPath,
retainInMemory);
REFLECT_STRUCT(Config::ServerCap::DocumentOnTypeFormattingOptions,
firstTriggerCharacter, moreTriggerCharacter);
REFLECT_STRUCT(Config::ServerCap::Workspace::WorkspaceFolders, supported,
Expand Down Expand Up @@ -309,9 333,9 @@ REFLECT_STRUCT(Config::Session, maxNum);
REFLECT_STRUCT(Config::WorkspaceSymbol, caseSensitivity, maxNum, sort);
REFLECT_STRUCT(Config::Xref, maxNum);
REFLECT_STRUCT(Config, compilationDatabaseCommand, compilationDatabaseDirectory,
cacheDirectory, cacheFormat, capabilities, clang, client,
codeLens, completion, diagnostics, highlight, index, request,
session, workspaceSymbol, xref);
cache, capabilities, clang, client, codeLens, completion,
diagnostics, highlight, index, request, session, workspaceSymbol,
xref);

extern Config *g_config;

Expand Down
17 changes: 10 additions & 7 deletions src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 282,12 @@ void Initialize(MessageHandler *m, InitializeParam &param, ReplyOnce &reply) {
Reflect(json_writer, *g_config);
LOG_S(INFO) << "initializationOptions: " << output.GetString();

if (g_config->cacheDirectory.size()) {
SmallString<256> Path(g_config->cacheDirectory);
if (g_config->cache.directory.size()) {
SmallString<256> Path(g_config->cache.directory);
sys::fs::make_absolute(project_path, Path);
// Use upper case for the Driver letter on Windows.
g_config->cacheDirectory = NormalizePath(Path.str());
EnsureEndsInSlash(g_config->cacheDirectory);
g_config->cache.directory = NormalizePath(Path.str());
EnsureEndsInSlash(g_config->cache.directory);
}
}

Expand Down Expand Up @@ -334,13 334,16 @@ void Initialize(MessageHandler *m, InitializeParam &param, ReplyOnce &reply) {
}
if (param.workspaceFolders.empty())
g_config->workspaceFolders.push_back(project_path);
if (g_config->cacheDirectory.size())

if (g_config->cache.directory.empty())
g_config->cache.retainInMemory = 1;
else if (!g_config->cache.hierarchicalPath)
for (const std::string &folder : g_config->workspaceFolders) {
// Create two cache directories for files inside and outside of the
// project.
std::string escaped = EscapeFileName(folder.substr(0, folder.size() - 1));
sys::fs::create_directories(g_config->cacheDirectory escaped);
sys::fs::create_directories(g_config->cacheDirectory '@' escaped);
sys::fs::create_directories(g_config->cache.directory escaped);
sys::fs::create_directories(g_config->cache.directory '@' escaped);
}

idx::Init();
Expand Down
1 change: 1 addition & 0 deletions src/messages/textDocument_did.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 23,7 @@ void MessageHandler::textDocument_didClose(TextDocumentParam &param) {
std::string path = param.textDocument.uri.GetPath();
wfiles->OnClose(path);
manager->OnClose(path);
pipeline::RemoveCache(path);
}

void MessageHandler::textDocument_didOpen(DidOpenTextDocumentParam &param) {
Expand Down
4 changes: 2 additions & 2 deletions src/messages/workspace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 34,8 @@ void MessageHandler::workspace_didChangeWatchedFiles(
DidChangeWatchedFilesParam &param) {
for (auto &event : param.changes) {
std::string path = event.uri.GetPath();
if ((g_config->cacheDirectory.size() &&
StringRef(path).startswith(g_config->cacheDirectory)) ||
if ((g_config->cache.directory.size() &&
StringRef(path).startswith(g_config->cache.directory)) ||
lookupExtension(path).first == LanguageId::Unknown)
return;
for (std::string cur = path; cur.size(); cur = sys::path::parent_path(cur))
Expand Down
61 changes: 41 additions & 20 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 45,7 @@ void VFS::Clear() {
state.clear();
}

bool VFS::Loaded(const std::string &path) {
int VFS::Loaded(const std::string &path) {
std::lock_guard lock(mutex);
return state[path].loaded;
}
Expand Down Expand Up @@ -125,35 125,43 @@ bool CacheInvalid(VFS *vfs, IndexFile *prev, const std::string &path,
};

std::string AppendSerializationFormat(const std::string &base) {
switch (g_config->cacheFormat) {
switch (g_config->cache.format) {
case SerializeFormat::Binary:
return base ".blob";
case SerializeFormat::Json:
return base ".json";
}
}

std::string GetCachePath(const std::string &source_file) {
std::string GetCachePath(const std::string &src) {
if (g_config->cache.hierarchicalPath) {
std::string ret = src[0] == '/' ? src.substr(1) : src;
#ifdef _WIN32
std::replace(ret.begin(), ret.end(), ':', '@');
#endif
return g_config->cache.directory ret;
}
for (auto &root : g_config->workspaceFolders)
if (StringRef(source_file).startswith(root)) {
if (StringRef(src).startswith(root)) {
auto len = root.size();
return g_config->cacheDirectory
return g_config->cache.directory
EscapeFileName(root.substr(0, len - 1)) '/'
EscapeFileName(source_file.substr(len));
EscapeFileName(src.substr(len));
}
return g_config->cacheDirectory '@'
return g_config->cache.directory '@'
EscapeFileName(g_config->fallbackFolder.substr(
0, g_config->fallbackFolder.size() - 1))
'/' EscapeFileName(source_file);
'/' EscapeFileName(src);
}

std::unique_ptr<IndexFile> RawCacheLoad(const std::string &path) {
if (g_config->cacheDirectory.empty()) {
if (g_config->cache.retainInMemory) {
std::shared_lock lock(g_index_mutex);
auto it = g_index.find(path);
if (it == g_index.end())
if (it != g_index.end())
return std::make_unique<IndexFile>(it->second.index);
if (g_config->cache.directory.empty())
return nullptr;
return std::make_unique<IndexFile>(it->second.index);
}

std::string cache_path = GetCachePath(path);
Expand All @@ -163,7 171,7 @@ std::unique_ptr<IndexFile> RawCacheLoad(const std::string &path) {
if (!file_content || !serialized_indexed_content)
return nullptr;

return ccls::Deserialize(g_config->cacheFormat, path,
return ccls::Deserialize(g_config->cache.format, path,
*serialized_indexed_content, *file_content,
IndexFile::kMajorVersion);
}
Expand Down Expand Up @@ -275,7 283,7 @@ bool Indexer_Parse(SemaManager *completion, WorkingFiles *wfiles,
request.mode != IndexMode::NonInteractive);
{
std::lock_guard lock1(vfs->mutex);
vfs->state[path_to_index].loaded = true;
vfs->state[path_to_index].loaded ;
}
lock.unlock();

Expand All @@ -292,7 300,7 @@ bool Indexer_Parse(SemaManager *completion, WorkingFiles *wfiles,
VFS::State &st = vfs->state[path];
if (st.loaded)
continue;
st.loaded = true;
st.loaded ;
st.timestamp = prev->mtime;
}
IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get());
Expand Down Expand Up @@ -355,31 363,37 @@ bool Indexer_Parse(SemaManager *completion, WorkingFiles *wfiles,
<< " (delta: " << !!prev << ")";
{
std::lock_guard lock(GetFileMutex(path));
if (vfs->Loaded(path))
int loaded = vfs->Loaded(path), retain = g_config->cache.retainInMemory;
if (loaded)
prev = RawCacheLoad(path);
else
prev.reset();
if (g_config->cacheDirectory.empty()) {
if (retain > 0 && retain <= loaded 1) {
std::lock_guard lock(g_index_mutex);
auto it = g_index.insert_or_assign(
path, InMemoryIndexFile{curr->file_contents, *curr});
std::string().swap(it.first->second.index.file_contents);
} else {
}
if (g_config->cache.directory.size()) {
std::string cache_path = GetCachePath(path);
if (deleted) {
(void)sys::fs::remove(cache_path);
(void)sys::fs::remove(AppendSerializationFormat(cache_path));
} else {
if (g_config->cache.hierarchicalPath)
sys::fs::create_directories(
sys::path::parent_path(cache_path, sys::path::Style::posix),
true);
WriteToFile(cache_path, curr->file_contents);
WriteToFile(AppendSerializationFormat(cache_path),
Serialize(g_config->cacheFormat, *curr));
Serialize(g_config->cache.format, *curr));
}
}
on_indexed->PushBack(IndexUpdate::CreateDelta(prev.get(), curr.get()),
request.mode != IndexMode::NonInteractive);
{
std::lock_guard lock1(vfs->mutex);
vfs->state[path].loaded = true;
vfs->state[path].loaded ;
}
if (entry.id >= 0) {
std::lock_guard lock(project->mtx);
Expand Down Expand Up @@ -706,8 720,15 @@ void Index(const std::string &path, const std::vector<const char *> &args,
mode != IndexMode::NonInteractive);
}

void RemoveCache(const std::string &path) {
if (g_config->cache.directory.size()) {
std::lock_guard lock(g_index_mutex);
g_index.erase(path);
}
}

std::optional<std::string> LoadIndexedContent(const std::string &path) {
if (g_config->cacheDirectory.empty()) {
if (g_config->cache.directory.empty()) {
std::shared_lock lock(g_index_mutex);
auto it = g_index.find(path);
if (it == g_index.end())
Expand Down
6 changes: 3 additions & 3 deletions src/pipeline.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 22,13 @@ struct VFS {
struct State {
int64_t timestamp;
int step;
bool loaded;
int loaded;
};
std::unordered_map<std::string, State> state;
std::mutex mutex;

void Clear();
bool Loaded(const std::string &path);
int Loaded(const std::string &path);
bool Stamp(const std::string &path, int64_t ts, int step);
};

Expand All @@ -55,7 55,7 @@ void Standalone(const std::string &root);

void Index(const std::string &path, const std::vector<const char *> &args,
IndexMode mode, bool must_exist, RequestId id = {});

void RemoveCache(const std::string &path);
std::optional<std::string> LoadIndexedContent(const std::string& path);

void NotifyOrRequest(const char *method, bool request,
Expand Down
7 changes: 4 additions & 3 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 112,10 @@ void EnsureEndsInSlash(std::string &path) {

std::string EscapeFileName(std::string path) {
bool slash = path.size() && path.back() == '/';
for (char &c : path)
if (c == '\\' || c == '/' || c == ':')
c = '@';
#ifdef _WIN32
std::replace(path.begin(), path.end(), ':', '@');
#endif
std::replace(path.begin(), path.end(), '/', '@');
if (slash)
path = '/';
return path;
Expand Down