• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thoni56 / c-xrefactory / 1733

12 Feb 2026 11:48PM UTC coverage: 81.961% (+0.03%) from 81.933%
1733

push

travis-ci

thoni56
[refactor] Rename "local motion" to "peek" and separate external/internal push operations

External peek (Emacs Ctrl-F3/F4) now uses -olcxpushonly -olnodialog instead of the
dedicated -olcxpushforlm flag. Internal usage check in refactory.c gets its own
OP_INTERNAL_PUSH_FOR_USAGE_CHECK.  Added test_peek to verify browsing stack survives a
peek cycle.

14812 of 18072 relevant lines covered (81.96%)

16183425.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.77
src/reference_database.c
1
#include "reference_database.h"
2
#include "memory.h"
3
#include "stackmemory.h"
4
#include "log.h"
5
#include "globals.h"
6
#include "position.h"
7
#include "referenceableitemtable.h"
8
#include "usage.h"
9
#include <stdlib.h>
10
#include <string.h>
11

12
/* Opaque implementation structure */
13
struct ReferenceDatabase {
14
    /* For now, just a placeholder */
15
    int placeholder;
16
};
17

18
/* Context for searching the ReferenceableItemTable by position */
19
typedef struct {
20
    Position targetPosition;
21
    ReferenceableItem *found;
22
} FindReferenceableContext;
23

24
/* Check if target position is within the reference identifier */
25
static bool positionIsWithinReference(Position refStart, Position target, const char *linkName) {
10✔
26
    /* Must be same file and line */
27
    if (refStart.file != target.file || refStart.line != target.line)
10✔
28
        return false;
9✔
29

30
    /* Check if target column is within the identifier */
31
    int length = strlen(linkName);
1✔
32
    return target.col >= refStart.col && target.col < refStart.col + length;
33
}
34

35
/* Callback for mapOverReferenceableItemTableWithPointer */
8✔
36
static void checkReferenceableItemAtPosition(ReferenceableItem *item, void *contextPtr) {
8✔
37
    FindReferenceableContext *context = (FindReferenceableContext *)contextPtr;
38

39
    /* If already found, skip */
8✔
40
    if (context->found != NULL)
2✔
41
        return;
42

43
    /* Walk the references list for this item */
15✔
44
    for (Reference *ref = item->references; ref != NULL; ref = ref->next) {
10✔
45
        if (positionIsWithinReference(ref->position, context->targetPosition, item->linkName)) {
1✔
46
            log_trace("Found referenceable '%s' at %d:%d (target was %d:%d, length %zu)",
47
                     item->linkName, ref->position.line, ref->position.col,
48
                     context->targetPosition.line, context->targetPosition.col,
49
                     strlen(item->linkName));
1✔
50
            context->found = item;
1✔
51
            return;
52
        }
53
    }
54
}
55

56
/* Find the ReferenceableItem that has a Reference at the given position */
3✔
57
static ReferenceableItem* findReferenceableItemWithReferenceAt(Position position) {
3✔
58
    FindReferenceableContext context = {
59
        .targetPosition = position,
60
        .found = NULL
61
    };
62

3✔
63
    mapOverReferenceableItemTableWithPointer(checkReferenceableItemAtPosition, &context);
64

3✔
65
    return context.found;
66
}
67

7✔
68
ReferenceDatabase* createReferenceDatabase(void) {
7✔
69
    ReferenceDatabase* db = malloc(sizeof(ReferenceDatabase));
7✔
70
    if (db) {
7✔
71
        db->placeholder = 42; // Just to initialize something
72
    }
7✔
73
    return db;
74
}
75

6✔
76
void destroyReferenceDatabase(ReferenceDatabase *db) {
6✔
77
    if (db) {
6✔
78
        free(db);
79
    }
6✔
80
}
81

82
/* Extract the definition position from a ReferenceableItem's references */
1✔
83
static Position extractDefinitionPosition(ReferenceableItem *item) {
84
    /* Walk the references looking for the definition */
1✔
85
    for (Reference *ref = item->references; ref != NULL; ref = ref->next) {
1✔
86
        if (isDefinitionUsage(ref->usage)) {
87
            return ref->position;
88
        }
89
    }
×
90
    /* No definition found - return no position */
91
    return NO_POSITION;
92
}
3✔
93

94
ReferenceableResult findReferenceableAt(ReferenceDatabase *db, const char *fileName,
95
                                        Position position) {
96
    // TODO: This is where we would:
97
    // 1. Check if fileName needs to be rescanned (file modification time, etc.)
98
    // 2. Call parseCurrentInputFile() or similar to populate reference tables
99
    //
100
    // For now, assume the tables are already populated (by parsing elsewhere)
101

102
    (void)db;        // Suppress unused parameter warnings
103
    (void)fileName;  // fileName would be used for lazy parsing
104

3✔
105
    /* Find the ReferenceableItem that has a reference at this position */
106
    ReferenceableItem *item = findReferenceableItemWithReferenceAt(position);
3✔
107

2✔
108
    if (item == NULL) {
109
        return makeReferenceableFailure();
110
    }
111

1✔
112
    /* Extract the definition position from the item's references */
113
    Position definition = extractDefinitionPosition(item);
1✔
114

115
    return makeReferenceableResult(item, definition, true);
116
}
×
117

118
ReferencesResult getReferencesTo(ReferenceDatabase *db, const char *fileName, Position position) {
119
    // TODO: Automatically check if fileName or its dependencies have changed
120
    // TODO: Parse/reparse only the files that need updating
×
121
    // TODO: Then find all references to the referenceable at position
122
    return makeReferencesFailure();
123
}
124

125

3✔
126
/* Utility functions */
127
ReferenceableResult makeReferenceableResult(ReferenceableItem *referenceable, Position definition,
128
                                            bool found) {
3✔
129
    ReferenceableResult result;
3✔
130
    result.referenceable = referenceable;
3✔
131
    result.definition = definition;
3✔
132
    result.found = found;
133
    return result;
134
}
×
135

136
ReferencesResult makeReferencesResult(Reference *references, int count, bool found) {
×
137
    ReferencesResult result;
×
138
    result.references = references;
×
139
    result.count = count;
×
140
    result.found = found;
141
    return result;
142
}
2✔
143

2✔
144
ReferenceableResult makeReferenceableFailure(void) {
145
    return makeReferenceableResult(NULL, NO_POSITION, false);
146
}
×
147

×
148
ReferencesResult makeReferencesFailure(void) {
149
    return makeReferencesResult(NULL, 0, false);
150
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc