@@ -30,12 +30,16 @@ import (
30
30
31
31
var globalCliPath string
32
32
var globalClangdPath string
33
+ var globalFormatterConf * paths.Path
33
34
var enableLogging bool
34
35
35
36
// Setup initializes global variables.
36
- func Setup (cliPath string , clangdPath string , _enableLogging bool ) {
37
+ func Setup (cliPath string , clangdPath string , formatFilePath string , _enableLogging bool ) {
37
38
globalCliPath = cliPath
38
39
globalClangdPath = clangdPath
40
+ if formatFilePath != "" {
41
+ globalFormatterConf = paths .New (formatFilePath )
42
+ }
39
43
enableLogging = _enableLogging
40
44
}
41
45
@@ -1769,15 +1773,22 @@ func (handler *InoHandler) createClangdFormatterConfig(cppuri lsp.DocumentURI) (
1769
1773
AllowShortFunctionsOnASingleLine: None
1770
1774
`
1771
1775
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 )
1777
1779
} else {
1778
- log .Printf (" using custom formatter config file %s" , customConfigFile )
1780
+ log .Printf (" using custom formatter config file %s" , conf )
1779
1781
config = string (c )
1780
1782
}
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 )
1781
1792
}
1782
1793
1783
1794
targetFile := cppuri .AsPath ()
0 commit comments