#!/bin/sh #------------------------------------------------------------------------------ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | www.openfoam.com # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2020 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. # # Script # bin/tools/vscode-settings # # Description # Emit some settings for Visual Studio Code + OpenFOAM # # Example # bin/tools/vscode-settings > .vscode/settings.json # etc/openfoam -spdp -int64 bin/tools/vscode-settings # # Environment # WM_PROJECT_DIR, WM_PROJECT_USER_DIR, WM_OPTIONS # # More information: # https://openfoamwiki.net/index.php/HowTo_Use_OpenFOAM_with_Visual_Studio_Code # #------------------------------------------------------------------------------ # Values consistent with wmake-with-bear cacheDirName="build/$WM_OPTIONS" printHelp() { cat< .vscode/settings.json etc/openfoam -spdp -int64 bin/tools/vscode-settings USAGE exit 0 # clean exit } #------------------------------------------------------------------------------ unset outputDir # Parse options while [ "$#" -gt 0 ] do case "$1" in -h | -help*) printHelp ;; *) echo "Unknown option/argument: '$1'" 1>&2 break ;; esac shift done #------------------------------------------------------------------------------ # Report settings and flag errors projectDir="$WM_PROJECT_DIR" session="$projectDir"/etc/openfoam echo "project: ${WM_PROJECT_DIR:?OpenFOAM environment not set?}" 1>&2 echo "options: ${WM_OPTIONS:?not set}" 1>&2 if [ -x "$session" ] then echo "session: $session" 1>&2 else echo "No session: $session" 1>&2 fi if [ -z "$outputDir" ] then prefixDir="$projectDir" if ! [ -w "$prefixDir" ] then echo "Non-writable directory: $prefixDir" 1>&2 echo "Try with user location" 1>&2 prefixDir="$WM_PROJECT_USER_DIR" if ! [ -w "$prefixDir" ] then echo "Non-writable directory: $prefixDir" 1>&2 echo "Using home directory" 1>&2 prefixDir="$HOME" fi fi outputDir="$prefixDir/$cacheDirName" fi ## echo "Output = $outputDir" 1>&2 # JSON output. Long entries are outdented. cat << INFO 1>&2 # ------------------------- # Some settings for Visual Studio Code + OpenFOAM # ------------------------- INFO echo '{' # BEGIN_LIST # ccls integration cat << JSON_CONTENT "ccls.cache.directory": "$outputDir/ccls-cache", "ccls.misc.compilationDatabaseDirectory": "$outputDir", JSON_CONTENT # Compilation via openfoam session if [ -x "$session" ] then cat << JSON_CONTENT "C_Cpp.default.compileCommands": "$session wmake -with-bear -s -j", JSON_CONTENT fi cat << JSON_CONTENT "C_Cpp.autocomplete": "Disabled", "C_Cpp.errorSquiggles": "Disabled", "C_Cpp.formatting": "Disabled", "C_Cpp.intelliSenseEngine": "Disabled" JSON_CONTENT echo '}' # END_LIST #------------------------------------------------------------------------------