Skip to content

Commit cfbdfa8

Browse files
committed
ycm: add doc string for all the functions in configuration file
1 parent 50918c2 commit cfbdfa8

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

.ycm_extra_conf.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,24 @@
5151

5252

5353
def DirectoryOfThisScript():
54+
"""
55+
Return the absolute path of the parent directory containing this
56+
script.
57+
"""
5458
return os.path.dirname(os.path.abspath(__file__))
5559

5660

5761
def GuessBuildDirectory():
62+
"""
63+
Guess the build directory using the following heuristics:
64+
65+
1. Returns the current directory of this script plus 'build'
66+
subdirectory in absolute path if this subdirectory exists.
67+
68+
2. Otherwise, probes whether there exists any directory
69+
containing '.ninja_log' file two levels above the current directory;
70+
returns this single directory only if there is one candidate.
71+
"""
5872
result = os.path.join(DirectoryOfThisScript(), "build")
5973

6074
if os.path.exists(result):
@@ -73,6 +87,16 @@ def GuessBuildDirectory():
7387

7488

7589
def TraverseByDepth(root, include_extensions):
90+
"""
91+
Return a set of child directories of the 'root' containing file
92+
extensions specified in 'include_extensions'.
93+
94+
NOTE:
95+
1. The 'root' directory itself is excluded from the result set.
96+
2. No subdirectories would be excluded if 'include_extensions' is left
97+
to 'None'.
98+
3. Each entry in 'include_extensions' must begin with string '.'.
99+
"""
76100
is_root = True
77101
result = set()
78102
# Perform a depth first top down traverse of the given directory tree.
@@ -132,6 +156,11 @@ def TraverseByDepth(root, include_extensions):
132156

133157

134158
def MakeRelativePathsInFlagsAbsolute(flags, working_directory):
159+
"""
160+
Iterate through 'flags' and replace the relative paths prefixed by
161+
'-isystem', '-I', '-iquote', '--sysroot=' with absolute paths
162+
start with 'working_directory'.
163+
"""
135164
if not working_directory:
136165
return list(flags)
137166
new_flags = []
@@ -161,11 +190,17 @@ def MakeRelativePathsInFlagsAbsolute(flags, working_directory):
161190

162191

163192
def IsHeaderFile(filename):
193+
"""
194+
Check whether 'filename' is considered as a header file.
195+
"""
164196
extension = os.path.splitext(filename)[1]
165197
return extension in HEADER_EXTENSIONS
166198

167199

168200
def GetCompilationInfoForFile(filename):
201+
"""
202+
Helper function to look up compilation info of 'filename' in the 'database'.
203+
"""
169204
# The compilation_commands.json file generated by CMake does not have
170205
# entries for header files. So we do our best by asking the db for flags for
171206
# a corresponding source file, if any. If one exists, the flags for that
@@ -187,6 +222,13 @@ def GetCompilationInfoForFile(filename):
187222

188223

189224
def FlagsForFile(filename, **kwargs):
225+
"""
226+
Callback function to be invoked by YouCompleteMe in order to get the
227+
information necessary to compile 'filename'.
228+
229+
It returns a dictionary with a single element 'flags'. This element is a
230+
list of compiler flags to pass to libclang for the file 'filename'.
231+
"""
190232
if database:
191233
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
192234
# python list, but a "list-like" StringVec object

0 commit comments

Comments
 (0)