From fe1dc3aca5adc1fd516dbc83b12568d885287227 Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Thu, 11 Apr 2024 12:20:45 +0100 Subject: [PATCH] lsp: Enable formatting functionality (#643) In https://github.com/StyraInc/regal/pull/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: https://github.com/StyraInc/regal/issues/638#issuecomment-2048459623 In https://github.com/open-policy-agent/vscode-opa/pull/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 --- internal/lsp/messages.go | 2 +- internal/lsp/server.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/lsp/messages.go b/internal/lsp/messages.go index 648a0b6a..eb33087f 100644 --- a/internal/lsp/messages.go +++ b/internal/lsp/messages.go @@ -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 { diff --git a/internal/lsp/server.go b/internal/lsp/server.go index 833ab5a0..b42c4c73 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -570,7 +570,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) @@ -764,7 +764,7 @@ func (l *LanguageServer) handleInitialize( ExecuteCommandProvider: ExecuteCommandOptions{ Commands: []string{"regal.fmt", "regal.fmt.v1"}, }, - DocumentFormattingProvider: false, + DocumentFormattingProvider: true, }, }