Skip to content

Commit 8ce08c3

Browse files
committed
Support skipping textDocument/formatting with requireMarker too
Closes #213.
1 parent ce8317f commit 8ce08c3

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

langserver/handle_text_document_formatting.go

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func (h *langHandler) formatting(uri DocumentURI, options FormattingOptions) ([]
6262
if cfgs, ok := h.configs[f.LanguageID]; ok {
6363
for _, cfg := range cfgs {
6464
if cfg.FormatCommand != "" {
65+
if dir := matchRootPath(fname, cfg.RootMarkers); dir == "" && cfg.RequireMarker {
66+
continue
67+
}
6568
configs = append(configs, cfg)
6669
}
6770
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package langserver
2+
3+
import (
4+
"log"
5+
"os"
6+
"path/filepath"
7+
"testing"
8+
)
9+
10+
func TestFormattingRequireRootMatcher(t *testing.T) {
11+
base, _ := os.Getwd()
12+
file := filepath.Join(base, "foo")
13+
uri := toURI(file)
14+
15+
h := &langHandler{
16+
logger: log.New(log.Writer(), "", log.LstdFlags),
17+
rootPath: base,
18+
configs: map[string][]Language{
19+
"vim": {
20+
{
21+
LintCommand: `echo ` + file + `:2:No it is normal!`,
22+
LintIgnoreExitCode: true,
23+
LintStdin: true,
24+
RequireMarker: true,
25+
RootMarkers: []string{".vimlintrc"},
26+
},
27+
},
28+
},
29+
files: map[DocumentURI]*File{
30+
uri: {
31+
LanguageID: "vim",
32+
Text: "scriptencoding utf-8\nabnormal!\n",
33+
},
34+
},
35+
}
36+
37+
d, err := h.formatRequest(uri, FormattingOptions{})
38+
if err != nil {
39+
t.Fatal(err)
40+
}
41+
if len(d) != 0 {
42+
t.Fatal("text edits should be zero as we have no root marker for the language but require one", d)
43+
}
44+
}

0 commit comments

Comments
 (0)