diff --git a/CHANGELOG.md b/CHANGELOG.md index 283ccf6..a05d8a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/src/Domain/Lang/DocommentDomainCSharp.ts b/src/Domain/Lang/DocommentDomainCSharp.ts index 6b0f96d..905c3d6 100644 --- a/src/Domain/Lang/DocommentDomainCSharp.ts +++ b/src/Domain/Lang/DocommentDomainCSharp.ts @@ -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 { @@ -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; } diff --git a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts index 34cea71..759626e 100644 --- a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts +++ b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts @@ -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 { @@ -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)); } } @@ -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 {