mirror of
https://github.com/golang/go
synced 2024-11-18 20:24:41 -07:00
c02eab13f0
This change uses go/types information to get the types for the different symbols. It also groups the symbols according to their kinds, though this doesn't seem to be reflected in the actual VSCode UI... Updates golang/go#30915 Change-Id: I2caefe01f9834aaad6b9e81cd391d461405ef725 Reviewed-on: https://go-review.googlesource.com/c/tools/+/169438 Reviewed-by: Ian Cottrell <iancottrell@google.com>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
// 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 (
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
)
|
|
|
|
func toProtocolDocumentSymbols(m *protocol.ColumnMapper, symbols []source.Symbol) []protocol.DocumentSymbol {
|
|
result := make([]protocol.DocumentSymbol, 0, len(symbols))
|
|
for _, s := range symbols {
|
|
ps := protocol.DocumentSymbol{
|
|
Name: s.Name,
|
|
Kind: toProtocolSymbolKind(s.Kind),
|
|
Detail: s.Detail,
|
|
Children: toProtocolDocumentSymbols(m, s.Children),
|
|
}
|
|
if r, err := m.Range(s.Span); err == nil {
|
|
ps.Range = r
|
|
}
|
|
if r, err := m.Range(s.SelectionSpan); err == nil {
|
|
ps.SelectionRange = r
|
|
}
|
|
result = append(result, ps)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func toProtocolSymbolKind(kind source.SymbolKind) protocol.SymbolKind {
|
|
switch kind {
|
|
case source.StructSymbol:
|
|
return protocol.Struct
|
|
case source.PackageSymbol:
|
|
return protocol.Package
|
|
case source.VariableSymbol:
|
|
return protocol.Variable
|
|
case source.ConstantSymbol:
|
|
return protocol.Constant
|
|
case source.FunctionSymbol:
|
|
return protocol.Function
|
|
case source.MethodSymbol:
|
|
return protocol.Method
|
|
default:
|
|
return 0
|
|
}
|
|
}
|