github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/internal/lsp/format.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package lsp 6 7 import ( 8 "context" 9 10 "github.com/powerman/golang-tools/internal/lsp/mod" 11 "github.com/powerman/golang-tools/internal/lsp/protocol" 12 "github.com/powerman/golang-tools/internal/lsp/source" 13 "github.com/powerman/golang-tools/internal/lsp/work" 14 ) 15 16 func (s *Server) formatting(ctx context.Context, params *protocol.DocumentFormattingParams) ([]protocol.TextEdit, error) { 17 snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.UnknownKind) 18 defer release() 19 if !ok { 20 return nil, err 21 } 22 switch snapshot.View().FileKind(fh) { 23 case source.Mod: 24 return mod.Format(ctx, snapshot, fh) 25 case source.Go: 26 return source.Format(ctx, snapshot, fh) 27 case source.Work: 28 return work.Format(ctx, snapshot, fh) 29 } 30 return nil, nil 31 }