question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question/Help] How to get a related comment for each node?

See original GitHub issue

I have a block of code

import { IFilter } from '../pipelines/IFilter';

/**
* Bi-directional Value Converters
*
* @valueConverter RgbToHex - Red-Green-Blue to Hex converter.
* We want to bind this color object to an HTML5 color input.
*/
@valueConverter("RgbToHex")
export class RgbToHexValueConverter {
  toView(rgb: IColor): string {
    return "#" + (
      (1 << 24) + (rgb.r << 16) + (rgb.g << 8) + rgb.b
    ).toString(16).slice(1);
  }

  /**
  * A method
  *
  * @method fromView - get data from view?
  * This method is fromView.
  */
  fromView(hex: string): IColor {
    let exp = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,
      result = exp.exec(hex);
    return {
      r: parseInt(result[1], 16),
      g: parseInt(result[2], 16),
      b: parseInt(result[3], 16)
    };
  }

  get fullName(): string {
    return "FullName";
  }
}

How to get a related comment for each node? I need whole comment text and the type: MultiLine or SingleLine.

For example:

ClassDeclaration

/**
* Bi-directional Value Converters
*
* @valueConverter RgbToHex - Red-Green-Blue to Hex converter.
* We want to bind this color object to an HTML5 color input.
*/

1

MethodDeclaration

  /**
  * A method
  *
  * @method fromView - get data from view?
  * This method is fromView.
  */

2

With Typescript compiler API I am able to find any comment for each node by leadingComments.

Can anyone guide me?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dsherretcommented, Jul 8, 2019

@HamedFathi jsdocs will always be multiline—won’t be // text (single line). If you want to get the single line comments then use getLeadingCommentRanges() on the node you want to get the comments from.

1reaction
dsherretcommented, Jul 8, 2019

@HamedFathi no problem! Glad to help.

By the way, there is also a thing called “comment nodes” that’s specific to ts-morph: https://dsherret.github.io/ts-morph/details/comments#comment-nodes – I’m not sure if it’s helpful in this scenario though, but worth mentioning just in case (and might be useful for someone else reading this).

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Question/Help] How to get a related comment for each node?
I have a block of code import { IFilter } from '../pipelines/IFilter'; /** * Bi-directional Value Converters * * @valueConverter RgbToHex - Red-Green-Blue ......
Read more >
Question: help me please · Issue #1621 · node-fetch/node-fetch ...
@jgromaire What command did you run ? You need to use the Bug report issue template so we can help you. Create a...
Read more >
Interview Question, Help needed - general - CodeChef Discuss
We have a list of N nodes with each node pointing to one of the N nodes. It could even be pointing to...
Read more >
Node.js Interview Questions and Answers - Blog - RisingStack
Hiring Node.js developers, or want to get hired? 10 Node.js interview questions you should know the answers for.
Read more >
Help with this C++ code. If possible please comment | Chegg.com
Ask the user for the name of a file containing data. · If the list is empty, create a new node with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found