Skip to content

Commit 3ee496e

Browse files
author
Keisuke KATO
authored
Merge pull request #21 from k--kato/#16
Fixed Expansion is triggering in a lot of cases when it shouldn't #16
2 parents 39acaaf + bad425c commit 3ee496e

File tree

8 files changed

+67
-22
lines changed

8 files changed

+67
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 0.0.9 (December 11, 2016)
4+
5+
* 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).
6+
37
## 0.0.8 (December 2, 2016)
48

59
* bug fix - Adds extra param for `Func<T, bool>`. See [#19](https://github.com/k--kato/vscode-docomment/issues/19).

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 VSCode-Extension
3+
Copyright (c) 2016 Keisuke Kato
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# XML Documentation Comments Support for Visual Studio Code
22

3-
[![Build Status](https://travis-ci.org/k--kato/vscode-docomment.svg?branch=master)](https://travis-ci.org/k--kato/vscode-docomment)
4-
[![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)
5-
[![License: MIT](http://img.shields.io/badge/license-MIT-orange.svg)](LICENSE)
3+
[![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)
64

75
Generate XML documentation comments for Visual Studio Code.
86

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

3533
## Installation
3634

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

4441

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

72+
## Contributors
73+
74+
* [@ivanz](https://github.com/ivanz)
75+
7576

7677
## License
7778

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "docomment",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"publisher": "k--kato",
55
"engines": {
6-
"vscode": "^1.7.x"
6+
"vscode": "^1.7.0"
77
},
88
"displayName": "C# XML Documentation Comments",
99
"description": "Generate C# XML documentation comments for ///",

src/Api/VSCodeApi.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TextEditor, Position, Selection, window} from 'vscode';
1+
import {TextEditor, Position, Selection, TextDocumentContentChangeEvent} from 'vscode';
22
import {StringUtil} from '../Utility/StringUtil';
33

44
export class VSCodeApi {
@@ -24,6 +24,11 @@ export class VSCodeApi {
2424
return (this._activeEditor.document.languageId === languageId);
2525
}
2626

27+
public IsEmptyContentChanges(event: TextDocumentContentChangeEvent): boolean {
28+
return event.text === null || event.text === '';
29+
}
30+
31+
2732
public GetActivePosition(): Position {
2833
return this._activeEditor.selection.active;
2934
}
@@ -153,4 +158,20 @@ export class VSCodeApi {
153158
return null;
154159
}
155160

161+
public ReadNextLineFromCurrent(): string {
162+
const lineCount: number = this.GetLineCount();
163+
const curLine: number = this.GetActiveLine();
164+
165+
for (let i: number = curLine; i < lineCount - 1; i++) {
166+
167+
// Skip empty line
168+
const line: string = this.ReadLine(i + 1);
169+
if (StringUtil.IsNullOrWhiteSpace(line)) continue;
170+
171+
return line;
172+
}
173+
174+
return null;
175+
}
176+
156177
}

src/Domain/Lang/DocommentDomainCSharp.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export class DocommentDomainCSharp extends DocommentDomain {
1919
/* @override */
2020
public IsTriggerDocomment(): boolean {
2121

22+
// NG: KeyCode is EMPTY
23+
const isEmpty: boolean = this._vsCodeApi.IsEmptyContentChanges(this._event);
24+
if (isEmpty) return false;
25+
2226
// NG: KeyCode is NOT '/' or Enter
2327
const activeChar: string = this._vsCodeApi.ReadCharAtCurrent();
2428
if (activeChar == null) return false;
@@ -36,16 +40,15 @@ export class DocommentDomainCSharp extends DocommentDomain {
3640
// NG: Line is NOT /// (NG: ////)
3741
const activeLine: string = this._vsCodeApi.ReadLineAtCurrent();
3842
if (activeLine == null) return false;
43+
3944
if (isSlashKey) {
40-
const isDocComment: boolean = SyntacticAnalysisCSharp.IsDocCommentStrict(activeLine);
41-
if (!isDocComment) return false;
45+
if (!SyntacticAnalysisCSharp.IsDocCommentStrict(activeLine)) return false;
4246

4347
// NG: '/' => Insert => Event => ' /// '
4448
if (SyntacticAnalysisCSharp.IsDoubleDocComment(activeLine)) return false;
4549
}
4650
if (this._isEnterKey) {
47-
const isDocComment: boolean = SyntacticAnalysisCSharp.IsDocComment(activeLine);
48-
if (!isDocComment) return false;
51+
if (!SyntacticAnalysisCSharp.IsDocComment(activeLine)) return false;
4952
}
5053

5154
// NG: Position is NOT ///
@@ -146,7 +149,7 @@ export class DocommentDomainCSharp extends DocommentDomain {
146149
case CodeType.Comment:
147150
return '/// ';
148151
case CodeType.None:
149-
return ''
152+
return '';
150153
default:
151154
return '';
152155
}
@@ -170,7 +173,7 @@ export class DocommentDomainCSharp extends DocommentDomain {
170173
const replaceSelection = this._vsCodeApi.GetSelectionByPosition(anchor, active);
171174
this._vsCodeApi.ReplaceText(replaceSelection, docomment);
172175
} else {
173-
const insertPosition: Position = this._vsCodeApi.ShiftPositionChar(position, 1)
176+
const insertPosition: Position = this._vsCodeApi.ShiftPositionChar(position, 1);
174177
this._vsCodeApi.InsertText(insertPosition, docomment);
175178
}
176179
}

src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export class SyntacticAnalysisCSharp {
2222
}
2323

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

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

3232
/*-------------------------------------------------------------------------
@@ -84,6 +84,7 @@ export class SyntacticAnalysisCSharp {
8484

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

@@ -97,13 +98,10 @@ export class SyntacticAnalysisCSharp {
9798
let paramName: Array<string> = new Array<string>();
9899
params[1].split(',').forEach(param => {
99100
const hasOptionalParam: boolean = param.match(/\S+\s+\S+\s*=/) !== null;
100-
const hasGenericParam: boolean = param.match(/[<]/) !== null;
101101
const hasTypeInfo: boolean = param.match(/[\w\W]+\s+[\w\W]+/) !== null;
102102
let name: RegExpMatchArray = null;
103103
if (hasOptionalParam) {
104104
name = param.match(/\S+\s+(\S+)\s*=.*/);
105-
} else if (hasGenericParam) {
106-
name = null; // SKIP
107105
} else if (!hasTypeInfo) {
108106
name = null; // SKIP
109107
} else {

test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,22 @@ suite('SyntacticAnalysis.SyntacticAnalysisCSharp.IsClass Tests', () => {
208208
assert.equal(actual[1], 'onComplete');
209209
});
210210

211+
test(`
212+
Category: Black-box testing
213+
Class : SyntacticAnalysis.SyntacticAnalysisCSharp
214+
Method : IsDocComment
215+
`, () => {
216+
assert.equal(SyntacticAnalysisCSharp.IsDocComment('///'), true, '///');
217+
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' ///'), true, ' ///');
218+
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// '), true, ' /// ');
219+
220+
assert.equal(SyntacticAnalysisCSharp.IsDocComment('/// ///'), false, '/// ///');
221+
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// ///'), false, ' /// ///');
222+
assert.equal(SyntacticAnalysisCSharp.IsDocComment('//////'), false, '//////');
223+
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' //////'), false, ' //////');
224+
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /////'), false, ' /////');
225+
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// //'), false, ' /// //');
226+
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' //// ///'), false, ' //// ///');
227+
assert.equal(SyntacticAnalysisCSharp.IsDocComment(' /// <bla>'), false, '\' /// <bla>\'');
228+
});
211229
});

0 commit comments

Comments
 (0)