Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format-ignore-exit-code configuration #285

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion langserver/handle_text_document_formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ Configs:
var buf bytes.Buffer
cmd.Stderr = &buf
b, err := cmd.Output()
if err != nil {

// Most format tools exit with zero status code when formatting is successful.
// Some do not.
// To handle a formatter that exits with non-zero value, use format-ignore-exit-code.
if err != nil && !config.FormatIgnoreExitCode {
h.logger.Println(command+":", buf.String())
continue
}
Expand Down
59 changes: 30 additions & 29 deletions langserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,36 @@ type Config1 struct {

// Language is
type Language struct {
Prefix string `yaml:"prefix" json:"prefix"`
LintFormats []string `yaml:"lint-formats" json:"lintFormats"`
LintStdin bool `yaml:"lint-stdin" json:"lintStdin"`
LintOffset int `yaml:"lint-offset" json:"lintOffset"`
LintOffsetColumns int `yaml:"lint-offset-columns" json:"lintOffsetColumns"`
LintCommand string `yaml:"lint-command" json:"lintCommand"`
LintIgnoreExitCode bool `yaml:"lint-ignore-exit-code" json:"lintIgnoreExitCode"`
LintCategoryMap map[string]string `yaml:"lint-category-map" json:"lintCategoryMap"`
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"`
FormatStdin bool `yaml:"format-stdin" json:"formatStdin"`
SymbolCommand string `yaml:"symbol-command" json:"symbolCommand"`
SymbolStdin bool `yaml:"symbol-stdin" json:"symbolStdin"`
SymbolFormats []string `yaml:"symbol-formats" json:"symbolFormats"`
CompletionCommand string `yaml:"completion-command" json:"completionCommand"`
CompletionStdin bool `yaml:"completion-stdin" json:"completionStdin"`
HoverCommand string `yaml:"hover-command" json:"hoverCommand"`
HoverStdin bool `yaml:"hover-stdin" json:"hoverStdin"`
HoverType string `yaml:"hover-type" json:"hoverType"`
HoverChars string `yaml:"hover-chars" json:"hoverChars"`
Env []string `yaml:"env" json:"env"`
RootMarkers []string `yaml:"root-markers" json:"rootMarkers"`
RequireMarker bool `yaml:"require-marker" json:"requireMarker"`
Commands []Command `yaml:"commands" json:"commands"`
Prefix string `yaml:"prefix" json:"prefix"`
LintFormats []string `yaml:"lint-formats" json:"lintFormats"`
LintStdin bool `yaml:"lint-stdin" json:"lintStdin"`
LintOffset int `yaml:"lint-offset" json:"lintOffset"`
LintOffsetColumns int `yaml:"lint-offset-columns" json:"lintOffsetColumns"`
LintCommand string `yaml:"lint-command" json:"lintCommand"`
LintIgnoreExitCode bool `yaml:"lint-ignore-exit-code" json:"lintIgnoreExitCode"`
LintCategoryMap map[string]string `yaml:"lint-category-map" json:"lintCategoryMap"`
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"`
FormatIgnoreExitCode bool `yaml:"format-ignore-exit-code" json:"formatIgnoreExitCode"`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a big whitespace diff here, but only this line was changed.

FormatStdin bool `yaml:"format-stdin" json:"formatStdin"`
SymbolCommand string `yaml:"symbol-command" json:"symbolCommand"`
SymbolStdin bool `yaml:"symbol-stdin" json:"symbolStdin"`
SymbolFormats []string `yaml:"symbol-formats" json:"symbolFormats"`
CompletionCommand string `yaml:"completion-command" json:"completionCommand"`
CompletionStdin bool `yaml:"completion-stdin" json:"completionStdin"`
HoverCommand string `yaml:"hover-command" json:"hoverCommand"`
HoverStdin bool `yaml:"hover-stdin" json:"hoverStdin"`
HoverType string `yaml:"hover-type" json:"hoverType"`
HoverChars string `yaml:"hover-chars" json:"hoverChars"`
Env []string `yaml:"env" json:"env"`
RootMarkers []string `yaml:"root-markers" json:"rootMarkers"`
RequireMarker bool `yaml:"require-marker" json:"requireMarker"`
Commands []Command `yaml:"commands" json:"commands"`
}

// NewHandler create JSON-RPC handler for this language server.
Expand Down
5 changes: 5 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
"description": "Formatting command. Input filename can be injected using `${INPUT}`, and flags can be injected using `${--flag:key}` (adds `--flag <value>` if value exists for key), `${--flag=key}` (adds `--flag=<value>` if value exists for key), or `${--flag:!key}` (adds `--flag` if value for key is falsy).\n\n`efm-langserver` may provide values for keys `charStart`, `charEnd`, `rowStart`, `rowEnd`, `colStart`, `colEnd`, or any key in [`interface FormattingOptions`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#formattingOptions).\n\nExample: `prettier --stdin --stdin-filepath ${INPUT} ${--tab-width:tabWidth} ${--use-tabs:insertSpaces} ${--range-start=charStart} ${--range-start=charEnd}`",
"type": "string"
},
"format-ignore-exit-code": {
"default": false,
"description": "ignore exit code of format",
"type": "boolean"
},
"format-stdin": {
"description": "use stdin for the format",
"type": "boolean"
Expand Down
Loading