2019-04-17 13:37:20 -06:00
|
|
|
// 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.
|
|
|
|
|
2018-12-05 15:00:36 -07:00
|
|
|
package lsp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-02-26 15:56:56 -07:00
|
|
|
"golang.org/x/tools/internal/lsp/mod"
|
2018-12-05 15:00:36 -07:00
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
|
|
)
|
|
|
|
|
2019-04-17 13:37:20 -06:00
|
|
|
func (s *Server) formatting(ctx context.Context, params *protocol.DocumentFormattingParams) ([]protocol.TextEdit, error) {
|
2020-02-26 15:56:56 -07:00
|
|
|
snapshot, fh, ok, err := s.beginFileRequest(params.TextDocument.URI, source.UnknownKind)
|
2020-02-13 11:46:49 -07:00
|
|
|
if !ok {
|
2019-06-27 14:29:03 -06:00
|
|
|
return nil, err
|
|
|
|
}
|
2020-02-26 15:56:56 -07:00
|
|
|
switch fh.Identity().Kind {
|
|
|
|
case source.Mod:
|
|
|
|
return mod.Format(ctx, snapshot, fh)
|
|
|
|
case source.Go:
|
|
|
|
return source.Format(ctx, snapshot, fh)
|
2019-12-10 09:51:34 -07:00
|
|
|
}
|
2020-02-26 15:56:56 -07:00
|
|
|
return nil, nil
|
2019-04-08 07:22:58 -06:00
|
|
|
}
|