2018-08-21 05:27:52 +00:00
|
|
|
// Copyright 2017-2018 ccls Authors
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2017-03-26 21:40:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-29 04:21:21 +00:00
|
|
|
#include "config.hh"
|
2018-10-28 17:49:31 +00:00
|
|
|
#include "lsp.hh"
|
2017-04-21 04:50:31 +00:00
|
|
|
|
|
|
|
#include <functional>
|
2017-04-20 05:46:10 +00:00
|
|
|
#include <mutex>
|
2017-03-31 04:21:52 +00:00
|
|
|
#include <string>
|
2018-03-31 20:59:27 +00:00
|
|
|
#include <unordered_map>
|
2017-03-31 04:21:52 +00:00
|
|
|
#include <vector>
|
2017-03-26 21:40:34 +00:00
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
namespace ccls {
|
2018-03-11 22:12:26 +00:00
|
|
|
struct WorkingFiles;
|
|
|
|
|
2018-10-14 06:22:29 +00:00
|
|
|
std::pair<LanguageId, bool> lookupExtension(std::string_view filename);
|
|
|
|
|
2017-03-26 21:40:34 +00:00
|
|
|
struct Project {
|
2017-04-20 05:01:36 +00:00
|
|
|
struct Entry {
|
2018-10-08 05:02:28 +00:00
|
|
|
std::string root;
|
2018-07-08 07:46:53 +00:00
|
|
|
std::string directory;
|
2017-04-20 05:01:36 +00:00
|
|
|
std::string filename;
|
2018-09-19 16:31:45 +00:00
|
|
|
std::vector<const char *> args;
|
2017-05-07 05:36:29 +00:00
|
|
|
// If true, this entry is inferred and was not read from disk.
|
|
|
|
bool is_inferred = false;
|
2018-12-21 09:05:23 +00:00
|
|
|
// 0 unless coming from a compile_commands.json entry.
|
|
|
|
int compdb_size = 0;
|
2018-05-05 22:29:17 +00:00
|
|
|
int id = -1;
|
2017-04-20 05:01:36 +00:00
|
|
|
};
|
|
|
|
|
2018-10-08 05:02:28 +00:00
|
|
|
struct Folder {
|
|
|
|
std::string name;
|
2018-12-21 09:05:23 +00:00
|
|
|
std::unordered_map<std::string, int> search_dir2kind;
|
2018-10-08 05:02:28 +00:00
|
|
|
std::vector<Entry> entries;
|
|
|
|
std::unordered_map<std::string, int> path2entry_index;
|
2018-12-21 09:05:23 +00:00
|
|
|
std::unordered_map<std::string, std::vector<const char *>> dot_ccls;
|
2018-10-08 05:02:28 +00:00
|
|
|
};
|
2017-05-21 07:37:53 +00:00
|
|
|
|
2018-12-21 09:05:23 +00:00
|
|
|
std::mutex mtx;
|
2018-10-08 05:02:28 +00:00
|
|
|
std::unordered_map<std::string, Folder> root2folder;
|
2017-03-26 21:40:34 +00:00
|
|
|
|
2017-03-31 04:21:52 +00:00
|
|
|
// Loads a project for the given |directory|.
|
|
|
|
//
|
2018-03-31 03:16:33 +00:00
|
|
|
// If |config->compilationDatabaseDirectory| is not empty, look for .ccls or
|
2018-03-11 22:12:26 +00:00
|
|
|
// compile_commands.json in it, otherwise they are retrieved in
|
|
|
|
// |root_directory|.
|
2018-03-31 03:16:33 +00:00
|
|
|
// For .ccls, recursive directory listing is used and files with known
|
|
|
|
// suffixes are indexed. .ccls files can exist in subdirectories and they
|
2018-03-20 02:51:42 +00:00
|
|
|
// will affect flags in their subtrees (relative paths are relative to the
|
|
|
|
// project root, not subdirectories). For compile_commands.json, its entries
|
|
|
|
// are indexed.
|
2018-12-21 09:05:23 +00:00
|
|
|
void Load(const std::string &root);
|
|
|
|
void LoadDirectory(const std::string &root, Folder &folder);
|
2017-03-31 04:21:52 +00:00
|
|
|
|
2017-05-07 05:36:29 +00:00
|
|
|
// Lookup the CompilationEntry for |filename|. If no entry was found this
|
|
|
|
// will infer one based on existing project structure.
|
2018-12-24 05:22:51 +00:00
|
|
|
Entry FindEntry(const std::string &path, bool can_redirect, bool must_exist);
|
2017-04-21 04:50:31 +00:00
|
|
|
|
2018-03-21 19:49:28 +00:00
|
|
|
// If the client has overridden the flags, or specified them for a file
|
|
|
|
// that is not in the compilation_database.json make sure those changes
|
|
|
|
// are permanent.
|
2018-09-19 16:31:45 +00:00
|
|
|
void SetArgsForFile(const std::vector<const char *> &args,
|
|
|
|
const std::string &path);
|
2018-03-21 19:49:28 +00:00
|
|
|
|
2018-11-03 20:52:43 +00:00
|
|
|
void Index(WorkingFiles *wfiles, RequestId id);
|
2017-03-31 04:21:52 +00:00
|
|
|
};
|
2018-10-28 17:49:31 +00:00
|
|
|
} // namespace ccls
|