Skip to content

Commit 7f0145a

Browse files
committed
[completion][tests] Add a test for "Completion Goto Definition"
This exposed a bug which also was fixed
1 parent 4bb072f commit 7f0145a

6 files changed

Lines changed: 72 additions & 1 deletion

File tree

src/cxref.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,16 @@ static void findAndGotoDefinition(ReferenceableItem *referenceable) {
863863
SessionStackEntry *top = sessionData.browsingStack.top;
864864
BrowserMenu menu = makeBrowserMenu(*referenceable, true, true, 0, UsageUsed, UsageNone,
865865
NO_POSITION);
866+
top->hkSelectedSym = &menu; // Needed for createSelectionMenu to find matching symbols
866867
top->menu = &menu;
867-
ensureReferencesAreLoadedFor(referenceable->linkName);
868+
869+
// Load references from disk and associate with menu
870+
scanReferencesToCreateMenu(referenceable->linkName);
871+
mapOverReferenceableItemTable(putOnLineLoadedReferences);
872+
recomputeSelectedReferenceable(top);
873+
868874
orderRefsAndGotoDefinition(top);
875+
top->hkSelectedSym = NULL;
869876
top->menu = NULL;
870877

871878
// recover stack
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
include ../Makefile.server
2+
3+
$(TEST): CXrefs
4+
@$(SERVER_DRIVER) commands.input $(EXTRA) > output.tmp
5+
@$(NORMALIZE) output.tmp > output
6+
@$(VERIFY)
7+
8+
trace: EXTRA = \'-debug\'
9+
trace: $(TEST)
10+
11+
CXrefs: .c-xrefrc
12+
@$(CXREF) src -create -o $(TEST).log
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CXREF -xrefrc CURDIR/.c-xrefrc src/main.c -xrefactory-II -server -log=log.log -commandlog=commands.log
2+
-olcxgetprojectname -xrefrc CURDIR/.c-xrefrc CURDIR/src/main.c
3+
<sync>
4+
-olcxcomplet CURDIR/src/main.c -olcursor=243 -xrefrc CURDIR/.c-xrefrc -p CURDIR
5+
<sync>
6+
-olcxcgoto1 -xrefrc CURDIR/.c-xrefrc -p CURDIR
7+
<sync>
8+
<exit>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CXREF -xrefrc CURDIR/.c-xrefrc src/main.c -xrefactory-II -server -log=log.log -commandlog=commands.log -o server-buffer
2+
-olcxgetprojectname -xrefrc CURDIR/.c-xrefrc CURDIR/src/main.c
3+
end-of-options
4+
5+
<sync>
6+
<set-info len=<n>>CURDIR</set-info>
7+
-olcxcomplet CURDIR/src/main.c -olcursor=243 -xrefrc CURDIR/.c-xrefrc -p CURDIR
8+
end-of-options
9+
10+
<sync>
11+
<all-completions nofocus=0 len=<n>>my_global_first :void my_global_first(int arg)
12+
my_global_second :void my_global_second(void )</all-completions>
13+
-olcxcgoto1 -xrefrc CURDIR/.c-xrefrc -p CURDIR
14+
end-of-options
15+
16+
<sync>
17+
<goto>
18+
<position-lc line=4 col=5 len=<n>>CURDIR/src/main.c</position-lc>
19+
</goto>
20+
-exit
21+
end-of-options
22+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "myheader.h"
2+
3+
/* Definition of the global function */
4+
void my_global_first(int arg) {
5+
int local_var = arg;
6+
}
7+
8+
void my_global_second(void) {
9+
}
10+
11+
void caller(void) {
12+
/* Complete here to get menu with two options */
13+
my_global_
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef MYHEADER_H
2+
#define MYHEADER_H
3+
4+
/* Global function declarations */
5+
void my_global_first(int arg);
6+
void my_global_second(void);
7+
8+
#endif

0 commit comments

Comments
 (0)