From 5b2815a9033ea98a39c02e0155148bf493e6a2a6 Mon Sep 17 00:00:00 2001 From: kasecato Date: Sun, 24 Feb 2019 09:39:21 +0900 Subject: [PATCH] Improved activation on enter #75 --- CHANGELOG.md | 4 ++++ README.md | 3 ++- src/Domain/Lang/DocommentDomainCSharp.ts | 12 ++++++++++-- src/Formatter/FormatterCSharp.ts | 9 ++++++--- src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts | 13 ++++++++++++- test/TestData/.vscode/settings.json | 4 +++- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 546f881..af04c8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 0.1.6 (Feb 24, 2019) + +* bug fix - Support delimited comment syntax /** */? See [#75](https://github.com/kasecato/vscode-docomment/issues/75). + ## 0.1.5 (Feb 23, 2019) * bug fix - Support delimited comment syntax /** */? See [#75](https://github.com/kasecato/vscode-docomment/issues/75). diff --git a/README.md b/README.md index bbeed65..917cf0f 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ The menu under File > Preferences (Code > Preferences on Mac) provides entries t ```js { - // Comments are single-line comments that start with three slashes (///) ("single"), or delimited comments that start with a slash and two stars (/**) ("delimited"). + // single: Comments are single-line comments that start with three slashes (///) (Default) + // delimited: Delimited comments that start with a slash and two stars (/**) "docomment.syntax": "single", // Press the Enter key to activate a command (Default: false) "docomment.activateOnEnter": false, diff --git a/src/Domain/Lang/DocommentDomainCSharp.ts b/src/Domain/Lang/DocommentDomainCSharp.ts index 9ed7ce6..a2ffec9 100644 --- a/src/Domain/Lang/DocommentDomainCSharp.ts +++ b/src/Domain/Lang/DocommentDomainCSharp.ts @@ -61,9 +61,17 @@ export class DocommentDomainCSharp extends DocommentDomain { return false; } } + + // Comment Line if (isEnterKey) { + if (this._config.activateOnEnter) { + // NG: '////' + if (!SyntacticAnalysisCSharp.IsDocCommentOnActivationEnter(activeLine, this._config.syntax)) { + return false; + } + } // NG: '////' - if (!SyntacticAnalysisCSharp.IsDocComment(activeLine, this._config.syntax)) { + else if (!SyntacticAnalysisCSharp.IsDocComment(activeLine, this._config.syntax)) { return false; } } @@ -258,7 +266,7 @@ export class DocommentDomainCSharp extends DocommentDomain { // Format const indentBaseLine: string = this._vsCodeApi.ReadLineAtCurrent(); const indent: string = StringUtil.GetIndent(code, indentBaseLine, this._config.insertSpaces, this._config.detectIdentation); - const docomment: string = FormatterCSharp.Format(docommentList, indent, this._config.syntax); + const docomment: string = FormatterCSharp.Format(docommentList, indent, this._config.syntax, this._config.activateOnEnter); return docomment; } diff --git a/src/Formatter/FormatterCSharp.ts b/src/Formatter/FormatterCSharp.ts index b543d18..8a0e1ed 100644 --- a/src/Formatter/FormatterCSharp.ts +++ b/src/Formatter/FormatterCSharp.ts @@ -6,12 +6,12 @@ export class FormatterCSharp { /*------------------------------------------------------------------------- * Public Method: Formatter *-----------------------------------------------------------------------*/ - public static Format(docommentList: string[], indent: string, syntax: CommentSyntax) { + public static Format(docommentList: string[], indent: string, syntax: CommentSyntax, activateOnEnter: boolean) { switch (syntax) { case CommentSyntax.single: return FormatterCSharp.FormatAsSingle(docommentList, indent, syntax); case CommentSyntax.delimited: - return FormatterCSharp.FormatAsDelimited(docommentList, indent, syntax); + return FormatterCSharp.FormatAsDelimited(docommentList, indent, syntax, activateOnEnter); } } @@ -29,7 +29,7 @@ export class FormatterCSharp { return docomment; } - private static FormatAsDelimited(docommentList: string[], indent: string, syntax: CommentSyntax) { + private static FormatAsDelimited(docommentList: string[], indent: string, syntax: CommentSyntax, activateOnEnter: boolean) { let docomment = '\n'; for (let i = 0; i < docommentList.length; i++) { docomment += indent + ' ' + SyntacticAnalysisCSharp.GetCommentSyntax(syntax) + ' ' + docommentList[i]; @@ -39,6 +39,9 @@ export class FormatterCSharp { } docomment += '\n'; docomment += indent; + if (activateOnEnter) { + docomment += ' */'; + } return docomment; } diff --git a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts index 99e5daa..7dd016a 100644 --- a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts +++ b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts @@ -1,5 +1,5 @@ -import { CommentSyntax } from "../Entity/Config/Contributes/Configuration"; import { CodeType } from "../Domain/IDocommentDomain"; +import { CommentSyntax } from "../Entity/Config/Contributes/Configuration"; export class SyntacticAnalysisCSharp { @@ -47,6 +47,16 @@ export class SyntacticAnalysisCSharp { } } + public static IsDocCommentOnActivationEnter(activeLine: string, syntax: CommentSyntax): boolean { + switch (syntax) { + case CommentSyntax.single: + return activeLine.match(/^[ \t]*\/{3} $/) !== null; + case CommentSyntax.delimited: + return activeLine.match(/^[ \t]*\/\*{2}[ \t]*$/) !== null + || SyntacticAnalysisCSharp.IsDocComment(activeLine, syntax); + } + } + public static IsDoubleDocComment(activeLine: string, syntax: CommentSyntax): boolean { switch (syntax) { case CommentSyntax.single: @@ -56,6 +66,7 @@ export class SyntacticAnalysisCSharp { } } + /*------------------------------------------------------------------------- * Public Method: Code *-----------------------------------------------------------------------*/ diff --git a/test/TestData/.vscode/settings.json b/test/TestData/.vscode/settings.json index ef9d283..f8772bc 100644 --- a/test/TestData/.vscode/settings.json +++ b/test/TestData/.vscode/settings.json @@ -1,6 +1,8 @@ // Place your settings in this file to overwrite default and user settings. { - "docomment.syntax": "delimited", + // single: Comments are single-line comments that start with three slashes (///) (Default) + // delimited: Delimited comments that start with a slash and two stars (/**) + "docomment.syntax": "single", // Press the Enter key to activate a command (Default: false) "docomment.activateOnEnter": false, "docomment.advanced": {