From 5658f888b308fcf8b34b296b5434c71e003ef5b0 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Wed, 8 May 2019 17:44:01 +0800 Subject: [PATCH] internal/lsp: disable rangeFormatting temporarily RangeFormatting was broken with the introduction of the diff library, but not noticed until golang/go#31150. Temporarily disable this behavior until we fix it. Change-Id: Ie3e50a763e0c0e8672ad20c3a2e37d901325d356 Reviewed-on: https://go-review.googlesource.com/c/tools/+/175938 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Ian Cottrell --- internal/lsp/cmd/format.go | 10 ++++++---- internal/lsp/format.go | 14 -------------- internal/lsp/general.go | 13 ++++++------- internal/lsp/server.go | 2 +- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/internal/lsp/cmd/format.go b/internal/lsp/cmd/format.go index 79403b08..32f64688 100644 --- a/internal/lsp/cmd/format.go +++ b/internal/lsp/cmd/format.go @@ -67,11 +67,13 @@ func (f *format) Run(ctx context.Context, args ...string) error { if err != nil { return err } - p := protocol.DocumentRangeFormattingParams{ - TextDocument: protocol.TextDocumentIdentifier{URI: loc.URI}, - Range: loc.Range, + if loc.Range.Start != loc.Range.End { + return fmt.Errorf("only full file formatting supported") } - edits, err := server.RangeFormatting(ctx, &p) + p := protocol.DocumentFormattingParams{ + TextDocument: protocol.TextDocumentIdentifier{URI: loc.URI}, + } + edits, err := server.Formatting(ctx, &p) if err != nil { return fmt.Errorf("%v: %v", spn, err) } diff --git a/internal/lsp/format.go b/internal/lsp/format.go index 409d048a..f591ae1b 100644 --- a/internal/lsp/format.go +++ b/internal/lsp/format.go @@ -20,20 +20,6 @@ func (s *Server) formatting(ctx context.Context, params *protocol.DocumentFormat return formatRange(ctx, view, spn) } -func (s *Server) rangeFormatting(ctx context.Context, params *protocol.DocumentRangeFormattingParams) ([]protocol.TextEdit, error) { - uri := span.NewURI(params.TextDocument.URI) - view := s.findView(ctx, uri) - _, m, err := newColumnMap(ctx, view, uri) - if err != nil { - return nil, err - } - spn, err := m.RangeSpan(params.Range) - if err != nil { - return nil, err - } - return formatRange(ctx, view, spn) -} - // formatRange formats a document with a given range. func formatRange(ctx context.Context, v source.View, s span.Span) ([]protocol.TextEdit, error) { f, m, err := newColumnMap(ctx, v, s.URI()) diff --git a/internal/lsp/general.go b/internal/lsp/general.go index ade4cf54..0f8f663e 100644 --- a/internal/lsp/general.go +++ b/internal/lsp/general.go @@ -78,13 +78,12 @@ func (s *Server) initialize(ctx context.Context, params *protocol.InitializePara CompletionProvider: &protocol.CompletionOptions{ TriggerCharacters: []string{"."}, }, - DefinitionProvider: true, - DocumentFormattingProvider: true, - DocumentRangeFormattingProvider: true, - DocumentSymbolProvider: true, - HoverProvider: true, - DocumentHighlightProvider: true, - DocumentLinkProvider: &protocol.DocumentLinkOptions{}, + DefinitionProvider: true, + DocumentFormattingProvider: true, + DocumentSymbolProvider: true, + HoverProvider: true, + DocumentHighlightProvider: true, + DocumentLinkProvider: &protocol.DocumentLinkOptions{}, SignatureHelpProvider: &protocol.SignatureHelpOptions{ TriggerCharacters: []string{"(", ","}, }, diff --git a/internal/lsp/server.go b/internal/lsp/server.go index d94bd934..71a3d489 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -231,7 +231,7 @@ func (s *Server) Formatting(ctx context.Context, params *protocol.DocumentFormat } func (s *Server) RangeFormatting(ctx context.Context, params *protocol.DocumentRangeFormattingParams) ([]protocol.TextEdit, error) { - return s.rangeFormatting(ctx, params) + return nil, notImplemented("RangeFormatting") } func (s *Server) OnTypeFormatting(context.Context, *protocol.DocumentOnTypeFormattingParams) ([]protocol.TextEdit, error) {