Skip to content

Commit

Permalink
Revert "Fixed: Expansion is triggering in a lot of cases when it shou…
Browse files Browse the repository at this point in the history
…ldn't (#16)"
  • Loading branch information
Keisuke KATO authored Aug 4, 2016
1 parent 07a5e86 commit 87a33d1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 44 deletions.
15 changes: 0 additions & 15 deletions src/Api/VSCodeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,4 @@ 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: 18 additions & 7 deletions src/Domain/Lang/DocommentDomainCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,27 @@ export class DocommentDomainCSharp extends DocommentDomain {
// NG: Line is NOT /// (NG: ////)
const activeLine: string = this._vsCodeApi.ReadLineAtCurrent();
if (activeLine == null) return false;
if (isSlashKey || this._isEnterKey) {
if (isSlashKey) {
const isDocComment: boolean = SyntacticAnalysisCSharp.IsDocCommentStrict(activeLine);
if (!isDocComment) return false;

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

const previousLine: string = this._vsCodeApi.ReadPreviousLineFromCurrent();
if (SyntacticAnalysisCSharp.IsDocComment(previousLine)) 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 nextLine: string = this._vsCodeApi.ReadNextLineFromCurrent();
if (SyntacticAnalysisCSharp.IsDocComment(nextLine)) return false;
}
// NG: Previous line is XML document comment
// const previousLine: string = this._vsCodeApi.ReadPreviousLineFromCurrent();
// if (SyntacticAnalysisCSharp.IsDocComment(previousLine)) return false;

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


/*-------------------------------------------------------------------------
*
*
*-----------------------------------------------------------------------*/
const isInMethod = false; // fixme:
if (isInMethod) return CodeType.None;
Expand Down
12 changes: 10 additions & 2 deletions src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ 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(/^\s*?\/{3}\s*$/) !== null;
return activeLine.match(/\/{3}/) !== null;
}

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

/*-------------------------------------------------------------------------
Expand Down Expand Up @@ -89,7 +97,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: 0 additions & 20 deletions test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,4 @@ 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 87a33d1

Please sign in to comment.