2019-12-13 23:36:28 +00:00
|
|
|
/*
|
|
|
|
4coder_code_index_listers.cpp - Listers for exploring the contents of the code index.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
struct Tiny_Jump{
|
|
|
|
Buffer_ID buffer;
|
|
|
|
i64 pos;
|
|
|
|
};
|
|
|
|
|
2019-12-14 00:20:59 +00:00
|
|
|
CUSTOM_UI_COMMAND_SIG(jump_to_definition)
|
|
|
|
CUSTOM_DOC("List all definitions in the code index and jump to one chosen by the user.")
|
2019-12-13 23:36:28 +00:00
|
|
|
{
|
2019-12-14 00:20:59 +00:00
|
|
|
char *query = "Definition:";
|
2019-12-13 23:36:28 +00:00
|
|
|
|
2019-12-14 00:20:59 +00:00
|
|
|
Scratch_Block scratch(app);
|
2020-02-29 23:38:38 +00:00
|
|
|
Lister_Block lister(app, scratch);
|
2019-12-13 23:36:28 +00:00
|
|
|
lister_set_query(lister, query);
|
2020-02-29 23:38:38 +00:00
|
|
|
lister_set_default_handlers(lister);
|
2019-12-13 23:36:28 +00:00
|
|
|
|
|
|
|
code_index_lock();
|
|
|
|
for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always);
|
|
|
|
buffer != 0;
|
|
|
|
buffer = get_buffer_next(app, buffer, Access_Always)){
|
|
|
|
Code_Index_File *file = code_index_get_file(buffer);
|
|
|
|
if (file != 0){
|
|
|
|
for (i32 i = 0; i < file->note_array.count; i += 1){
|
|
|
|
Code_Index_Note *note = file->note_array.ptrs[i];
|
|
|
|
Tiny_Jump *jump = push_array(scratch, Tiny_Jump, 1);
|
|
|
|
jump->buffer = buffer;
|
|
|
|
jump->pos = note->pos.first;
|
2019-12-14 00:20:59 +00:00
|
|
|
|
|
|
|
String_Const_u8 sort = {};
|
|
|
|
switch (note->note_kind){
|
|
|
|
case CodeIndexNote_Type:
|
|
|
|
{
|
|
|
|
sort = string_u8_litexpr("type");
|
|
|
|
}break;
|
|
|
|
case CodeIndexNote_Function:
|
|
|
|
{
|
|
|
|
sort = string_u8_litexpr("function");
|
|
|
|
}break;
|
|
|
|
case CodeIndexNote_Macro:
|
|
|
|
{
|
|
|
|
sort = string_u8_litexpr("macro");
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
lister_add_item(lister, note->text, sort, jump, 0);
|
2019-12-13 23:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
code_index_unlock();
|
|
|
|
|
|
|
|
Lister_Result l_result = run_lister(app, lister);
|
|
|
|
Tiny_Jump result = {};
|
|
|
|
if (!l_result.canceled && l_result.user_data != 0){
|
|
|
|
block_copy_struct(&result, (Tiny_Jump*)l_result.user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.buffer != 0){
|
|
|
|
View_ID view = get_this_ctx_view(app, Access_Always);
|
|
|
|
jump_to_location(app, view, result.buffer, result.pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|