uctakeoff / vscode-counter

VS Code extension: counts blank lines, comment lines, and physical lines of source code in many programming languages.
MIT License
151 stars 20 forks source link

comment lines of tsx is incorrect #51

Closed a1156883061 closed 2 years ago

a1156883061 commented 3 years ago

In tsx files, comment in element was not counted.

      {/* Bulletin Board Card */}
      <BulletinBoardCard
        title={title}
        content={content}
        address={address}
        contributor={contributor}
        publishStart={publishStart}
        publishEnd={publishEnd}
        onClick={onClick}
      />

comment like {/* Bulletin Board Card*/} was not recognized to comment.

a1156883061 commented 3 years ago

It seems these line cause this miss https://github.com/uctakeoff/vscode-counter/blob/627554d7ce33a3137732574bdf50ce262ea589c4/src/LineCounter.ts#L57-L63

this block comment not start with /* but {/*, so index not equals to 0

So type was be recognized as code ranther than comment

uctakeoff commented 2 years ago

Thank you for identifying the cause. However, there are still some problems with your idea.

If I fix it, the following code will also become a comment line.

x = 0;  /* comment */

Some C writers often write this kind of code.

There is also a way to mark the space between {/* and */} as a block comment, but it is not so cool. Do you have any other ideas?

hyluo1 commented 2 years ago

I think there should be a regex to identify the tsx comment Like this \{.*\/\*.*\*\/.*\}

uctakeoff commented 2 years ago

That method is a tsx-specific solution. The program needs to work in any language.

uctakeoff commented 2 years ago

@a1156883061 @hyluo1 This has been fixed in ver. 3.0.4. We had no choice but to give it a special treatment after all.