diff --git a/CHANGELOG.md b/CHANGELOG.md index c0f65e1..d946f6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. See [#19](https://github.com/k--kato/vscode-docomment/issues/19). diff --git a/LICENSE.txt b/LICENSE.txt index 049a433..dec291f 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -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 diff --git a/README.md b/README.md index 98986e4..a6a006c 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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 diff --git a/package.json b/package.json index f5accf4..f1388ff 100644 --- a/package.json +++ b/package.json @@ -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 ///", diff --git a/src/Api/VSCodeApi.ts b/src/Api/VSCodeApi.ts index 42636bf..fd4b3c4 100644 --- a/src/Api/VSCodeApi.ts +++ b/src/Api/VSCodeApi.ts @@ -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 { @@ -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; } @@ -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; + } + } diff --git a/src/Domain/Lang/DocommentDomainCSharp.ts b/src/Domain/Lang/DocommentDomainCSharp.ts index d9a1ec2..6787180 100644 --- a/src/Domain/Lang/DocommentDomainCSharp.ts +++ b/src/Domain/Lang/DocommentDomainCSharp.ts @@ -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; @@ -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 /// @@ -146,7 +149,7 @@ export class DocommentDomainCSharp extends DocommentDomain { case CodeType.Comment: return '/// '; case CodeType.None: - return '' + return ''; default: return ''; } @@ -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); } } diff --git a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts index 7e040cd..f44e14d 100644 --- a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts +++ b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts @@ -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; } /*------------------------------------------------------------------------- @@ -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; } @@ -97,13 +98,10 @@ export class SyntacticAnalysisCSharp { let paramName: Array = new Array(); 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 { diff --git a/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts b/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts index c7ff022..4cf1a91 100644 --- a/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts +++ b/test/SyntacticAnalysis/SyntacticAnalysisCSharp.test.ts @@ -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(' /// '), false, '\' /// \''); + }); });