mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 12:05:50 +00:00
Add "Base" code lens which jumps the editor to the base method definition.
This commit is contained in:
parent
215a9a80fb
commit
7f4918ab15
@ -27,7 +27,9 @@ int foo() {
|
||||
|
||||
float MyBar::MemberFunc(int a, char b, std::vector<int> foo) {
|
||||
this->x = 100;
|
||||
return 0;
|
||||
this->MemberFunc(0, 0, {});
|
||||
|
||||
return ::foo();
|
||||
}
|
||||
|
||||
|
||||
|
96
foo/a.cc
Normal file
96
foo/a.cc
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
abc
|
||||
daaa
|
||||
faf
|
||||
dakkdakk
|
||||
abaa
|
||||
*/
|
||||
#include <string>
|
||||
|
||||
#include "a.h"
|
||||
|
||||
struct Middle : public Parent {
|
||||
void foo() override {}
|
||||
};
|
||||
struct DerivedA : public Middle {
|
||||
void foo() override {}
|
||||
};
|
||||
struct DerivedB : public Middle {
|
||||
void foo() override {}
|
||||
};
|
||||
struct Derived2B : public DerivedB {
|
||||
void foo() override {}
|
||||
};
|
||||
|
||||
struct Derived2C : public DerivedB {
|
||||
void foo() override;
|
||||
};
|
||||
|
||||
|
||||
void Derived2C::foo() {}
|
||||
|
||||
void User() {
|
||||
Parent p;
|
||||
Middle m;
|
||||
DerivedA da;
|
||||
DerivedB db;
|
||||
Derived2B d2b;
|
||||
|
||||
p.foo();
|
||||
m.foo();
|
||||
da.foo();
|
||||
db.foo();
|
||||
d2b.foo();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct Saaaaaa {};
|
||||
|
||||
struct S2 {
|
||||
S2() {}
|
||||
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
struct MyFoo {
|
||||
std::string name;
|
||||
};
|
||||
|
||||
void f() {
|
||||
S2 s2;
|
||||
s2.a += 10;
|
||||
s2.b -= 100;
|
||||
s2.b -= 5;
|
||||
|
||||
MyFoo f;
|
||||
// f.name = 10;
|
||||
f.name = "okay";
|
||||
|
||||
MyFoo f2;
|
||||
f2.name = "yes!";
|
||||
}
|
||||
|
||||
|
||||
void baz();
|
||||
|
||||
void foo();
|
||||
void foo();
|
||||
|
||||
void foo() {}
|
||||
|
||||
/**/
|
||||
void caller() {
|
||||
MyFoo fff;
|
||||
fff.name = "this name";
|
||||
baz();
|
||||
baz();
|
||||
baz();
|
||||
foo();
|
||||
|
||||
foo();
|
||||
foo();
|
||||
}
|
@ -951,8 +951,6 @@ void QueryDbMainLoop(
|
||||
}
|
||||
|
||||
case IpcId::TextDocumentCodeLens: {
|
||||
// TODO: add code lens for
|
||||
// - jump to parent method for functions
|
||||
auto msg = static_cast<Ipc_TextDocumentCodeLens*>(message.get());
|
||||
|
||||
Out_TextDocumentCodeLens response;
|
||||
@ -991,27 +989,6 @@ void QueryDbMainLoop(
|
||||
|
||||
int offset = 0;
|
||||
|
||||
/*
|
||||
// TODO: See if we can get this working.
|
||||
optional<QueryableLocation> base_definition = GetBaseDefinitionSpelling(db, func);
|
||||
if (base_definition) {
|
||||
optional<lsLocation> ls_base = GetLsLocation(db, working_files, *base_definition);
|
||||
if (ls_base) {
|
||||
optional<lsRange> range = GetLsRange(common.working_file, ref.loc.range);
|
||||
if (range) {
|
||||
TCodeLens code_lens;
|
||||
code_lens.range = *range;
|
||||
code_lens.command = lsCommand<lsCodeLensCommandArguments>();
|
||||
code_lens.command->command = "superindex.goto";
|
||||
code_lens.command->arguments.uri = GetLsDocumentUri(db, ref.loc.path);
|
||||
code_lens.command->arguments.position = code_lens.range.start;
|
||||
code_lens.command->arguments.locations.push_back(*ls_base);
|
||||
response.result.push_back(code_lens);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
std::vector<QueryFuncRef> base_callers = GetCallersForAllBaseFunctions(db, func);
|
||||
std::vector<QueryFuncRef> derived_callers = GetCallersForAllDerivedFunctions(db, func);
|
||||
if (base_callers.empty() && derived_callers.empty()) {
|
||||
@ -1027,11 +1004,32 @@ void QueryDbMainLoop(
|
||||
}
|
||||
|
||||
AddCodeLens(&common, ref.loc.OffsetStartColumn(offset++), ToQueryableLocation(db, func.derived), "derived", "derived");
|
||||
|
||||
// "Base"
|
||||
optional<QueryableLocation> base_definition = GetBaseDefinitionSpelling(db, func);
|
||||
if (base_definition) {
|
||||
optional<lsLocation> ls_base = GetLsLocation(db, working_files, *base_definition);
|
||||
if (ls_base) {
|
||||
optional<lsRange> range = GetLsRange(common.working_file, ref.loc.range);
|
||||
if (range) {
|
||||
TCodeLens code_lens;
|
||||
code_lens.range = *range;
|
||||
code_lens.range.start.character += offset++;
|
||||
code_lens.command = lsCommand<lsCodeLensCommandArguments>();
|
||||
code_lens.command->title = "Base";
|
||||
code_lens.command->command = "superindex.goto";
|
||||
code_lens.command->arguments.uri = ls_base->uri;
|
||||
code_lens.command->arguments.position = ls_base->range.start;
|
||||
response.result.push_back(code_lens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryableVarDef& def = db->vars[symbol.idx];
|
||||
AddCodeLens(&common, ref.loc.OffsetStartColumn(0), def.uses, "reference", "references", true /*exclude_loc*/, false /*only_interesting*/);
|
||||
AddCodeLens(&common, ref.loc.OffsetStartColumn(0), def.uses, "ref", "refs", true /*exclude_loc*/, false /*only_interesting*/);
|
||||
break;
|
||||
}
|
||||
case SymbolKind::File:
|
||||
|
Loading…
Reference in New Issue
Block a user