ccls/src/project.h

64 lines
2.0 KiB
C
Raw Normal View History

2018-08-21 05:27:52 +00:00
// Copyright 2017-2018 ccls Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "config.h"
2018-03-22 05:01:21 +00:00
#include "method.h"
#include <functional>
#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>
struct WorkingFiles;
struct Project {
2017-04-20 05:01:36 +00:00
struct Entry {
2018-07-08 07:46:53 +00:00
std::string directory;
2017-04-20 05:01:36 +00:00
std::string filename;
std::vector<std::string> args;
// If true, this entry is inferred and was not read from disk.
bool is_inferred = false;
int id = -1;
2017-04-20 05:01:36 +00:00
};
2017-05-21 07:37:53 +00:00
// Include directories for "" headers
std::vector<std::string> quote_include_directories;
// Include directories for <> headers
std::vector<std::string> angle_include_directories;
2017-04-20 05:01:36 +00:00
std::vector<Entry> entries;
std::mutex mutex_;
2018-09-10 06:46:13 +00:00
std::unordered_map<std::string, int> path_to_entry_index;
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
// 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-08-09 17:08:14 +00:00
void Load(const std::string &root_directory);
2017-03-31 04:21:52 +00:00
// Lookup the CompilationEntry for |filename|. If no entry was found this
// will infer one based on existing project structure.
2018-08-09 17:08:14 +00:00
Entry FindCompilationEntryForFile(const std::string &filename);
// 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-08-09 17:08:14 +00:00
void SetFlagsForFile(const std::vector<std::string> &flags,
const std::string &path);
// Run |action| on every file in the project.
2018-08-09 17:08:14 +00:00
void
ForAllFilteredFiles(std::function<void(int i, const Entry &entry)> action);
2018-08-09 17:08:14 +00:00
void Index(WorkingFiles *wfiles, lsRequestId id);
2017-03-31 04:21:52 +00:00
};