Skip to content

feat(codehints): language-agnostic "doc comment" generator#2999

Open
abose wants to merge 5 commits into
mainfrom
ai
Open

feat(codehints): language-agnostic "doc comment" generator#2999
abose wants to merge 5 commits into
mainfrom
ai

Conversation

@abose

@abose abose commented Jun 30, 2026

Copy link
Copy Markdown
Member

Summary

Adds a language-aware doc-comment hint provider that expands a comment opener above a function/declaration into a tab-navigable documentation skeleton.

Details

  • Adds doc-comment hints for JS/TS/JSX/TSX, PHP, Java, C, C++, and Python.

  • Uses the correct convention per language:

    • JSDoc for JS/TS
    • PHPDoc for PHP
    • Javadoc/Doxygen-style tags for Java/C/C++
    • Python docstrings with Args: / Returns:
  • Removes Rust support for this hint since Rust uses /// markdown-style docs.

  • Avoids shadowing normal LSP/Tern completions by only claiming hints in valid doc-comment opener contexts.

  • Parses function parameters directly from declarations without requiring a language server.

  • Keeps generated snippets free of trailing whitespace.

  • Improves Python behavior:

    • handles auto-closed "" correctly
    • only adds Returns: when an explicit return annotation exists

Tests

  • Updated unit:DocCommentHints to exercise the real provider per language using a mock editor.
  • Added integration:DocCommentHints coverage to verify the hints popup appears in real editor windows per language.

abose added 5 commits June 30, 2026 22:00
Adds a DocCommentHints default extension: when the caret is on a
doc-comment opener above a declaration, it offers a single hint - "Add
JSDoc comment" / "Add docstring" - that expands a Tab-navigable skeleton
(@param per parameter + @returns, or Python Args:/Returns:) with the
parameters parsed from the signature.

- Works across JS/TS/JSX/TSX/PHP/Java/C/C++/Rust (JSDoc) and Python
  (docstring); names come from parsing the declaration, so it needs no
  language server, with a clean seam to enrich types from LSP/Tern later.
- Registers at high priority but claims hints ONLY in the opener context,
  so it never shadows the normal LSP/Tern completion providers.
- Triggers on a half-typed opener (/, /*) too, gated on an adjacent
  declaration so a stray / never spams the list; re-validates each
  keystroke so it dismisses cleanly.
- Generated lines carry no trailing whitespace (tabstops sit on the
  {type} only), so linters stay quiet.
- TabstopManager is preloaded in brackets.js / SpecRunner.js so the
  extension can resolve it synchronously.

Unit tests (unit:DocCommentHints) cover the param parser, the per-language
name conventions, and trailing-whitespace-free snippet output.
The doc-comment hint applied JSDoc to every block-comment language - wrong
for Java/C/C++ (Javadoc/Doxygen don't use {type} braces) and mislabeled
("Add JSDoc comment" in a .cpp file). Now each language gets its own
convention and label:

- jsdoc  (JS/TS/JSX/TSX): @param {type} name / @returns {type}
- phpdoc (PHP):           @param type $name / @return type
- tagdoc (Java/C/C++):    @param name / @return        (no {type} braces)
- pydoc  (Python):        """ ... Args:/Returns: ... """

Rust is dropped (its doc comments are /// markdown, not @param).

Python fixes:
- triggers on the auto-closed `""` state (typing " auto-closes to "" with
  the caret between the quotes); matches the whole line and replaces it on
  insert so the stray quote is swallowed.
- only emits a Returns: section when the def has an explicit `-> Type`
  annotation (an untyped function usually returns None - don't guess).

Tests: unit:DocCommentHints now drives the real provider per language on a
mock editor (hasHints -> getHints -> insertHint), and a new
integration:DocCommentHints opens a file per language in a test window and
asserts the code-hints popup actually appears.
The release build validates that every default extension is listed in
either minifyableExtensions or nonMinifyExtensions; the new
DocCommentHints extension was missing, failing makeConcatExtensions.
…ture

JSDoc generation used a constant {*}. For TypeScript (and JSDoc-typed JS)
the types are already in the signature being documented, so we now parse
them in - @param {number} a, @returns {Promise<number>} - synchronously,
no language server. Untyped JS stays {*}.

The parser is hardened for complex types via a single top-level scanner
that tracks () [] {} <> nesting, treats `>` after `=` as the arrow (not a
generic close), and skips string/template contents. This makes param
splitting and name/type extraction reliable for generics, function types,
object/tuple types, unions, conditionals, optionals (`?` -> [name]),
defaults and rest. Any annotation that doesn't balance falls back to {*},
so a broken `@param {…}` is never emitted.

_parseSignature now returns params as {name, type, optional} plus
returnType; the jsdoc builder renders the type as the tabstop default
(editable), the other styles are unchanged (read p.name). Scope: jsdoc
(JS/TS/JSX/TSX) only, per request.

Tests: new _parseParam/_validType suites cover the complex-type cases and
the unbalanced-fallback; _parseSignature asserts extracted param/return
types; the TS provider case now asserts real {number}/{string}/{boolean}.
In a .ts file the parameter/return types live in the signature, so a JSDoc
{type} (@param {number} / @returns {*}) is redundant and TypeScript flags
it: "JSDoc types may be moved to TypeScript types." Our generator was
raising that suggestion the instant a doc comment was inserted.

Split the JSDoc style by language:
- JavaScript/JSX -> jsdoc: @param {*} name / @returns {*}  (JSDoc IS the JS
  type system; {*} is a valid placeholder in a .js file)
- TypeScript/TSX -> new tsdoc style: @param name / @returns  (names only,
  no {type} braces, no {*} on @returns - types come from the signature)

The signature parser is unchanged and still extracts parameter names
reliably from complex TS signatures (generics, function types, etc.); the
type values are simply not emitted for TS.

Tests: new tsdoc builder unit test; the TS provider case and the
integration b.ts/c.ts cases now assert names-only and that {type}/{*} are
absent; the integration suite now accepts the hint and asserts the
inserted doc comment (not just that the popup appears).
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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