Skip to content

Commit

Permalink
Merge pull request #109 from kasecato/#108/extra_comment
Browse files Browse the repository at this point in the history
Fixed #108 extra /// before comment block
  • Loading branch information
kasecato authored Jul 28, 2020
2 parents 53b1037 + c3c51ee commit fba7438
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 52 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 0.1.17 (July 28, 2020)

* bug fix - extra "///" before comment block. See [#108](https://github.com/kasecato/vscode-docomment/issues/108).
* revert - ctrl-enter (insert line below, insert line above) in middle of line not adding `///`. See [#98](https://github.com/kasecato/vscode-docomment/issues/98).

## 0.1.16 (July 27, 2020)

* bug fix - ctrl-enter (insert line below, insert line above) in middle of line not adding `///`. See [#98](https://github.com/kasecato/vscode-docomment/issues/98).
Expand Down
88 changes: 41 additions & 47 deletions src/Domain/Lang/DocommentDomainCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { SyntacticAnalysisCSharp } from '../../SyntacticAnalysis/SyntacticAnalys
import { StringUtil } from '../../Utility/StringUtil';
import { DocommentDomain } from '../DocommentDomain';
import { CodeType } from '../IDocommentDomain';
import { CommentSyntax } from '../../Entity/Config/Contributes/Configuration';

export class DocommentDomainCSharp extends DocommentDomain {

Expand Down Expand Up @@ -40,67 +39,62 @@ export class DocommentDomainCSharp extends DocommentDomain {
return false;
}

// NG: KeyCode is NOT '/' or Enter
const isActivationKey: boolean = SyntacticAnalysisCSharp.IsActivationKey(activeChar, this._config.syntax);
const isEnterKey: boolean = SyntacticAnalysisCSharp.IsEnterKey(eventText);
if (!isActivationKey && !isEnterKey) {
// NG: After Insert Docomment
const isAfterDocomment: boolean = SyntacticAnalysisCSharp.IsAfterDocomment(eventText);
if (isAfterDocomment) {
return false;
}
this._isEnterKey = isEnterKey;

// NG: Activate on Enter NOT '/'
const activeLine: string = this._vsCodeApi.ReadLineAtCurrent();
let isActivateKeyDelimited: boolean;
const isActivationKey: boolean = SyntacticAnalysisCSharp.IsActivationKey(activeChar, this._config.syntax);
if (isActivationKey) {
return this.IsTriggerDocommentByActivationKey();
}

this._isEnterKey = SyntacticAnalysisCSharp.IsEnterKey(eventText);
if (this._isEnterKey) {
return this.IsTriggerDocommentByEnterKey(eventText);
}

return false;
}

private IsTriggerDocommentByActivationKey(): boolean {

if (this._config.activateOnEnter) {
if (!isEnterKey) {
if (!this._isEnterKey) {
return false;
}
if (this._config.syntax === CommentSyntax.delimited) {
isActivateKeyDelimited = SyntacticAnalysisCSharp.IsDocCommentStrict(activeLine, this._config.syntax);
}
}

// NG: After Insert DocComment
const isAfterDocComment: boolean = (activeChar == ' ') && !isActivationKey && isEnterKey;
if (isAfterDocComment) {
const activeLine: string = this._vsCodeApi.ReadLineAtCurrent();

// NG: '////'
if (!SyntacticAnalysisCSharp.IsDocCommentStrict(activeLine, this._config.syntax)) {
return false;
}

// NG: '////'
if (isActivationKey || isActivateKeyDelimited) {
// NG: '////'
if (!SyntacticAnalysisCSharp.IsDocCommentStrict(activeLine, this._config.syntax)) {
return false;
}
// NG: '/' => Insert => Event => ' /// '
if (SyntacticAnalysisCSharp.IsDoubleDocComment(activeLine, this._config.syntax)) {
return false;
}

// NG: '/' => Insert => Event => ' /// '
if (SyntacticAnalysisCSharp.IsDoubleDocComment(activeLine, this._config.syntax)) {
return false;
}
return true;
}

private IsTriggerDocommentByEnterKey(eventText: string): boolean {

const activeLine: string = this._vsCodeApi.ReadLineAtCurrent();

// NG: '////'
if (!SyntacticAnalysisCSharp.IsDocComment(activeLine, this._config.syntax)) {
return false;
}
// Comment Line
else if (isEnterKey) {
// NG: '////'
const isInsertLineAbove = SyntacticAnalysisCSharp.IsInsertLineAbove(activeLine);
if (isInsertLineAbove) {
const nextLine = this._vsCodeApi.ReadNextLineFromCurrent();
const isInsertDocCommentLineAbove = SyntacticAnalysisCSharp.IsDocComment(nextLine, this._config.syntax);
if (!isInsertDocCommentLineAbove) {
return false;
}
this._isInsertDocCommentLineAbove = isInsertDocCommentLineAbove;
} else {
if (!SyntacticAnalysisCSharp.IsDocComment(activeLine, this._config.syntax)) {
return false;
}
}
// NG: Undo comment lines with the enter key
if (SyntacticAnalysisCSharp.IsDocComment(eventText, this._config.syntax)) {
return false;
}

// NG: Undo comment lines with the enter key
if (SyntacticAnalysisCSharp.IsDocComment(eventText, this._config.syntax)) {
return false;
}

// OK
return true;
}

Expand Down
13 changes: 8 additions & 5 deletions src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ export class SyntacticAnalysisCSharp {
/*-------------------------------------------------------------------------
* Public Method: Comment Type
*-----------------------------------------------------------------------*/
public static IsEnterKey(text: string): boolean {
return (text.startsWith('\n') || text.startsWith("\r\n"));
public static IsEnterKey(eventText: string): boolean {
return (eventText.startsWith('\n') || eventText.startsWith("\r\n"));
}

public static IsAfterDocomment(eventText: string): boolean {
return eventText.match(/^\n[ \t]+[\S]+/) !== null || eventText.match(/^\r\n[ \t]+[\S]+/) !== null;
}

public static IsInsertLineAbove(activeLine: string): boolean {
Expand Down Expand Up @@ -47,7 +51,7 @@ export class SyntacticAnalysisCSharp {
case CommentSyntax.single:
return activeLine.match(/\/{3}/) !== null;
case CommentSyntax.delimited:
return activeLine.match(/^[ \t]*\*{1}[^\/]/) !== null;
return ((activeLine.match(/^[ \t]*\*{1}[^\/]/) !== null) || this.IsDocCommentStrict(activeLine, syntax));
}
}

Expand Down Expand Up @@ -134,8 +138,7 @@ export class SyntacticAnalysisCSharp {

public static IsComment(code: string): boolean {
if (code === null) return false;
if (code === '') return true;
return code.match(/[ \t]+/) !== null;
return true;
}

public static GetCommentSyntax(syntax: CommentSyntax): string {
Expand Down

0 comments on commit fba7438

Please sign in to comment.