.ycm_extra_conf.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Based on the example .ycm_extra_conf.py from YouCompleteMe, adapted
  2. # for SerenityOS.
  3. #
  4. # This file is NOT licensed under the GPLv3, which is the license for the rest
  5. # of YouCompleteMe.
  6. #
  7. # Here's the license text for this file:
  8. #
  9. # This is free and unencumbered software released into the public domain.
  10. #
  11. # Anyone is free to copy, modify, publish, use, compile, sell, or
  12. # distribute this software, either in source code form or as a compiled
  13. # binary, for any purpose, commercial or non-commercial, and by any
  14. # means.
  15. #
  16. # In jurisdictions that recognize copyright laws, the author or authors
  17. # of this software dedicate any and all copyright interest in the
  18. # software to the public domain. We make this dedication for the benefit
  19. # of the public at large and to the detriment of our heirs and
  20. # successors. We intend this dedication to be an overt act of
  21. # relinquishment in perpetuity of all present and future rights to this
  22. # software under copyright law.
  23. #
  24. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  27. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  28. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  29. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  30. # OTHER DEALINGS IN THE SOFTWARE.
  31. #
  32. # For more information, please refer to <http://unlicense.org/>
  33. import os
  34. import ycm_core
  35. DIR_OF_THIS_SCRIPT = os.path.abspath(os.path.dirname(__file__))
  36. SOURCE_EXTENSIONS = ['.cpp', '.c']
  37. database = ycm_core.CompilationDatabase(os.path.join(DIR_OF_THIS_SCRIPT, 'Build/ladybird'))
  38. def is_header_file(filename):
  39. extension = os.path.splitext(filename)[1]
  40. return extension in ['.h', '.hxx', '.hpp', '.hh']
  41. def find_corresponding_source_file(filename):
  42. if is_header_file(filename):
  43. basename = os.path.splitext(filename)[0]
  44. for extension in SOURCE_EXTENSIONS:
  45. replacement_file = basename + extension
  46. if os.path.exists(replacement_file):
  47. return replacement_file
  48. return filename
  49. def Settings(**kwargs): # noqa: N802
  50. if kwargs['language'] != 'cfamily':
  51. return {}
  52. # If the file is a header, try to find the corresponding source file and
  53. # retrieve its flags from the compilation database if using one. This is
  54. # necessary since compilation databases don't have entries for header files.
  55. # In addition, use this source file as the translation unit. This makes it
  56. # possible to jump from a declaration in the header file to its definition
  57. # in the corresponding source file.
  58. filename = find_corresponding_source_file(kwargs['filename'])
  59. compilation_info = database.GetCompilationInfoForFile(filename)
  60. if not compilation_info.compiler_flags_:
  61. return {}
  62. return {
  63. 'flags': list(compilation_info.compiler_flags_),
  64. 'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT,
  65. 'override_filename': filename
  66. }