Skip to content

Commit 9061344

Browse files
kovapatrikShikachuu
authored andcommitted
feat: watching changed on configuration file
Co-Authored-By: Czékus Máté <[email protected]>
1 parent 3555616 commit 9061344

File tree

4 files changed

+105
-4
lines changed

4 files changed

+105
-4
lines changed

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
vendor/
19+
20+
# Go workspace file
21+
go.work
22+
go.work.sum
23+
24+
# env file
25+
.env
26+
27+
/bin

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/dop251/goja v0.0.0-20240828124009-016eb7256539
88
github.com/dop251/goja_nodejs v0.0.0-20240728170619-29b559befffc
99
github.com/dustin/go-humanize v1.0.1
10+
github.com/fsnotify/fsnotify v1.7.0
1011
github.com/ghodss/yaml v1.0.0
1112
github.com/gizak/termui/v3 v3.1.0
1213
github.com/json-iterator/go v1.1.12
@@ -38,7 +39,6 @@ require (
3839
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3940
github.com/dlclark/regexp2 v1.11.4 // indirect
4041
github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097 // indirect
41-
github.com/fsnotify/fsnotify v1.7.0 // indirect
4242
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
4343
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
4444
github.com/google/uuid v1.6.0 // indirect

language-server/config.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package languageserver
2+
3+
import (
4+
"os"
5+
6+
"github.com/daveshanley/vacuum/plugin"
7+
"github.com/daveshanley/vacuum/rulesets"
8+
"github.com/fsnotify/fsnotify"
9+
"github.com/spf13/viper"
10+
)
11+
12+
func (s *ServerState) onConfigChange(e fsnotify.Event) {
13+
14+
// extract flags
15+
rulesetFlag := viper.GetString("ruleset")
16+
functionsFlag := viper.GetString("functions")
17+
baseFlag := viper.GetString("base")
18+
skipCheckFlag := viper.GetBool("skip-check")
19+
remoteFlag := viper.GetBool("remote")
20+
timeoutFlag := viper.GetInt("timeout")
21+
hardModeFlag := viper.GetBool("hard-mode")
22+
ignoreArrayCircleRef := viper.GetBool("ignore-array-circle-ref")
23+
ignorePolymorphCircleRef := viper.GetBool("ignore-array-circle-ref")
24+
25+
defaultRuleSets := rulesets.BuildDefaultRuleSetsWithLogger(s.lintRequest.Logger)
26+
selectedRS := defaultRuleSets.GenerateOpenAPIRecommendedRuleSet()
27+
functions := s.lintRequest.Functions
28+
29+
// FUNCTIONS
30+
if functionsFlag != "" {
31+
pm, err := plugin.LoadFunctions(functionsFlag, true)
32+
if err == nil {
33+
functions = pm.GetCustomFunctions()
34+
}
35+
}
36+
37+
// HARD MODE
38+
if hardModeFlag {
39+
selectedRS = defaultRuleSets.GenerateOpenAPIDefaultRuleSet()
40+
41+
// extract all OWASP Rules
42+
owaspRules := rulesets.GetAllOWASPRules()
43+
allRules := selectedRS.Rules
44+
for k, v := range owaspRules {
45+
allRules[k] = v
46+
}
47+
}
48+
49+
// RULESET
50+
if rulesetFlag != "" {
51+
rsBytes, rsErr := os.ReadFile(rulesetFlag)
52+
if rsErr == nil {
53+
// load in our user supplied ruleset and try to validate it.
54+
userRS, userErr := rulesets.CreateRuleSetFromData(rsBytes)
55+
if userErr == nil {
56+
selectedRS = defaultRuleSets.GenerateRuleSetFromSuppliedRuleSet(userRS)
57+
}
58+
}
59+
}
60+
61+
s.lintRequest.BaseFlag = baseFlag
62+
s.lintRequest.Remote = remoteFlag
63+
s.lintRequest.SkipCheckFlag = skipCheckFlag
64+
s.lintRequest.DefaultRuleSets = defaultRuleSets
65+
s.lintRequest.SelectedRS = selectedRS
66+
s.lintRequest.Functions = functions
67+
s.lintRequest.TimeoutFlag = timeoutFlag
68+
s.lintRequest.IgnoreArrayCircleRef = ignoreArrayCircleRef
69+
s.lintRequest.IgnorePolymorphCircleRef = ignorePolymorphCircleRef
70+
}

language-server/server.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ package languageserver
1717

1818
import (
1919
"fmt"
20+
"path/filepath"
21+
"strings"
22+
"time"
23+
2024
"github.com/daveshanley/vacuum/model"
2125
"github.com/daveshanley/vacuum/motor"
2226
"github.com/daveshanley/vacuum/utils"
27+
"github.com/spf13/viper"
2328
"github.com/tliron/glsp"
2429
protocol "github.com/tliron/glsp/protocol_3_16"
2530
glspserv "github.com/tliron/glsp/server"
26-
"path/filepath"
27-
"strings"
28-
"time"
2931
)
3032

3133
var serverName = "vacuum"
@@ -101,6 +103,8 @@ func NewServer(version string, lintRequest *utils.LintFileRequest) *ServerState
101103
}
102104

103105
func (s *ServerState) Run() error {
106+
viper.OnConfigChange(s.onConfigChange)
107+
viper.WatchConfig()
104108
return s.server.RunStdio()
105109
}
106110

0 commit comments

Comments
 (0)