Skip to content

Commit

Permalink
add add lint-after-open
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Mar 18, 2024
1 parent c1cc75e commit 5f95685
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions langserver/handle_text_document_formatting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestFormattingRequireRootMatcher(t *testing.T) {
{
LintCommand: `echo ` + file + `:2:No it is normal!`,
LintIgnoreExitCode: true,
LintAfterOpen: true,
LintStdin: true,
RequireMarker: true,
RootMarkers: []string{".vimlintrc"},
Expand Down
16 changes: 13 additions & 3 deletions langserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type Language struct {
LintSource string `yaml:"lint-source" json:"lintSource"`
LintSeverity int `yaml:"lint-severity" json:"lintSeverity"`
LintWorkspace bool `yaml:"lint-workspace" json:"lintWorkspace"`
LintAfterOpen bool `yaml:"lint-after-open" json:"lintAfterOpen"`
LintOnSave bool `yaml:"lint-on-save" json:"lintOnSave"`
FormatCommand string `yaml:"format-command" json:"formatCommand"`
FormatCanRange bool `yaml:"format-can-range" json:"formatCanRange"`
Expand Down Expand Up @@ -374,9 +375,18 @@ func (h *langHandler) lint(ctx context.Context, uri DocumentURI, eventType event
if dir := matchRootPath(fname, cfg.RootMarkers); dir == "" && cfg.RequireMarker == true {
continue
}
// if LintOnSave is true, only lint when running on didSave
if cfg.LintOnSave && eventType != eventTypeSave {
continue
switch eventType {
case eventTypeOpen:
// if LintAfterOpen is not true, ignore didOpen
if !cfg.LintAfterOpen {
continue
}
case eventTypeChange:
// if LintOnSave is true, ignore didChange
if cfg.LintOnSave {
continue
}
default:
}
if cfg.LintCommand != "" {
configs = append(configs, cfg)
Expand Down
5 changes: 5 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
"description": "offset value to skip lines",
"type": "number"
},
"lint-after-open": {
"default": true,
"description": "lint after open",
"type": "boolean"
},
"lint-on-save": {
"description": "only lint on save, i.e. don't lint on text changed",
"type": "boolean"
Expand Down

0 comments on commit 5f95685

Please sign in to comment.