Skip to content

Emit definition for all package statements, not just one#199

Merged
jupblb merged 14 commits intomainfrom
michal/package-defs
Apr 13, 2026
Merged

Emit definition for all package statements, not just one#199
jupblb merged 14 commits intomainfrom
michal/package-defs

Conversation

@jupblb
Copy link
Copy Markdown
Member

@jupblb jupblb commented Apr 10, 2026

This follows gopls convention.

jupblb added 7 commits April 10, 2026 11:36
Every file's package statement is an equally valid declaration of
the package. Previously only one heuristically chosen file got
the Definition role while others were marked as ReadAccess. Now
all package statements are definitions, with the best file still
providing the SymbolInformation documentation.
- Rename findBestPackageDefinitionPath to findPackageDocFile to reflect
  its actual purpose: picking the file for package documentation
- Remove redundant pkgDeclaration != nil guard (always true at that point)
- Drop PackageName struct; store symbol string directly in pkgSymbols map
- SetPkgSymbol now returns the symbol string, removing a separate Get call
- Remove unused go/ast import from lookup.go
Previously findBestPackageDefinitionPath always returned a file using
levenshtein distance heuristics, even when no file had a doc comment.
Now findPackageDocFile returns nil when no file has documentation,
which means no SymbolInformation is emitted for undocumented packages.

This removes the levenshtein dependency and the error return value.
Instead of stuffing everything into the legacy documentation field,
emit proper SCIP fields per the proto spec:
- display_name: the package name (e.g. 'initial')
- signature_documentation: 'package <name>' as Go source
- documentation: only the actual doc comment, when present
Instead of returning *ast.File and extracting Doc.Text() at the call
site, return the doc comment text directly. This removes the need for
the caller to know about ast.File internals.
findPackageDocs now returns all doc comments from all files in the
package, sorted by relevance: doc.go first, then exact package name
match, then other non-test files, and test files last. Previously
only the single best doc comment was returned and test files were
excluded entirely.
@jupblb jupblb force-pushed the michal/package-defs branch 2 times, most recently from 7afb5e6 to e670ad3 Compare April 10, 2026 14:14
jupblb added 5 commits April 10, 2026 19:51
Covers: all package declarations as definitions, display_name and
signature_documentation fields, multi-file doc comment collection
sorted by relevance, and file header comments separated by blank
lines not treated as doc comments.
The sort and loop handle empty input naturally. Use var instead of
make so nil is returned when no files have doc comments.
Register the package SymbolInformation on the first file before
iterating, removing the symInfoEmitted flag. Also remove the
unused packagePrefixes function.
@jupblb jupblb force-pushed the michal/package-defs branch from 1e1c16c to a9c2d7e Compare April 10, 2026 19:07
@jupblb jupblb force-pushed the michal/package-defs branch from a9c2d7e to 54b4cf3 Compare April 10, 2026 19:08
@jupblb jupblb force-pushed the michal/package-defs branch from 1259cea to e8298d2 Compare April 13, 2026 18:38
@jupblb jupblb merged commit 3cad9ef into main Apr 13, 2026
9 checks passed
@jupblb jupblb deleted the michal/package-defs branch April 13, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant