Repository navigation
Conversation
colbymchenry#1905) getPrecedingDocstring only walks preceding comment siblings, so a Python docstring — a bare string literal first in the body — never reached the docstring column, never entered nodes_fts, and was never shown by `codegraph node`. The identical sentence written as a leading `#` comment was both. For a Python codebase that is most of the prose there is. (colbymchenry#1905) Adds an optional getBodyDocstring() to LanguageExtractor, in the same shape as getSignature(), and routes every docstring call site through one docstringFor() helper that consults both sources. A node carrying a comment AND a docstring keeps both, joined: they are two things the author wrote about the same symbol and the column is free text. The Python implementation reads the grammar`s string_content rather than slicing quotes off the raw text, so r/u/b prefixes and both triple-quote forms work without a regex per case; f-strings are skipped because an interpolated string is code, not prose. Dedent follows PEP 257 (first line exempt). Scoped to Python deliberately. Julia (a string sibling before the def) and Elixir (@doc) fit the same hook and are left as follow-ups.
Owner
|
Thanks @maxmilian! Your commits here were carried into #2004 (authorship preserved), with a few follow-up changes from review, and that is now merged. Closing this one in favour of it. It will be in the next release. |
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.
Fixes #1905.
getPrecedingDocstringonly walks preceding comment siblings, so a Python docstring — a bare string literal first in the body — never reached thedocstringcolumn, never enterednodes_fts, and was never shown bycodegraph node. The identical sentence written as a leading#comment was both.What changed
LanguageExtractorgains an optionalgetBodyDocstring?(), same shape asgetSignature?().tree-sitter.tsnow goes through onedocstringFor()helper that consults both sources. A node carrying a comment and a docstring keeps both, joined — two things the author wrote about the same symbol, and the column is free text.string_contentrather than slicing quotes off the raw text, sor/u/bprefixes and both"""and'''forms work without a regex per case. f-strings are skipped: an interpolated string is code, not prose. Dedent follows PEP 257 (first line exempt).Scoped to Python deliberately. Julia (a string sibling before the def) and Elixir (
@doc) fit the same hook; I would rather land one language with the seam proven.The recall risk, measured
The issue flags that more indexed prose raises recall and can add weak hits. Indexed 117 Python files from
docling-core(3,233 nodes) before and after, same queries, top 5:flattening nested tables(appears only in a docstring)_collect_subtree_textabsent_collect_subtree_textat #2descendant TableItemTableItem,_draw_table_cells, …MarkdownDocSerializer(exact name)the(stop word alone)scaled,normalized, …So: the gap closes, name-anchored queries do not degrade, and the churn is confined to a query that was arbitrary in both directions. I am not claiming the stop-word case is unchanged — it isn't — only that it does not displace a real match.
Testing
__tests__/python-body-docstrings.test.ts, 6 cases: the issue's own repro, multi-line dedent, comment + docstring together, single-quote andr-prefixed forms, f-string skipped, and a no-docstring control. Red-armed — revertingpython.tstomainturns 4 of them red, leaving the two negative controls green.Full suite: 259 files / 4,541 passed / 0 failed.
tsc --noEmitclean. CHANGELOG entry under[Unreleased]→ New Features.