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/event"
11 "golang.org/x/tools/internal/lsp/debug/tag"
12 "golang.org/x/tools/internal/lsp/protocol"
13 "golang.org/x/tools/internal/lsp/source"
16 func (s *Server) documentSymbol(ctx context.Context, params *protocol.DocumentSymbolParams) ([]interface{}, error) {
17 ctx, done := event.Start(ctx, "lsp.Server.documentSymbol")
20 snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.Go)
23 return []interface{}{}, err
25 docSymbols, err := source.DocumentSymbols(ctx, snapshot, fh)
27 event.Error(ctx, "DocumentSymbols failed", err, tag.URI.Of(fh.URI()))
28 return []interface{}{}, nil
30 // Convert the symbols to an interface array.
31 // TODO: Remove this once the lsp deprecates SymbolInformation.
32 symbols := make([]interface{}, len(docSymbols))
33 for i, s := range docSymbols {
34 if snapshot.View().Options().HierarchicalDocumentSymbolSupport {
38 // If the client does not support hierarchical document symbols, then
39 // we need to be backwards compatible for now and return SymbolInformation.
40 symbols[i] = protocol.SymbolInformation{
43 Deprecated: s.Deprecated,
44 Location: protocol.Location{
45 URI: params.TextDocument.URI,