Skip to content

Commit

Permalink
lsp: Enable formatting functionality
Browse files Browse the repository at this point in the history
In #641 support was added to
handle textDocument/formatting requests from clients. However, the
functionality was disabled for fear that users would see a confusing
message:

#638 (comment)

In open-policy-agent/vscode-opa#148 the regal
formatter will be used if the user has enabled regal and opa fmt will be
used if not. This means that there is only ever one formatter available
for rego and the user will see no message.

Signed-off-by: Charlie Egan <charlie@styra.com>
  • Loading branch information
charlieegan3 committed Apr 11, 2024
1 parent 8de5461 commit 9f21105
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/lsp/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ type FormattingOptions struct {
InsertSpaces bool `json:"insertSpaces"`
TrimTrailingWhitespace bool `json:"trimTrailingWhitespace"`
InsertFinalNewline bool `json:"insertFinalNewline"`
TrimFinalNewlines bool `json:"trimFinalNewline"`
TrimFinalNewlines bool `json:"trimFinalNewlines"`
}

type FileOperationsServerCapabilities struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func (l *LanguageServer) handleTextDocumentFormatting(
}

if warnings := validateFormattingOptions(params.Options); len(warnings) > 0 {
fmt.Fprintf(os.Stderr, "formatting params validation warnings: %v", warnings)
fmt.Fprintf(l.errorLog, "formatting params validation warnings: %v\n", warnings)
}

oldContent, ok := l.cache.GetFileContents(params.TextDocument.URI)
Expand Down Expand Up @@ -759,7 +759,7 @@ func (l *LanguageServer) handleInitialize(
ExecuteCommandProvider: ExecuteCommandOptions{
Commands: []string{"regal.fmt", "regal.fmt.v1"},
},
DocumentFormattingProvider: false,
DocumentFormattingProvider: true,
},
}

Expand Down

0 comments on commit 9f21105

Please sign in to comment.