@@ -30,12 +30,16 @@ import (
3030
3131var globalCliPath string
3232var globalClangdPath string
33+ var globalFormatterConf * paths.Path
3334var enableLogging bool
3435
3536// Setup initializes global variables.
36- func Setup (cliPath string , clangdPath string , _enableLogging bool ) {
37+ func Setup (cliPath string , clangdPath string , formatFilePath string , _enableLogging bool ) {
3738 globalCliPath = cliPath
3839 globalClangdPath = clangdPath
40+ if formatFilePath != "" {
41+ globalFormatterConf = paths .New (formatFilePath )
42+ }
3943 enableLogging = _enableLogging
4044}
4145
@@ -1769,15 +1773,22 @@ func (handler *InoHandler) createClangdFormatterConfig(cppuri lsp.DocumentURI) (
17691773AllowShortFunctionsOnASingleLine: None
17701774`
17711775
1772- // If a custom config is present in the sketch folder, use that one
1773- customConfigFile := handler .sketchRoot .Join (".clang-format" )
1774- if customConfigFile .Exist () {
1775- if c , err := customConfigFile .ReadFile (); err != nil {
1776- log .Printf (" error reading custom formatter config file %s: %s" , customConfigFile , err )
1776+ try := func (conf * paths.Path ) bool {
1777+ if c , err := conf .ReadFile (); err != nil {
1778+ log .Printf (" error reading custom formatter config file %s: %s" , conf , err )
17771779 } else {
1778- log .Printf (" using custom formatter config file %s" , customConfigFile )
1780+ log .Printf (" using custom formatter config file %s" , conf )
17791781 config = string (c )
17801782 }
1783+ return true
1784+ }
1785+
1786+ if sketchFormatterConf := handler .sketchRoot .Join (".clang-format" ); sketchFormatterConf .Exist () {
1787+ // If a custom config is present in the sketch folder, use that one
1788+ try (sketchFormatterConf )
1789+ } else if globalFormatterConf != nil && globalFormatterConf .Exist () {
1790+ // Otherwise if a global config file is present, use that one
1791+ try (globalFormatterConf )
17811792 }
17821793
17831794 targetFile := cppuri .AsPath ()
0 commit comments