From 5f956853b1ad7c9457faf059555b8021f26539af Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 18 Mar 2024 22:52:25 +0900 Subject: [PATCH] add add lint-after-open --- .../handle_text_document_formatting_test.go | 1 + langserver/handler.go | 16 +++++++++++++--- schema.json | 5 +++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/langserver/handle_text_document_formatting_test.go b/langserver/handle_text_document_formatting_test.go index b00dc26..ae687d2 100644 --- a/langserver/handle_text_document_formatting_test.go +++ b/langserver/handle_text_document_formatting_test.go @@ -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"}, diff --git a/langserver/handler.go b/langserver/handler.go index 35a6374..1c861b5 100644 --- a/langserver/handler.go +++ b/langserver/handler.go @@ -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"` @@ -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) diff --git a/schema.json b/schema.json index 0d3422b..d5c4aba 100644 --- a/schema.json +++ b/schema.json @@ -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"