Index file language and send it on hover

This commit is contained in:
topisani 2017-11-30 04:47:29 +01:00 committed by Jacob Dufault
parent eac644d81a
commit 28ad5b1ed1
7 changed files with 47 additions and 2 deletions

View File

@ -2328,7 +2328,9 @@ bool QueryDbMainLoop(Config* config,
if (!ls_range)
continue;
response.result.contents = GetHoverForSymbol(db, ref.idx);
response.result.contents.value = GetHoverForSymbol(db, ref.idx);
response.result.contents.language = file->def->language;
response.result.range = *ls_range;
break;
}

View File

@ -995,6 +995,24 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
if (!db)
return;
// update the file language
// TODO: only do this when |is_first_ownership| in ConsumeFile is true
switch (clang_getCursorLanguage(decl->cursor)) {
case CXLanguage_C:
db->language = "c";
break;
case CXLanguage_CPlusPlus:
db->language = "c++";
break;
case CXLanguage_ObjC:
db->language = "objc";
break;
case CXLanguage_Invalid:
db->language = "invalid";
break;
}
NamespaceHelper* ns = &param->ns;
// std::cerr << "DECL kind=" << decl->entityInfo->kind << " at " <<

View File

@ -473,6 +473,8 @@ struct IndexFile {
std::string path;
std::vector<std::string> args;
int64_t last_modification_time = 0;
// "c++", "c", "obj-c", "invalid" or "unknown"
std::string language;
// The path to the translation unit cc file which caused the creation of this
// IndexFile. When parsing a translation unit we generate many IndexFile

View File

@ -1179,6 +1179,24 @@ MAKE_REFLECT_STRUCT(lsSignatureHelp,
signatures,
activeSignature,
activeParameter);
// MarkedString can be used to render human readable text. It is either a markdown string
// or a code-block that provides a language and a code snippet. The language identifier
// is sematically equal to the optional language identifier in fenced code blocks in GitHub
// issues. See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting
//
// The pair of a language and a value is an equivalent to markdown:
// ```${language}
// ${value}
// ```
//
// Note that markdown strings will be sanitized - that means html will be escaped.
struct lsMarkedString {
std::string language;
std::string value;
};
MAKE_REFLECT_STRUCT(lsMarkedString, language, value);
struct Out_TextDocumentSignatureHelp
: public lsOutMessage<Out_TextDocumentSignatureHelp> {
lsRequestId id;
@ -1228,7 +1246,7 @@ struct Ipc_TextDocumentHover : public IpcMessage<Ipc_TextDocumentHover> {
MAKE_REFLECT_STRUCT(Ipc_TextDocumentHover, id, params);
struct Out_TextDocumentHover : public lsOutMessage<Out_TextDocumentHover> {
struct Result {
std::string contents;
lsMarkedString contents;
optional<lsRange> range;
};

View File

@ -171,6 +171,7 @@ void CompareGroups(std::vector<T>& previous_data,
QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) {
QueryFile::Def def;
def.path = indexed.path;
def.language = indexed.language;
def.includes = indexed.includes;
def.inactive_regions = indexed.skipped_by_preprocessor;

View File

@ -169,6 +169,8 @@ void Reflect(TVisitor& visitor, MergeableUpdate<TId, TValue>& value) {
struct QueryFile {
struct Def {
std::string path;
// Language identifier
std::string language;
// Includes in the file.
std::vector<IndexInclude> includes;
// Outline of the file (ie, for code lens).
@ -191,6 +193,7 @@ struct QueryFile {
};
MAKE_REFLECT_STRUCT(QueryFile::Def,
path,
language,
outline,
all_symbols,
inactive_regions);

View File

@ -169,6 +169,7 @@ void Reflect(TVisitor& visitor, IndexFile& value) {
if (!gTestOutputMode) {
REFLECT_MEMBER(version);
REFLECT_MEMBER(last_modification_time);
REFLECT_MEMBER(language);
REFLECT_MEMBER(import_file);
REFLECT_MEMBER(args);
}