Skip to content
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

JSDoc tag descriptions lose their indentation. #53576

Open
jespertheend opened this issue Mar 29, 2023 · 2 comments · May be fixed by #53631
Open

JSDoc tag descriptions lose their indentation. #53576

jespertheend opened this issue Mar 29, 2023 · 2 comments · May be fixed by #53631
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Help Wanted You can do this
Milestone

Comments

@jespertheend
Copy link
Contributor

Does this issue occur when all extensions are disabled?: Yes

Version: 1.76.2
Commit: ee2b180d582a7f601fa6ecfdad8d9fd269ab1884
Date: 2023-03-14T17:47:26.641Z
Browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36

Steps to Reproduce:

  1. Open vscode.dev
  2. Create a new file and set language mode to JavaScript
  3. Paste the following:
/**
 * This works
 * ```
 * some
 *   indentations
 *     and
 *       some
 *         more
 * ```
 */
function foo() {}

/**
 * @typedef MyObj
 * @property {number} foo This doesn't
 * ```
 * some
 *   indentations
 *     and
 *       some
 *         more
 * ```
 */

const obj = /** @type {MyObj} */ (null);

obj.foo
  1. Hover over foo on the last line.

When hovering over foo() it works fine:
image

But on obj.foo the identation of the code block is lost:
image

@mjbvz mjbvz transferred this issue from microsoft/vscode Mar 29, 2023
@mjbvz
Copy link
Contributor

mjbvz commented Mar 29, 2023

@sandersn Looks like typescript is dropping the indentation in the second case:

"documentation": [
        {
            "text": "This doesn't\n```\nsome\nindentations\nand\nsome\nmore\n```",
            "kind": "text"
        }
    ],

@mjbvz mjbvz removed their assignment Mar 29, 2023
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this Domain: JSDoc Relates to JSDoc parsing and type generation labels Mar 30, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 30, 2023
@jespertheend
Copy link
Contributor Author

Seems like the issue lies here:

if (margin !== undefined && indent + whitespace.length > margin) {
comments.push(whitespace.slice(margin - indent));
state = JSDocState.SavingComments;
}

When parsing jsdoc comments inside parseJSDocCommentWorker() the margin is 3, so the indentation ends up being fine. But when similar steps are performed inside parseTagComments(), the margin ends up being 26 in my case.
So it seems like the margin of the first line is being used, which is usually pretty long because it contains the @param/@property tags and their name and type.

And this playground example, confirms this behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants