Skip to content

fix(chat): document code command now properly indents generated comments especially python docstrings #8039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ichim-david
Copy link
Collaborator

This pr deals with a couple of issues:

  • improper generation of docstrings when asking for the class
  • failure to generate with result text being an empty string within python methods
  • improper spacing when the result contained also the function definition not just the comment

Test plan

  • Use opt + d to generate Python docstrings on classes, methods
  • Check if the position and spacing are correct

- Enhanced FixupController to handle indentation correctly when inserting code snippets, especially for Python docstrings.
- Adjusted docstring placement logic in `getLanguageSpecificQueryWrappers` to ensure correct positioning above symbols.
- Added a special case to handle Python documentation indentation.
- Fixed an issue where the LLM returns the entire code block instead of only the docstring.

## Test plan

- Tested with various code snippets and docstrings to ensure correct indentation and placement.
- Verified that the fix addresses the issue of the LLM returning the entire code block instead of only the docstring.
- Modified the symbol capture condition in `getLanguageSpecificQueryWrappers` to correctly identify symbols based on their position relative to the start position.
- Changed `node.startPosition.row <= start.row` to `node.startPosition.row < start.row` to refine the symbol matching logic.

This fixes the tests from `vscode/src/tree-sitter/query-tests/documentable-nodes.test.ts`
- Adjusted indentation logic in `FixupController.ts` to handle cases where the target indentation is greater than the text indentation.
- Added a special case for Python documentation to avoid incorrect indentation.
- Modified `claude.ts` to prevent empty responses from Claude when generating docstrings for Python functions by excluding the function definition line from the stop sequences.
- Fixed a bug in `FixupController.ts` where the entire code block was being returned instead of just the docstring for Python document code actions. Now, the code correctly replaces the original range with the generated text.
- With the fixes made to the white space, we get a better spacing distribution than what we had before.
@ichim-david ichim-david requested a review from umpox June 9, 2025 07:42
@ichim-david ichim-david marked this pull request as draft June 9, 2025 16:07
…test coverage (#8080)

This commit addresses an issue where `vscode.commands.executeCommand` would throw a TypeError when invoked with null arguments. The fix involves adding a null check before accessing `Symbol.iterator` when handling arguments.

Additionally, this commit includes comprehensive test coverage for `vscode.commands.executeCommand`, specifically focusing on handling null, undefined, and iterable arguments correctly.

The following changes were made:

- Added null check in `vscode-shim.ts` to prevent TypeError when `args[0]` is null.
- Added tests in `vscode-shim.test.ts` to verify correct handling of null, undefined, and iterable arguments.
- Added no-op handlers for `textEditor/selection` and `textEditor/revealRange` requests in `TestClient.ts` to support testing scenarios.

Test plan:

- Run `document-code.test.ts` and vscode-shim.test.ts` to ensure all tests pass.
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