2019-03-18 16:43:08 -06:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package lsp
|
|
|
|
|
|
|
|
import (
|
2019-04-17 13:37:20 -06:00
|
|
|
"context"
|
|
|
|
|
2019-03-18 16:43:08 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
2019-03-26 15:38:40 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
2019-12-04 11:18:11 -07:00
|
|
|
"golang.org/x/tools/internal/lsp/telemetry"
|
|
|
|
"golang.org/x/tools/internal/telemetry/log"
|
2019-08-13 13:07:39 -06:00
|
|
|
"golang.org/x/tools/internal/telemetry/trace"
|
2019-03-18 16:43:08 -06:00
|
|
|
)
|
|
|
|
|
2019-04-17 13:37:20 -06:00
|
|
|
func (s *Server) documentSymbol(ctx context.Context, params *protocol.DocumentSymbolParams) ([]protocol.DocumentSymbol, error) {
|
2019-06-26 20:46:12 -06:00
|
|
|
ctx, done := trace.StartSpan(ctx, "lsp.Server.documentSymbol")
|
|
|
|
defer done()
|
2019-09-05 16:54:05 -06:00
|
|
|
|
2020-02-13 11:46:49 -07:00
|
|
|
snapshot, fh, ok, err := s.beginFileRequest(params.TextDocument.URI, source.Go)
|
|
|
|
if !ok {
|
|
|
|
return []protocol.DocumentSymbol{}, err
|
2019-08-16 11:49:17 -06:00
|
|
|
}
|
2020-02-13 11:46:49 -07:00
|
|
|
symbols, err := source.DocumentSymbols(ctx, snapshot, fh)
|
2019-12-04 11:18:11 -07:00
|
|
|
if err != nil {
|
2020-02-13 11:46:49 -07:00
|
|
|
log.Error(ctx, "DocumentSymbols failed", err, telemetry.URI.Of(fh.Identity().URI))
|
2019-12-04 11:18:11 -07:00
|
|
|
return []protocol.DocumentSymbol{}, nil
|
|
|
|
}
|
|
|
|
return symbols, nil
|
2019-03-18 16:43:08 -06:00
|
|
|
}
|