Skip to content

Commit

Permalink
Fixed Expansion is triggering in a lot of cases when it shouldn't #16
Browse files Browse the repository at this point in the history
  • Loading branch information
k--kato committed Dec 10, 2016
1 parent 39acaaf commit bad425c
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 22 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.0.9 (December 11, 2016)

* bug fix - Expansion is triggering in a lot of cases when it shouldn't . See [#16](https://github.com/k--kato/vscode-docomment/issues/16).

## 0.0.8 (December 2, 2016)

* bug fix - Adds extra param for `Func<T, bool>`. See [#19](https://github.com/k--kato/vscode-docomment/issues/19).
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 VSCode-Extension
Copyright (c) 2016 Keisuke Kato

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# XML Documentation Comments Support for Visual Studio Code

[![Build Status](https://travis-ci.org/k--kato/vscode-docomment.svg?branch=master)](https://travis-ci.org/k--kato/vscode-docomment)
[![Coverage Status](https://coveralls.io/repos/k--kato/vscode-docomment/badge.svg?branch=master&service=github)](https://coveralls.io/github/k--kato/vscode-docomment?branch=master)
[![License: MIT](http://img.shields.io/badge/license-MIT-orange.svg)](LICENSE)
[![Build Status](https://travis-ci.org/k--kato/vscode-docomment.svg?branch=master)](https://travis-ci.org/k--kato/vscode-docomment) [![Coverage Status](https://coveralls.io/repos/k--kato/vscode-docomment/badge.svg?branch=master&service=github)](https://coveralls.io/github/k--kato/vscode-docomment?branch=master) [![License: MIT](http://img.shields.io/badge/license-MIT-orange.svg)](LICENSE) [![Marketplace Version](http://vsmarketplacebadge.apphb.com/version/k--kato.docomment.svg)](https://marketplace.visualstudio.com/items?itemName=k--kato.docomment) [![Install](http://vsmarketplacebadge.apphb.com/installs-short/k--kato.docomment.svg)](https://marketplace.visualstudio.com/items?itemName=k--kato.docomment)

Generate XML documentation comments for Visual Studio Code.

Expand Down Expand Up @@ -34,11 +32,10 @@ The menu under File > Preferences (Code > Preferences on Mac) provides entries t

## Installation

1. Install Visual Studio Code 1.2.0 or higher
1. Install Visual Studio Code 1.7.0 or higher
1. Launch Code
1. From the command palette `Ctrl`-`Shift`-`P` (Windows, Linux) or `Cmd`-`Shift`-`P` (OSX)
1. Select `Install Extension`
1. Choose the extension '`docomment`' *or* run `ext install docomment`
1. From the extension view `Ctrl`-`Shift`-`X` (Windows, Linux) or `Cmd`-`Shift`-`X` (macOS)
1. Search and Choose the extension `C# XML Documentation Comments`
1. Reload Visual Studio Code


Expand Down Expand Up @@ -72,6 +69,10 @@ npm run compile
After the initial compile, the source files will be watched and recompiled
when changes are saved.

## Contributors

* [@ivanz](https://github.com/ivanz)


## License

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "docomment",
"version": "0.0.8",
"version": "0.0.9",
"publisher": "k--kato",
"engines": {
"vscode": "^1.7.x"
"vscode": "^1.7.0"
},
"displayName": "C# XML Documentation Comments",
"description": "Generate C# XML documentation comments for ///",
Expand Down
23 changes: 22 additions & 1 deletion src/Api/VSCodeApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TextEditor, Position, Selection, window} from 'vscode';
import {TextEditor, Position, Selection, TextDocumentContentChangeEvent} from 'vscode';
import {StringUtil} from '../Utility/StringUtil';

export class VSCodeApi {
Expand All @@ -24,6 +24,11 @@ export class VSCodeApi {
return (this._activeEditor.document.languageId === languageId);
}

public IsEmptyContentChanges(event: TextDocumentContentChangeEvent): boolean {
return event.text === null || event.text === '';
}


public GetActivePosition(): Position {
return this._activeEditor.selection.active;
}
Expand Down Expand Up @@ -153,4 +158,20 @@ export class VSCodeApi {
return null;
}

public ReadNextLineFromCurrent(): string {
const lineCount: number = this.GetLineCount();
const curLine: number = this.GetActiveLine();

for (let i: number = curLine; i < lineCount - 1; i++) {

// Skip empty line
const line: string = this.ReadLine(i + 1);
if (StringUtil.IsNullOrWhiteSpace(line)) continue;

return line;
}

return null;
}

}
15 changes: 9 additions & 6 deletions src/Domain/Lang/DocommentDomainCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class DocommentDomainCSharp extends DocommentDomain {
/* @override */
public IsTriggerDocomment(): boolean {

// NG: KeyCode is EMPTY
const isEmpty: boolean = this._vsCodeApi.IsEmptyContentChanges(this._event);
if (isEmpty) return false;

// NG: KeyCode is NOT '/' or Enter
const activeChar: string = this._vsCodeApi.ReadCharAtCurrent();
if (activeChar == null) return false;
Expand All @@ -36,16 +40,15 @@ export class DocommentDomainCSharp extends DocommentDomain {
// NG: Line is NOT /// (NG: ////)
const activeLine: string = this._vsCodeApi.ReadLineAtCurrent();
if (activeLine == null) return false;

if (isSlashKey) {
const isDocComment: boolean = SyntacticAnalysisCSharp.IsDocCommentStrict(activeLine);
if (!isDocComment) return false;
if (!SyntacticAnalysisCSharp.IsDocCommentStrict(activeLine)) return false;

// NG: '/' => Insert => Event => ' /// '
if (SyntacticAnalysisCSharp.IsDoubleDocComment(activeLine)) return false;
}
if (this._isEnterKey) {
const isDocComment: boolean = SyntacticAnalysisCSharp.IsDocComment(activeLine);
if (!isDocComment) return false;
if (!SyntacticAnalysisCSharp.IsDocComment(activeLine)) return false;
}

// NG: Position is NOT ///
Expand Down Expand Up @@ -146,7 +149,7 @@ export class DocommentDomainCSharp extends DocommentDomain {
case CodeType.Comment:
return '/// ';
case CodeType.None:
return ''
return '';
default:
return '';
}
Expand All @@ -170,7 +173,7 @@ export class DocommentDomainCSharp extends DocommentDomain {
const replaceSelection = this._vsCodeApi.GetSelectionByPosition(anchor, active);
this._vsCodeApi.ReplaceText(replaceSelection, docomment);
} else {
const insertPosition: Position = this._vsCodeApi.ShiftPositionChar(position, 1)
const insertPosition: Position = this._vsCodeApi.ShiftPositionChar(position, 1);
this._vsCodeApi.InsertText(insertPosition, docomment);
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export class SyntacticAnalysisCSharp {
}

public static IsDocComment(activeLine: string): boolean {
return activeLine.match(/\/{3}/) !== null;
return activeLine.match(/^\s*?\/{3}\s*$/) !== null;
}

public static IsDoubleDocComment(activeLine: string): boolean {
return activeLine.match(/^[ \t]+\/{3} $/) !== null;
return activeLine.match(/^[ \t]*\/{3} $/) !== null;
}

/*-------------------------------------------------------------------------
Expand Down Expand Up @@ -84,6 +84,7 @@ export class SyntacticAnalysisCSharp {

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

Expand All @@ -97,13 +98,10 @@ export class SyntacticAnalysisCSharp {
let paramName: Array<string> = new Array<string>();
params[1].split(',').forEach(param => {
const hasOptionalParam: boolean = param.match(/\S+\s+\S+\s*=/) !== null;
const hasGenericParam: boolean = param.match(/[<]/) !== null;
const hasTypeInfo: boolean = param.match(/[\w\W]+\s+[\w\W]+/) !== null;
let name: RegExpMatchArray = null;
if (hasOptionalParam) {
name = param.match(/\S+\s+(\S+)\s*=.*/);
} else if (hasGenericParam) {
name = null; // SKIP
} else if (!hasTypeInfo) {
name = null; // SKIP
} else {
Expand Down
18 changes: 18 additions & 0 deletions test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,22 @@ suite('SyntacticAnalysis.SyntacticAnalysisCSharp.IsClass Tests', () => {
assert.equal(actual[1], 'onComplete');
});

test(`
Category: Black-box testing
Class : SyntacticAnalysis.SyntacticAnalysisCSharp
Method : IsDocComment
`, () => {
assert.equal(SyntacticAnalysisCSharp.IsDocComment('///'), true, '///');
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' ///'), true, ' ///');
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// '), true, ' /// ');

assert.equal(SyntacticAnalysisCSharp.IsDocComment('/// ///'), false, '/// ///');
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// ///'), false, ' /// ///');
assert.equal(SyntacticAnalysisCSharp.IsDocComment('//////'), false, '//////');
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' //////'), false, ' //////');
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /////'), false, ' /////');
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// //'), false, ' /// //');
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' //// ///'), false, ' //// ///');
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// <bla>'), false, '\' /// <bla>\'');
});
});

0 comments on commit bad425c

Please sign in to comment.