mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-24 08:35:08 +00:00
textDocument/definition: don't jump to the type definition
This commit is contained in:
parent
03263c8521
commit
459091af4f
@ -21,30 +21,6 @@ limitations under the License.
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
namespace ccls {
|
namespace ccls {
|
||||||
namespace {
|
|
||||||
std::vector<DeclRef> GetNonDefDeclarationTargets(DB *db, SymbolRef sym) {
|
|
||||||
switch (sym.kind) {
|
|
||||||
case Kind::Var: {
|
|
||||||
std::vector<DeclRef> ret = GetNonDefDeclarations(db, sym);
|
|
||||||
// If there is no declaration, jump to its type.
|
|
||||||
if (ret.empty()) {
|
|
||||||
for (auto &def : db->GetVar(sym).def)
|
|
||||||
if (def.type) {
|
|
||||||
if (Maybe<DeclRef> use =
|
|
||||||
GetDefinitionSpell(db, SymbolIdx{def.type, Kind::Type})) {
|
|
||||||
ret.push_back(*use);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return GetNonDefDeclarations(db, sym);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void MessageHandler::textDocument_declaration(TextDocumentPositionParam ¶m,
|
void MessageHandler::textDocument_declaration(TextDocumentPositionParam ¶m,
|
||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
int file_id;
|
int file_id;
|
||||||
@ -96,7 +72,7 @@ void MessageHandler::textDocument_definition(TextDocumentPositionParam ¶m,
|
|||||||
// |uses| is empty if on a declaration/definition, otherwise it includes
|
// |uses| is empty if on a declaration/definition, otherwise it includes
|
||||||
// all declarations/definitions.
|
// all declarations/definitions.
|
||||||
if (drs.empty()) {
|
if (drs.empty()) {
|
||||||
for (DeclRef dr : GetNonDefDeclarationTargets(db, sym))
|
for (DeclRef dr : GetNonDefDeclarations(db, sym))
|
||||||
if (!(dr.file_id == file_id &&
|
if (!(dr.file_id == file_id &&
|
||||||
dr.range.Contains(ls_pos.line, ls_pos.character)))
|
dr.range.Contains(ls_pos.line, ls_pos.character)))
|
||||||
drs.push_back(dr);
|
drs.push_back(dr);
|
||||||
|
Loading…
Reference in New Issue
Block a user