From cf0166ab5dad14bd99c21180e754dadda9d08492 Mon Sep 17 00:00:00 2001 From: Igor Bogoslavskyi Date: Sun, 28 Jan 2018 21:22:32 +0100 Subject: [PATCH] Use unsaved file content when reparsing (#410) Fix #321 --- plugin/clang/cindex50.py | 4 ++-- plugin/completion/lib_complete.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugin/clang/cindex50.py b/plugin/clang/cindex50.py index a1641cf8..42e59d0e 100644 --- a/plugin/clang/cindex50.py +++ b/plugin/clang/cindex50.py @@ -2884,8 +2884,8 @@ def reparse(self, unsaved_files=None, options=0): print(value) if not isinstance(value, str): raise TypeError('Unexpected unsaved file contents.') - unsaved_files_array[i].name = name - unsaved_files_array[i].contents = value + unsaved_files_array[i].name = name.encode('utf-8') + unsaved_files_array[i].contents = value.encode('utf-8') unsaved_files_array[i].length = len(value) ptr = conf.lib.clang_reparseTranslationUnit(self, len(unsaved_files), unsaved_files_array, options) diff --git a/plugin/completion/lib_complete.py b/plugin/completion/lib_complete.py index 41c67bc1..997d0f2d 100644 --- a/plugin/completion/lib_complete.py +++ b/plugin/completion/lib_complete.py @@ -323,8 +323,14 @@ def update(self, view, settings): if not self.tu: log.error("translation unit is not available. Not reparsing.") return False + + # Prepare unsaved files. + file_name = view.file_name() + file_body = view.substr(sublime.Region(0, view.size())) + unsaved_files = [(file_name, file_body)] + start = time.time() - self.tu.reparse() + self.tu.reparse(unsaved_files=unsaved_files) end = time.time() log.debug("reparsed in %s seconds", end - start) # Store and potentially show errors to the user.