Skip to content

Instantly share code, notes, and snippets.

@aolo2
Created July 16, 2021 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aolo2/4d5e25c27942201de93eb1c646b9a7ac to your computer and use it in GitHub Desktop.
Save aolo2/4d5e25c27942201de93eb1c646b9a7ac to your computer and use it in GitHub Desktop.
CUSTOM_UI_COMMAND_SIG(jump_to_definition_at_cursor)
CUSTOM_DOC("Jump to the first definition in the code index matching an identifier at the cursor")
{
View_ID view = get_active_view(app, Access_Visible);
if (view != 0){
Scratch_Block scratch(app);
String_Const_u8 query = push_token_or_word_under_active_cursor(app, scratch);
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];
if (string_match(note->text, query)){
point_stack_push_view_cursor(app, view);
jump_to_location(app, view, buffer, note->pos.first);
goto done;
}
}
}
}
done:;
code_index_unlock();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment