Bug 1799258 - span_iterator::difference_type s/index_type/ptrdiff/. r=bradwerth
[gecko.git] / .ycm_extra_conf.py
blob46e1387ec9fb87cc4ef7fb12ab9a3d4779be5f55
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 import json
6 import os
7 import shlex
8 import subprocess
9 import sys
11 old_bytecode = sys.dont_write_bytecode
12 sys.dont_write_bytecode = True
14 path = os.path.abspath(os.path.join(os.path.dirname(__file__), "mach"))
16 # If mach is not here, we're on the objdir go to the srcdir.
17 if not os.path.exists(path):
18 with open(os.path.join(os.path.dirname(__file__), "mozinfo.json")) as info:
19 config = json.loads(info.read())
20 path = os.path.join(config["topsrcdir"], "mach")
22 sys.dont_write_bytecode = old_bytecode
25 def _is_likely_cpp_header(filename):
26 if not filename.endswith(".h"):
27 return False
29 if filename.endswith("Inlines.h") or filename.endswith("-inl.h"):
30 return True
32 cpp_file = filename[:-1] + "cpp"
33 return os.path.exists(cpp_file)
36 def Settings(**kwargs):
37 if kwargs["language"] == "cfamily":
38 return FlagsForFile(kwargs["filename"])
39 # This is useful for generic language server protocols, like rust-analyzer,
40 # to discover the right project root instead of guessing based on where the
41 # closest Cargo.toml is.
42 return {
43 "project_directory": ".",
47 def FlagsForFile(filename):
48 output = subprocess.check_output([path, "compileflags", filename])
49 output = output.decode("utf-8")
51 flag_list = shlex.split(output)
53 # This flag is added by Fennec for android build and causes ycmd to fail to parse the file.
54 # Removing this flag is a workaround until ycmd starts to handle this flag properly.
55 # https://github.com/Valloric/YouCompleteMe/issues/1490
56 final_flags = [x for x in flag_list if not x.startswith("-march=armv")]
58 if _is_likely_cpp_header(filename):
59 final_flags += ["-x", "c++"]
61 return {"flags": final_flags, "do_cache": True}
64 if __name__ == "__main__":
65 print(FlagsForFile(sys.argv[1]))