-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Per file compile flags and cwd #31
base: master
Are you sure you want to change the base?
Changes from all commits
507f893
0b734f1
0d696e1
c030cb6
bc34a85
f9b9c50
42cfd72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from clang.cindex import * | ||
import vim | ||
import time | ||
import re | ||
import time | ||
import threading | ||
import vim | ||
|
||
def initClangComplete(clang_complete_flags, library_path = None): | ||
global index | ||
|
@@ -24,56 +24,10 @@ def getCurrentFile(): | |
file = "\n".join(vim.eval("getline(1, '$')")) | ||
return (vim.current.buffer.name, file) | ||
|
||
class CodeCompleteTimer: | ||
def __init__(self, debug, file, line, column): | ||
self._debug = debug | ||
|
||
if not debug: | ||
return | ||
|
||
content = vim.eval("getline('.')"); | ||
print " " | ||
print "libclang code completion" | ||
print "========================" | ||
print "File: %s" % file | ||
print "Line: %d, Column: %d" % (line, column) | ||
print " " | ||
print "%s" % content | ||
|
||
print " " | ||
|
||
current = time.time() | ||
self._start = current | ||
self._last = current | ||
self._events = [] | ||
|
||
def registerEvent(self, event): | ||
if not self._debug: | ||
return | ||
def getCurrentTranslationUnit(update = False): | ||
currentFile = getCurrentFile() | ||
fileName = vim.current.buffer.name | ||
|
||
current = time.time() | ||
since_last = current - self._last | ||
self._last = current | ||
self._events.append((event, since_last)) | ||
|
||
def finish(self): | ||
if not self._debug: | ||
return | ||
|
||
overall = self._last - self._start | ||
|
||
for event in self._events: | ||
name, since_last = event | ||
percent = 1 / overall * since_last * 100 | ||
print "libclang code completion - %25s: %.3fs (%5.1f%%)" % \ | ||
(name, since_last, percent) | ||
|
||
print " " | ||
print "Overall: %.3f s" % overall | ||
print "========================" | ||
print " " | ||
|
||
def getCurrentTranslationUnit(args, currentFile, fileName, update = False): | ||
if fileName in translationUnits: | ||
tu = translationUnits[fileName] | ||
if update: | ||
|
@@ -85,10 +39,29 @@ def getCurrentTranslationUnit(args, currentFile, fileName, update = False): | |
print "LibClang - Reparsing: %.3f" % elapsed | ||
return tu | ||
|
||
userOptionsGlobal = vim.eval("g:clang_user_options").split(" ") | ||
userOptionsLocal = vim.eval("b:clang_user_options").split(" ") | ||
userOptionsPerFileDict = vim.eval( | ||
"g:clang_per_file_user_options('%s')" % fileName) | ||
userOptionsPerFile = userOptionsPerFileDict.get("flags", "").split(" ") | ||
args = userOptionsGlobal + userOptionsLocal + userOptionsPerFile | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we add this new option, we should probably move the option handling of libclang and clang-binary handling into a single function. I would prefer to |
||
old_cwd = vim.eval('getcwd()') | ||
new_cwd = userOptionsPerFileDict.get('cwd', old_cwd) | ||
print old_cwd, new_cwd | ||
|
||
if debug: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the print statement remaining debugging output? Can we remove it? |
||
start = time.time() | ||
flags = TranslationUnit.PARSE_PRECOMPILED_PREAMBLE | ||
tu = index.parse(fileName, args, [currentFile], flags) | ||
try: | ||
vim.command('cd ' + new_cwd) | ||
#vim.command('cd base') | ||
#print vim.eval('getcwd()') | ||
flags = TranslationUnit.PARSE_PRECOMPILED_PREAMBLE | ||
tu = index.parse(fileName, args, [currentFile], flags) | ||
tu.cwd = new_cwd | ||
finally: | ||
vim.command('cd ' + old_cwd) | ||
|
||
if debug: | ||
elapsed = (time.time() - start) | ||
print "LibClang - First parse: %.3f" % elapsed | ||
|
@@ -219,8 +192,13 @@ def getCurrentCompletionResults(line, column, args, currentFile, fileName, | |
tu = getCurrentTranslationUnit(args, currentFile, fileName) | ||
timer.registerEvent("Get TU") | ||
|
||
cr = tu.codeComplete(fileName, line, column, [currentFile], | ||
complete_flags) | ||
old_cwd = vim.eval('getcwd()') | ||
try: | ||
vim.command('cd ' + tu.cwd) | ||
cr = tu.codeComplete(fileName, line, column, [currentFile], | ||
complete_flags) | ||
finally: | ||
vim.command('cd ' + old_cwd) | ||
timer.registerEvent("Code Complete") | ||
return cr | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is too much limiting. Let's say that I have a directory with a.cpp and b.cpp files inside it, and for some reason I've specified two separate sets of build options in my Makefile. This approach would make it impossible to set the correct options for both of these files.
Also, designing clang_per_file_user_options this way causes another (IMO more major) problem. Let's say that you're working on a very large project with tons of directories. This would practically mean that you have to store the build options twice, once in your build system (Makefiles or whatnot) and once again in another db accessible by clang_per_file_user_options (as in https://gist.github.com/813631). However, if clang_per_file_user_options way designed to take the file name instead, it could do something like:
make source.cpp CC=echo CXX=echo
to make the build system print the correct command line for the file in question. This approach would address both of the above problems. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, looking closer into this, I think the clang_per_file_user_options implementation in https://gist.github.com/813631 might have tricked me, although I'm still not sure if that would provide the flexibility of getting the build options from the build system itself or not...