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.
10 "golang.org/x/tools/internal/lsp/protocol"
11 "golang.org/x/tools/internal/lsp/source"
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)
20 edits, err := source.Rename(ctx, snapshot, fh, params.Position, params.NewName)
25 var docChanges []protocol.TextDocumentEdit
26 for uri, e := range edits {
27 fh, err := snapshot.GetVersionedFile(ctx, uri)
31 docChanges = append(docChanges, documentChanges(fh, e)...)
33 return &protocol.WorkspaceEdit{
34 DocumentChanges: docChanges,
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)
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)
48 return nil, nil // ignore errors
50 // TODO(suzmue): return ident.Name as the placeholder text.
51 return &item.Range, nil