Skip to content

Commit

Permalink
Merge pull request #17 from ivanz/fix-expansion
Browse files Browse the repository at this point in the history
Fixed: Expansion is triggering in a lot of cases when it shouldn't (#16)
  • Loading branch information
Keisuke KATO authored Jul 29, 2016
2 parents cc2f192 + 50ef1ba commit 07a5e86
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
15 changes: 15 additions & 0 deletions src/Api/VSCodeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,19 @@ 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;
}
}
25 changes: 7 additions & 18 deletions src/Domain/Lang/DocommentDomainCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,16 @@ 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;

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

// NG: Position is NOT ///
// const position: number = this._vsCodeApi.GetActiveCharPosition();
// const positionDocComment: number = activeLine.lastIndexOf('///') + ((isEnterKey) ? 3 : 2);
// const isLastPosition: boolean = (position === positionDocComment);
// if (!isLastPosition) return false;
const previousLine: string = this._vsCodeApi.ReadPreviousLineFromCurrent();
if (SyntacticAnalysisCSharp.IsDocComment(previousLine)) return false;

// NG: Previous line is XML document comment
// const previousLine: string = this._vsCodeApi.ReadPreviousLineFromCurrent();
// if (SyntacticAnalysisCSharp.IsDocComment(previousLine)) return false;
const nextLine: string = this._vsCodeApi.ReadNextLineFromCurrent();
if (SyntacticAnalysisCSharp.IsDocComment(nextLine)) return false;
}

// OK
return true;
Expand Down Expand Up @@ -86,7 +75,7 @@ export class DocommentDomainCSharp extends DocommentDomain {


/*-------------------------------------------------------------------------
*
*
*-----------------------------------------------------------------------*/
const isInMethod = false; // fixme:
if (isInMethod) return CodeType.None;
Expand Down
12 changes: 2 additions & 10 deletions src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@ export class SyntacticAnalysisCSharp {
return (activeChar === '/');
}

public static IsDocCommentStrict(activeLine: string): boolean {
return activeLine.match(/(?:[^/]\/{3}[ \t]*$)|(?:^\/{3}[^/])|(?:^\/{3}[ \t]*$)/) !== null; // fixme: to simple
}

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

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

/*-------------------------------------------------------------------------
Expand Down Expand Up @@ -97,7 +89,7 @@ export class SyntacticAnalysisCSharp {
let paramName: Array<string> = new Array<string>();
params[1].split(',').forEach(param => {
const hasOptionaParam: boolean = param.match(/\S+\s+\S+\s*=/) !== null;
const name: RegExpMatchArray = (hasOptionaParam)
const name: RegExpMatchArray = (hasOptionaParam)
? param.match(/\S+\s+(\S+)\s*=.*/)
: param.match(/(\S+)\s*$/);
if (name !== null && name.length === 2) {
Expand Down
20 changes: 20 additions & 0 deletions test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,24 @@ 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 07a5e86

Please sign in to comment.