github.com/april1989/origin-go-tools@v0.0.32/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/april1989/origin-go-tools/internal/lsp/mod"
    11  	"github.com/april1989/origin-go-tools/internal/lsp/protocol"
    12  	"github.com/april1989/origin-go-tools/internal/lsp/source"
    13  )
    14  
    15  func (s *Server) formatting(ctx context.Context, params *protocol.DocumentFormattingParams) ([]protocol.TextEdit, error) {
    16  	snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.UnknownKind)
    17  	defer release()
    18  	if !ok {
    19  		return nil, err
    20  	}
    21  	switch fh.Kind() {
    22  	case source.Mod:
    23  		return mod.Format(ctx, snapshot, fh)
    24  	case source.Go:
    25  		return source.Format(ctx, snapshot, fh)
    26  	}
    27  	return nil, nil
    28  }