Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201028153306-37f0764111ff / internal / lsp / rename.go
1 // Copyright 2019 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         "golang.org/x/tools/internal/lsp/protocol"
11         "golang.org/x/tools/internal/lsp/source"
12 )
13
14 func (s *Server) rename(ctx context.Context, params *protocol.RenameParams) (*protocol.WorkspaceEdit, error) {
15         snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.Go)
16         defer release()
17         if !ok {
18                 return nil, err
19         }
20         edits, err := source.Rename(ctx, snapshot, fh, params.Position, params.NewName)
21         if err != nil {
22                 return nil, err
23         }
24
25         var docChanges []protocol.TextDocumentEdit
26         for uri, e := range edits {
27                 fh, err := snapshot.GetVersionedFile(ctx, uri)
28                 if err != nil {
29                         return nil, err
30                 }
31                 docChanges = append(docChanges, documentChanges(fh, e)...)
32         }
33         return &protocol.WorkspaceEdit{
34                 DocumentChanges: docChanges,
35         }, nil
36 }
37
38 func (s *Server) prepareRename(ctx context.Context, params *protocol.PrepareRenameParams) (*protocol.Range, error) {
39         snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.Go)
40         defer release()
41         if !ok {
42                 return nil, err
43         }
44         // Do not return errors here, as it adds clutter.
45         // Returning a nil result means there is not a valid rename.
46         item, err := source.PrepareRename(ctx, snapshot, fh, params.Position)
47         if err != nil {
48                 return nil, nil // ignore errors
49         }
50         // TODO(suzmue): return ident.Name as the placeholder text.
51         return &item.Range, nil
52 }