fix: Return whole lines when looking up source code #2193
Merged
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 pull request includes several changes to improve the handling and testing of source code snippets in the
buildContext
andlookupSourceCode
functions. The most important changes include modifying thelookupSourceCode
function to return an object with content and location, updating thebuildContext
function to accommodate this change, and adding new unit tests forlookupSourceCode
.Improvements to
lookupSourceCode
function:packages/cli/src/rpc/explain/lookupSourceCode.ts
: ModifiedlookupSourceCode
to return an object withcontent
andlocation
instead of an array of strings. This change ensures that the returned snippet includes both the content and its precise location. [1] [2] [3]Updates to
buildContext
function:packages/cli/src/rpc/explain/buildContext.ts
: UpdatedbuildContext
to handle the new object returned bylookupSourceCode
, ensuring that thecodeSnippets
array contains the correctcontent
andlocation
fields.Unit tests:
packages/cli/tests/unit/rpc/explain/buildContext.spec.ts
: Updated existing tests to match the new return type oflookupSourceCode
, ensuring that thelocation
field includes line numbers. [1] [2]packages/cli/tests/unit/rpc/explain/lookupSourceCode.spec.ts
: Added new unit tests forlookupSourceCode
to verify that it returns the correct snippet object and handles non-existent lines appropriately.