From ce30aee6cc56f39d0ac6fee03c4c151c08a8cd2e Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Wed, 16 Jun 2021 11:51:09 -0700 Subject: [PATCH] API docs: indexer: do not include Go blank const/var identifiers (#164) Fixes https://github.com/sourcegraph/sourcegraph/issues/22029 Signed-off-by: Stephen Gutekanst --- internal/indexer/documentation.go | 6 +- .../TestIndexer_documentation/testdata.golden | 96 ------------------- 2 files changed, 5 insertions(+), 97 deletions(-) diff --git a/internal/indexer/documentation.go b/internal/indexer/documentation.go index f4a21e8e..67f10372 100644 --- a/internal/indexer/documentation.go +++ b/internal/indexer/documentation.go @@ -369,7 +369,11 @@ func (d *docsIndexer) indexGenDecl(p *packages.Package, f *ast.File, node *ast.G case *ast.ValueSpec: // Variable or constant, potentially of the form `var x, y = 1, 2` - we emit each // separately. - for i := range t.Names { + for i, name := range t.Names { + if name.Name == "_" { + // Not only is it not exported, it cannot be referenced outside this package at all. + continue + } switch node.Tok { case token.CONST: constDocs := d.indexConstVar(p, t, i, "const", isTestFile) diff --git a/internal/indexer/testdata/TestIndexer_documentation/testdata.golden b/internal/indexer/testdata/TestIndexer_documentation/testdata.golden index 4a126270..01c196e7 100644 --- a/internal/indexer/testdata/TestIndexer_documentation/testdata.golden +++ b/internal/indexer/testdata/TestIndexer_documentation/testdata.golden @@ -34,7 +34,6 @@ testdata is a small package containing sample Go source code used for testing th - [var BigVar](#github.com-sourcegraph-lsif-go-internal-testdata---BigVar) - [var VarBlock1](#github.com-sourcegraph-lsif-go-internal-testdata---VarBlock1) - [var VarBlock2](#github.com-sourcegraph-lsif-go-internal-testdata---VarBlock2) - - [var _](#github.com-sourcegraph-lsif-go-internal-testdata---_) - [var wg](#github.com-sourcegraph-lsif-go-internal-testdata---wg) - [Types](#github.com-sourcegraph-lsif-go-internal-testdata---type) - [type Embedded struct](#github.com-sourcegraph-lsif-go-internal-testdata---Embedded) @@ -1083,101 +1082,6 @@ ZZZzz /,`.-'`' -. ;-;;,_ ``` It's sleeping! Some people write that as `sleeping` but Markdown isn't allowed in Go docstrings, right? right?! -#### var _ - -
hover - -> ```go -> var _ invalid type -> ``` -> -> --- -> -> Yeah this is some Go magic incantation which is common. -> -> ``` -> ,_ _ -> |\\_,-~/ -> / _ _ | ,--. -> ( @ @ ) / ,-' -> \ _T_/-._( ( -> / `. \ -> | _ \ | -> \ \ , / | -> || |-_\__ / -> ((_/`(____,-' -> -> ``` - -
- -
definitions - -```json -[ - { - "Document": "/child_symbols.go", - "Ranges": [ - { - "start": { - "line": 116, - "character": 4 - }, - "end": { - "line": 116, - "character": 5 - } - } - ] - } -] -``` - -
- -
references - -```json -[ - { - "Document": "/child_symbols.go", - "Ranges": [ - { - "start": { - "line": 116, - "character": 4 - }, - "end": { - "line": 116, - "character": 5 - } - } - ] - } -] -``` - -
- -```Go -var _ = Interface(&Struct{}) -``` - -Yeah this is some Go magic incantation which is common. - -``` - ,_ _ - |\\_,-~/ - / _ _ | ,--. -( @ @ ) / ,-' - \ _T_/-._( ( -/ `. \ -| _ \ | -\ \ , / | - || |-_\__ / -((_/`(____,-' - -``` #### var wg
hover