Emit definition for all package statements, not just one#199
Merged
Conversation
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.
7afb5e6 to
e670ad3
Compare
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.
1e1c16c to
a9c2d7e
Compare
a9c2d7e to
54b4cf3
Compare
1259cea to
e8298d2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This follows
goplsconvention.