Skip to content

feat: include python (w/ sphinx) support #3

Draft
gbrasil720 wants to merge 2 commits intospacelaxy:mainfrom
gbrasil720:feat/python-support
Draft

feat: include python (w/ sphinx) support #3
gbrasil720 wants to merge 2 commits intospacelaxy:mainfrom
gbrasil720:feat/python-support

Conversation

@gbrasil720
Copy link
Copy Markdown

This pull request adds full support for Python Sphinx-style documentation comments to the extension, including syntax highlighting, completion, and parsing. The main changes introduce a new parser for Python docstrings, update configuration to recognize Sphinx patterns, and improve completion and detection logic for Python comments.

Python Sphinx Documentation Support

  • Added full support for Python Sphinx-style comments in the documentation, including listing Python/Sphinx in the supported languages table and providing an example in README.md. [1] [2]

Configuration Updates

  • Added Sphinx-specific patterns (:param, :returns, :raises) to the default comment patterns for highlighting and completion in src/config/default-patterns.config.ts.
  • Updated language configuration to properly detect Python docstrings using regex, removed Python from hash-based comment detection, and set block comment lengths for Python docstrings in src/config/language.config.ts. [1] [2] [3]

Parser and Pattern Recognition

  • Added PythonParser for extracting and parsing Sphinx-style docstrings, including handling parameters, return values, types, and exceptions in src/parsers/python.parser.ts and registered it in the parser factory. [1] [2] [3]
  • Updated parser patterns configuration to include Python-specific comment detection, block extraction, code extraction, documentation parsing, and cleaning logic in src/config/parser-patterns.config.ts. [1] [2] [3] [4] [5]

Completion and Extension Logic

  • Refactored completion provider to dynamically fetch patterns from configuration, detect if the cursor is inside a Python docstring, and provide Sphinx-style completions; streamlined activation logic in src/extension.ts and src/providers/comment-completion.provider.ts. [1] [2]

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive Python Sphinx documentation support to the extension. It enables syntax highlighting, code completion, and parsing for Python docstrings using Sphinx/reStructuredText conventions like :param, :returns, and :raises tags.

Key changes:

  • Added Python parser for extracting and parsing Sphinx-style docstrings
  • Updated configuration to properly detect Python docstrings and exclude Python from hash-based comment detection
  • Refactored completion provider to support dynamic pattern fetching and Python docstring detection

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/parsers/python.parser.ts New parser implementation for Python Sphinx docstrings
src/providers/comment-highlight.provider.ts Added Python-specific highlighting logic for docstrings
src/providers/comment-completion.provider.ts Refactored to support dynamic patterns and Python docstring detection
src/config/parser-patterns.config.ts Added Python-specific regex patterns for docstring parsing
src/config/language.config.ts Updated language configuration for Python docstring support
src/config/default-patterns.config.ts Added Sphinx tag patterns for highlighting
src/parsers/index.ts Registered new Python parser
src/extension.ts Streamlined extension activation logic
README.md Added Python/Sphinx documentation and examples

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/parsers/index.ts
Comment on lines +10 to +22
export const PARSERS = [
new CSharpParser(),
new CppParser(),
new CppParser(),
new CppParser(),
new JavaParser(),
new JavaScriptParser(),
new JavaScriptParser(),
new PHPParser(),
new RustParser(),
new PythonParser(),
];

Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate parser instances are being created. Lines 12-14 create three CppParser instances and lines 16-17 create two JavaScriptParser instances. This array appears to be unused but creates unnecessary object instances.

Suggested change
export const PARSERS = [
new CSharpParser(),
new CppParser(),
new CppParser(),
new CppParser(),
new JavaParser(),
new JavaScriptParser(),
new JavaScriptParser(),
new PHPParser(),
new RustParser(),
new PythonParser(),
];

Copilot uses AI. Check for mistakes.
if(this.isInsideComment(document, position)) {
const completionItems = commentPatterns.map(pattern => {
const item = new vscode.CompletionItem(pattern.pattern, vscode.CompletionItemKind.Text);
item.insertText = pattern.pattern.startsWith('@') ? pattern.pattern.substring(1) : pattern.pattern;
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The completion logic is inconsistent. Line 11 uses the full pattern as the label, but line 12 removes the '@' prefix for insertion. This creates confusing completion items where the displayed text doesn't match what gets inserted.

Suggested change
item.insertText = pattern.pattern.startsWith('@') ? pattern.pattern.substring(1) : pattern.pattern;
item.insertText = pattern.pattern;

Copilot uses AI. Check for mistakes.
Comment thread src/extension.ts
Comment on lines +39 to +41
ConfigurationService.onConfigurationChanged(() => {

});
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty configuration change handler serves no purpose. The previous implementation updated completion patterns when configuration changed, but this functionality has been removed without explanation.

Copilot uses AI. Check for mistakes.
@henrythierrydev
Copy link
Copy Markdown
Member

I tested the extension with the proposed Python Sphinx documentation support, but I ran into several issues that prevent merging at this time:

  • Autocomplete conflicts and bugs, The current implementation causes inconsistencies in code completion, especially around Python docstrings, which makes it unreliable for daily use.
  • Copilot suggestions indicate unresolved issues, For example:

src/parsers/index.ts: Duplicate parser instances (CppParser and JavaScriptParser) create unnecessary objects.
src/providers/comment-completion.provider.ts: Completion logic is inconsistent; the displayed text sometimes differs from the inserted text, causing confusion.
src/extension.ts: The configuration change handler is empty, removing previous functionality without explanation.

Given these conflicts and bugs, I recommend holding off on this PR until the issues are resolved. Once these points are addressed, the extension can be safely merged with full Python Sphinx support.

@henrythierrydev henrythierrydev requested review from henrythierrydev and removed request for henrythierrydev September 20, 2025 17:56
@henrythierrydev henrythierrydev marked this pull request as draft September 20, 2025 17:57
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.

3 participants