Skip to content

Commit

Permalink
Improved activation on enter #75
Browse files Browse the repository at this point in the history
  • Loading branch information
kasecato committed Feb 24, 2019
1 parent 330709e commit 5b2815a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions src/Domain/Lang/DocommentDomainCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 6 additions & 3 deletions src/Formatter/FormatterCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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];
Expand All @@ -39,6 +39,9 @@ export class FormatterCSharp {
}
docomment += '\n';
docomment += indent;
if (activateOnEnter) {
docomment += ' */';
}
return docomment;
}

Expand Down
13 changes: 12 additions & 1 deletion src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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:
Expand All @@ -56,6 +66,7 @@ export class SyntacticAnalysisCSharp {
}
}


/*-------------------------------------------------------------------------
* Public Method: Code
*-----------------------------------------------------------------------*/
Expand Down
4 changes: 3 additions & 1 deletion test/TestData/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 5b2815a

Please sign in to comment.