Skip to content

Commit

Permalink
Merge pull request #214 from fsouza/rootMarker-improvements
Browse files Browse the repository at this point in the history
Support skipping textDocument/formatting with requireMarker too
  • Loading branch information
mattn authored Apr 20, 2022
2 parents 4fabe41 + 8ce08c3 commit 3b011bc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions langserver/handle_text_document_formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (h *langHandler) formatting(uri DocumentURI, options FormattingOptions) ([]
if cfgs, ok := h.configs[f.LanguageID]; ok {
for _, cfg := range cfgs {
if cfg.FormatCommand != "" {
if dir := matchRootPath(fname, cfg.RootMarkers); dir == "" && cfg.RequireMarker {
continue
}
configs = append(configs, cfg)
}
}
Expand Down
44 changes: 44 additions & 0 deletions langserver/handle_text_document_formatting_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package langserver

import (
"log"
"os"
"path/filepath"
"testing"
)

func TestFormattingRequireRootMatcher(t *testing.T) {
base, _ := os.Getwd()
file := filepath.Join(base, "foo")
uri := toURI(file)

h := &langHandler{
logger: log.New(log.Writer(), "", log.LstdFlags),
rootPath: base,
configs: map[string][]Language{
"vim": {
{
LintCommand: `echo ` + file + `:2:No it is normal!`,
LintIgnoreExitCode: true,
LintStdin: true,
RequireMarker: true,
RootMarkers: []string{".vimlintrc"},
},
},
},
files: map[DocumentURI]*File{
uri: {
LanguageID: "vim",
Text: "scriptencoding utf-8\nabnormal!\n",
},
},
}

d, err := h.formatRequest(uri, FormattingOptions{})
if err != nil {
t.Fatal(err)
}
if len(d) != 0 {
t.Fatal("text edits should be zero as we have no root marker for the language but require one", d)
}
}

0 comments on commit 3b011bc

Please sign in to comment.