clang: re-scan after save to get latest changes.

Slightly behind the cursor but better for the cache. Removes need to pass unsaved file
This commit is contained in:
Andy Williams 2017-02-18 23:06:06 +00:00
parent b5c061bc4d
commit 784c6c4917
4 changed files with 18 additions and 14 deletions

View File

@ -42,6 +42,9 @@ edi_editor_save(Edi_Editor *editor)
editor->modified = EINA_FALSE;
ecore_timer_del(editor->save_timer);
editor->save_timer = NULL;
if (edi_language_provider_has(editor))
edi_language_provider_get(editor)->refresh(editor);
}
static Eina_Bool

View File

@ -13,11 +13,11 @@
static Edi_Language_Provider _edi_language_provider_registry[] =
{
{
"c", _edi_language_c_add, _edi_language_c_del, _edi_language_c_mime_name,
_edi_language_c_lookup, _edi_language_c_lookup_doc
"c", _edi_language_c_add, _edi_language_c_refresh, _edi_language_c_del,
_edi_language_c_mime_name, _edi_language_c_lookup, _edi_language_c_lookup_doc
},
{NULL, NULL, NULL, NULL, NULL, NULL}
{NULL, NULL, NULL, NULL, NULL, NULL, NULL}
};
Edi_Language_Provider *edi_language_provider_get(Edi_Editor *editor)

View File

@ -42,6 +42,7 @@ typedef struct _Edi_Language_Provider
const char *id;
void (*add)(Edi_Editor *editor);
void (*refresh)(Edi_Editor *editor);
void (*del)(Edi_Editor *editor);
const char *(*mime_name)(const char *mime);
Eina_List *(*lookup)(Edi_Editor *editor, unsigned int row, unsigned int col);

View File

@ -76,25 +76,16 @@ _clang_autosuggest_setup(Edi_Editor *editor)
Elm_Code *code;
const char *path;
const char **args;
unsigned int argc, end_row, end_col;
struct CXUnsavedFile unsaved_file;
unsigned int argc;
code = elm_code_widget_code_get(editor->entry);
path = elm_code_file_path_get(code->file);
end_row = elm_code_file_lines_get(code->file);
end_col = elm_code_file_line_get(code->file, end_row)->length;
unsaved_file.Filename = path;
unsaved_file.Contents = elm_code_widget_text_between_positions_get(
editor->entry, 1, 1, end_row, end_col);
unsaved_file.Length = strlen(unsaved_file.Contents);
//Initialize Clang
_clang_commands_get(path, &args, &argc);
editor->clang_idx = clang_createIndex(0, 0);
editor->clang_unit = clang_parseTranslationUnit(editor->clang_idx, path,
args, argc, NULL, 0, //&unsaved_file, 1,
args, argc, NULL, 0,
clang_defaultEditingTranslationUnitOptions() | CXTranslationUnit_DetailedPreprocessingRecord);
}
@ -114,6 +105,15 @@ _edi_language_c_add(Edi_Editor *editor)
#endif
}
void
_edi_language_c_refresh(Edi_Editor *editor)
{
#if HAVE_LIBCLANG
_clang_autosuggest_dispose(editor);
_clang_autosuggest_setup(editor);
#endif
}
void
_edi_language_c_del(Edi_Editor *editor)
{