diff --git a/bin/setupVScodeFOAM b/bin/setupVScodeFOAM new file mode 100755 index 0000000000..02fc0fd96d --- /dev/null +++ b/bin/setupVScodeFOAM @@ -0,0 +1,80 @@ +#!/bin/python3 +#------------------------------------------------------------------------------ +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | www.openfoam.com +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# Copyright (C) 2011-2016 OpenFOAM Foundation +# Copyright (C) 2017-2020 OpenCFD Ltd. +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM. +# +# OpenFOAM is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with OpenFOAM. If not, see . +# +# Script +# setupVScode +# +# Description +# Sets up Visual Studio Code for use with OpenFOAM by writing correct +# settings into .vscode/.settings . +# You can see the settings that we set in the good_settings variable below. +# +#------------------------------------------------------------------------------ +import os +import sys +import json + +print("Take a look at https://openfoamwiki.net/index.php/HowTo_Use_OpenFOAM_with_Visual_Studio_Code for more information.") + +assert len(sys.argv) == 1 + +assert "FOAM_LIBBIN" in os.environ, os.path.basename(sys.argv[0]) + " error: environment variable FOAM_LIBBIN not set" + +if not os.path.exists(".vscode"): + os.mkdir(".vscode") +assert os.path.isdir(".vscode"), "The path .vscode already exists and it is not a directory." + +if os.path.exists(".vscode/settings.json"): + assert os.path.isfile(".vscode/settings.json"), ".vscode/settings.json is not a file." + try: + settings = json.load(open(".vscode/settings.json", "r")) + except json.decoder.JSONDecodeError as exc: + print(exc) + print(".vscode/settings.json is not a valid json file (see exception above). Remove or fix this file then run setupVSCode again.") + sys.exit(1) +else: + settings = json.loads("{}") + +good_settings = json.loads("{}") +good_settings["ccls.cache.directory"] = os.path.join(os.environ["FOAM_LIBBIN"], "..", "ccls-cache") +good_settings["ccls.misc.compilationDatabaseDirectory"] = os.path.join(os.getenv("FOAM_LIBBIN"), "..") +good_settings["C_Cpp.autocomplete"] = "Disabled" +good_settings["C_Cpp.formatting"] = "Disabled" +good_settings["C_Cpp.errorSquiggles"] = "Disabled" +good_settings["C_Cpp.intelliSenseEngine"] = "Disabled" + +settings_already_good = True +for el in good_settings: + if el not in settings or settings[el] != good_settings[el]: + settings_already_good = False + settings[el] = good_settings[el] + +if settings_already_good: + print("The vs-code settings for this folder are already set correctly.") +else: + json.dump(settings, open(".vscode/settings.json", "w"), indent=4, sort_keys=False) + print("The vs-code settings for this folder are now set correctly.") diff --git a/wmake/wmake b/wmake/wmake index 572fea8256..f913545b40 100755 --- a/wmake/wmake +++ b/wmake/wmake @@ -367,6 +367,17 @@ then fi +#------------------------------------------------------------------------------ +# check if bear is installed and we are not already running under bear +#------------------------------------------------------------------------------ + +if bear --version > /dev/null && [ -z "${INTERCEPT_REPORT_COMMAND}" ] ; then + mkdir -p $FOAM_LIBBIN + bear --append --output $FOAM_LIBBIN/../compile_commands.json -- wmake $@ + exit $? +fi + + #------------------------------------------------------------------------------ # Setup parallel compilation #------------------------------------------------------------------------------