Skip to content

Commit

Permalink
Consider arguments in cache entries
Browse files Browse the repository at this point in the history
  • Loading branch information
xaizek committed Jul 15, 2017
1 parent 3843d9f commit 52c88ca
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions plugin/libclang.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,16 @@ def initClangComplete(clang_complete_flags, clang_compilation_database, \
print(" This will cause slow code completion.")
print(" Please report the problem.")

# Cache of translation units. Maps paths of files:
# <source file path> : {
# 'tu': <translation unit object>,
# 'args': <list of arguments>,
# }
# New cache entry for the same path, but with different list of arguments,
# overwrite previously cached data.
global translationUnits
translationUnits = dict()

global complete_flags
complete_flags = int(clang_complete_flags)
global compilation_database
Expand Down Expand Up @@ -180,8 +188,9 @@ def finish(self):

def getCurrentTranslationUnit(args, currentFile, fileName, timer,
update = False):
tu = translationUnits.get(fileName)
if tu != None:
tuCache = translationUnits.get(fileName)
if tuCache is not None and tuCache['args'] == args:
tu = tuCache['tu']
if update:
tu.reparse([currentFile])
timer.registerEvent("Reparsing")
Expand All @@ -195,7 +204,7 @@ def getCurrentTranslationUnit(args, currentFile, fileName, timer,
except TranslationUnitLoadError as e:
return None

translationUnits[fileName] = tu
translationUnits[fileName] = { 'tu': tu, 'args': args }

# Reparse to initialize the PCH cache even for auto completion
# This should be done by index.parse(), however it is not.
Expand Down Expand Up @@ -273,11 +282,11 @@ def highlightDiagnostics(tu):

def highlightCurrentDiagnostics():
if vim.current.buffer.name in translationUnits:
highlightDiagnostics(translationUnits[vim.current.buffer.name])
highlightDiagnostics(translationUnits[vim.current.buffer.name]['tu'])

def getCurrentQuickFixList():
if vim.current.buffer.name in translationUnits:
return getQuickFixList(translationUnits[vim.current.buffer.name])
return getQuickFixList(translationUnits[vim.current.buffer.name]['tu'])
return []

# Get the compilation parameters from the compilation database for source
Expand Down

0 comments on commit 52c88ca

Please sign in to comment.