1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package server
import (
"context"
"cuelang.org/go/internal/golangorgx/gopls/cuelang"
"cuelang.org/go/internal/golangorgx/gopls/file"
"cuelang.org/go/internal/golangorgx/gopls/protocol"
"cuelang.org/go/internal/golangorgx/tools/event"
"cuelang.org/go/internal/golangorgx/tools/event/tag"
)
func (s *server) Formatting(ctx context.Context, params *protocol.DocumentFormattingParams) ([]protocol.TextEdit, error) {
ctx, done := event.Start(ctx, "lsp.Server.formatting", tag.URI.Of(params.TextDocument.URI))
defer done()
fh, snapshot, release, err := s.fileOf(ctx, params.TextDocument.URI)
if err != nil {
return nil, err
}
defer release()
switch snapshot.FileKind(fh) {
case file.CUE:
return cuelang.FormatCUE(ctx, snapshot, fh)
default:
// TODO warn that we did not know how to format that file... why was the
// request routed to this LSP?
}
return nil, nil // empty result
}
|