github.com/v2fly/tools@v0.100.0/internal/lsp/references.go (about)

     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  	"github.com/v2fly/tools/internal/lsp/protocol"
    11  	"github.com/v2fly/tools/internal/lsp/source"
    12  )
    13  
    14  func (s *Server) references(ctx context.Context, params *protocol.ReferenceParams) ([]protocol.Location, 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  	references, err := source.References(ctx, snapshot, fh, params.Position, params.Context.IncludeDeclaration)
    21  	if err != nil {
    22  		return nil, err
    23  	}
    24  	var locations []protocol.Location
    25  	for _, ref := range references {
    26  		refRange, err := ref.Range()
    27  		if err != nil {
    28  			return nil, err
    29  		}
    30  		locations = append(locations, protocol.Location{
    31  			URI:   protocol.URIFromSpanURI(ref.URI()),
    32  			Range: refRange,
    33  		})
    34  	}
    35  	return locations, nil
    36  }