fix(fortran): map source_location back through cpp linemarkers (#2092)#2105
Open
SinghAman21 wants to merge 1 commit into
Open
fix(fortran): map source_location back through cpp linemarkers (#2092)#2105SinghAman21 wants to merge 1 commit into
SinghAman21 wants to merge 1 commit into
Conversation
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.
What
Capital-F Fortran files (
.F.F90.F95.F03.F08) are run throughcpp,which was invoked with
-P.-Psuppresses linemarkers, and sincecppblanksdirective lines, drops inactive
#ifdefblocks, and collapses blank runs, theline numbers tree-sitter sees no longer match the original file.
Result: every symbol got a wrong
source_location— including files with nopreprocessor directives at all (blank-line collapse). A confidently wrong line
sends
explain/affected/ the MCP read surface to unrelated code.How
-Psocppkeeps its# <n> "<file>"linemarkers._cpp_preprocessnow returns(source, line_map);_strip_linemarkersconsumes the markers to build a preprocessed-line → original-line map and
hands tree-sitter marker-free source (blanks kept, so rows stay in lockstep).
add_node/add_edgetranslate each line through_orig_line.-nostdinc -I /dev/nullsecurity flags, and the raw-bytesfallback for lowercase
.f90and whencppis absent (line_map = None).Verified on the issue's example:
module solver→ L9,compute_volume→ L12,zebrafunc(after 5 blank lines) → L6.Files
graphify/extractors/fortran.py— run cpp without-P, parse linemarkers,translate node/edge lines.
tests/test_languages.py— 2 location tests (directive case + blank-line case).tests/test_cpp_preprocess.py— updated for the new(bytes, line_map)signature; keeps the argument-injection check and adds a
-Pguard.CHANGELOG.md— entry under0.9.24 (unreleased).Reference
.F/.F90/.F95/.F03/.F08file gets a wrongsource_location—cpp -Prenumbers lines with no way back #2092graphify/extractors/fortran.py(cpp -Pinvocation).Conclusion
Fortran symbols now report their true source line regardless of extension or
preprocessor directives. Full suite green (pre-existing unrelated
test_ollama_retry_cap.pyfailures aside).