From fc5da954fcff829f57dce9a9d37699bb85f89c73 Mon Sep 17 00:00:00 2001 From: k--kato Date: Sun, 7 Feb 2016 20:41:02 +0900 Subject: [PATCH 1/4] add snippets --- .vscode/launch.json | 6 +- .vscode/tasks.json | 3 - package.json | 16 ++++-- snippets/csharp.json | 94 +++++++++++++++++++++++++++++++ test/TestData/coverageconfig.json | 6 ++ 5 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 snippets/csharp.json create mode 100644 test/TestData/coverageconfig.json diff --git a/.vscode/launch.json b/.vscode/launch.json index 08869ac..e282b14 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,8 +10,7 @@ "args": ["--extensionDevelopmentPath=${workspaceRoot}" ], "stopOnEntry": false, "sourceMaps": true, - "outDir": "out/src", - "preLaunchTask": "npm" + "outDir": "out/src" }, { "name": "Launch Tests", @@ -21,8 +20,7 @@ "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ], "stopOnEntry": false, "sourceMaps": true, - "outDir": "out/test", - "preLaunchTask": "npm" + "outDir": "out/test" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e703b23..2b8f0ef 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -22,9 +22,6 @@ "args": ["run"], "tasks": [ - { - "taskName": "npm" - }, { "taskName": "build", "suppressTaskName": true, diff --git a/package.json b/package.json index a801eef..739b643 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docomment", - "version": "0.0.3", + "version": "0.0.4", "publisher": "k--kato", "engines": { "vscode": "^0.10.6" @@ -16,6 +16,12 @@ }, "main": "./out/src/extension", "contributes": { + "snippets": [ + { + "language": "csharp", + "path": "./snippets/csharp.json" + } + ] }, "activationEvents": [ "onLanguage:csharp" @@ -27,12 +33,12 @@ "dependencies": { }, "devDependencies": { - "typescript": "^1.6.2", - "vscode": "0.10.x", - "tslint": "^3.2.1", + "typescript": "^1.7.5", + "vscode": "^0.10.x", + "tslint": "^3.3.0", "istanbul": "^0.4.2", "coveralls": "^2.11.6", - "mocha": "^2.3.4", + "mocha": "^2.4.5", "mocha-lcov-reporter": "^1.0.0" }, "extensionDependencies": [ diff --git a/snippets/csharp.json b/snippets/csharp.json new file mode 100644 index 0000000..69119de --- /dev/null +++ b/snippets/csharp.json @@ -0,0 +1,94 @@ +{ + ".source.charp": { + "c": { + "prefix": "", + "body": [ "${text}"], + "description": "The tag gives you a way to indicate that text within a description should be marked as code.Use to indicate multiple lines as code." + }, + "code": { + "prefix": "", + "body": [ "${content}"], + "description": "The tag gives you a way to indicate multiple lines as code.Use to indicate that text within a description should be marked as code." + }, + "example": { + "prefix": "", + "body": [ "${description}"], + "description": "The tag lets you specify an example of how to use a method or other library member.This commonly involves using the tag." + }, + "exception": { + "prefix": "", + "body": [ "${description}"], + "description": "The tag lets you specify which exceptions can be thrown.This tag can be applied to definitions for methods, properties, events, and indexers." + }, + "include": { + "prefix": "", + "body": [ ""], + "description": "The tag lets you refer to comments in another file that describe the types and members in your source code." + }, + "list": { + "prefix": "", + "body": [ ""], + "description": "The block is used to define the heading row of either a table or definition list.When defining a table, you only need to supply an entry for term in the heading." + }, + "para": { + "prefix": "", + "body": [ "${content}"], + "description": "The tag is for use inside a tag, such as , , or , and lets you add structure to the text." + }, + "param": { + "prefix": "", + "body": [ "${description}"], + "description": "The tag should be used in the comment for a method declaration to describe one of the parameters for the method.To document multiple parameters, use multiple tags." + }, + "paramref": { + "prefix": "", + "body": [ ""], + "description": "The tag gives you a way to indicate that a word in the code comments, for example in a or block refers to a parameter." + }, + "permission": { + "prefix": "", + "body": [ "${description}"], + "description": "The tag lets you document the access of a member.The PermissionSet class lets you specify access to a member." + }, + "remarks": { + "prefix": "", + "body": [ "${description}"], + "description": "The tag is used to add information about a type, supplementing the information specified with ." + }, + "returns": { + "prefix": "", + "body": [ "${description}"], + "description": "The tag should be used in the comment for a method declaration to describe the return value." + }, + "see": { + "prefix": "", + "body": [ ""], + "description": "The tag lets you specify a link from within text.Use to indicate that text should be placed in a See Also section." + }, + "seealso": { + "prefix": "", + "body": [ ""], + "description": "The tag lets you specify the text that you might want to appear in a See Also section.Use to specify a link from within text." + }, + "summary": { + "prefix": "", + "body": [ "${description}"], + "description": "The tag should be used to describe a type or a type member.Use to add supplemental information to a type description." + }, + "typeparam": { + "prefix": "", + "body": [ "${description}"], + "description": "The tag should be used in the comment for a generic type or method declaration to describe a type parameter." + }, + "typeparamref": { + "prefix": "", + "body": [ ""], + "description": "Use this tag to enable consumers of the documentation file to format the word in some distinct way, for example in italics." + }, + "value": { + "prefix": "", + "body": [ "${property-description}"], + "description": "The tag lets you describe the value that a property represents." + } + } +} \ No newline at end of file diff --git a/test/TestData/coverageconfig.json b/test/TestData/coverageconfig.json new file mode 100644 index 0000000..4106539 --- /dev/null +++ b/test/TestData/coverageconfig.json @@ -0,0 +1,6 @@ +{ + "coverage": ["./coverage/coverage.json"], + "sourcemapped": ["./out/src/*/**.js"], + "automaticallyShow": true, + "ignore": ["*.json"] +} From a1f05304d274211f381d8b7d9dfd1d4c9c359d29 Mon Sep 17 00:00:00 2001 From: k--kato Date: Sun, 7 Feb 2016 20:45:05 +0900 Subject: [PATCH 2/4] change repository name --- LICENSE.txt | 2 +- README.md | 6 +++--- package.json | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index a7f081e..049a433 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 VSCode-Extension +Copyright (c) 2016 VSCode-Extension 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 99b65e1..7307d40 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # XML Documentation Comments Support for Visual Studio Code -[![Build Status](https://travis-ci.org/k--kato/docomment.svg?branch=master)](https://travis-ci.org/k--kato/docomment) -[![Coverage Status](https://coveralls.io/repos/k--kato/docomment/badge.svg?branch=master&service=github)](https://coveralls.io/github/k--kato/docomment?branch=master) +[![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) Generate XML documentation comments for Visual Studio Code. @@ -48,7 +48,7 @@ public int bb(string s, ref int y, void * z) Clone a copy of the repo: ``` -git clone https://github.com/k--kato/docomment.git +git clone https://github.com/k--kato/vscode-docomment.git ``` ### Building the code diff --git a/package.json b/package.json index 739b643..6854235 100644 --- a/package.json +++ b/package.json @@ -54,12 +54,12 @@ }, "icon": "images/docomment.png", "license": "MIT", - "homepage": "https://github.com/k--kato/docomment#readme", + "homepage": "https://github.com/k--kato/vscode-docomment#readme", "repository": { "type": "git", - "url": "https://github.com/k--kato/docomment" + "url": "https://github.com/k--kato/vscode-docomment" }, "bugs": { - "url": "https://github.com/k--kato/docomment/issues" + "url": "https://github.com/k--kato/vscode-docomment/issues" } } \ No newline at end of file From cc1d314f2afa38656d1b6216bdf61c90bb745bf3 Mon Sep 17 00:00:00 2001 From: k--kato Date: Sun, 7 Feb 2016 23:38:19 +0900 Subject: [PATCH 3/4] add return key --- src/Api/VSCodeApi.ts | 2 +- src/Domain/DocommentDomain.ts | 16 +++--- src/Domain/IDocommentDomain.ts | 7 +-- src/Domain/Lang/DocommentDomainCSharp.ts | 50 ++++++++++++++++--- .../SyntacticAnalysisCSharp.ts | 4 ++ tsconfig.json | 2 +- 6 files changed, 61 insertions(+), 20 deletions(-) diff --git a/src/Api/VSCodeApi.ts b/src/Api/VSCodeApi.ts index 3f3d795..270eb01 100644 --- a/src/Api/VSCodeApi.ts +++ b/src/Api/VSCodeApi.ts @@ -1,4 +1,4 @@ -import {TextEditor, Position, Selection} from 'vscode'; +import {TextEditor, Position, Selection, window} from 'vscode'; import {StringUtil} from '../Utility/StringUtil'; export class VSCodeApi { diff --git a/src/Domain/DocommentDomain.ts b/src/Domain/DocommentDomain.ts index 43747d6..4c36ffc 100644 --- a/src/Domain/DocommentDomain.ts +++ b/src/Domain/DocommentDomain.ts @@ -45,15 +45,15 @@ export class DocommentDomain implements IDocommentDomain { if (codeType === null) return; // Gene Comment - const docomment = this.GeneDocomment(codeType, code); + const docomment = this.GeneDocomment(code, codeType); console.log(docomment); if (StringUtil.IsNullOrWhiteSpace(docomment)) return; // Write Comment - this.WriteDocomment(docomment); + this.WriteDocomment(code, codeType, docomment); // Move Cursor to - this.MoveCursorTo(docomment); + this.MoveCursorTo(code, codeType, docomment); } @@ -73,19 +73,17 @@ export class DocommentDomain implements IDocommentDomain { } /* @implements */ - public GeneDocomment(codeType: CodeType, code: string): string { + public GeneDocomment(code: string, codeType: CodeType): string { return null; } /* @implements */ - public WriteDocomment(docommnet: string): void { - const position: Position = this._vsCodeApi.GetActivePosition(); - const shiftChar = this._vsCodeApi.ShiftPositionChar(position, 1); - this._vsCodeApi.InsertText(shiftChar, docommnet); + public WriteDocomment(code: string, codeType: CodeType, docommnet: string): void { + // NOP } /* @implements */ - public MoveCursorTo(docomment: string): void { + public MoveCursorTo(code: string, codeType: CodeType, docomment: string): void { // NOP } diff --git a/src/Domain/IDocommentDomain.ts b/src/Domain/IDocommentDomain.ts index c2f3914..ce27e1f 100644 --- a/src/Domain/IDocommentDomain.ts +++ b/src/Domain/IDocommentDomain.ts @@ -6,6 +6,7 @@ import {VSCodeApi} from '../Api/VSCodeApi'; *-----------------------------------------------------------------------*/ export enum CodeType { None, + Comment, Namespace, Class, Interface, @@ -39,9 +40,9 @@ export interface IDocommentDomain { *-----------------------------------------------------------------------*/ IsTriggerDocomment(): boolean; GetCodeType(code: string): CodeType; - GeneDocomment(codeType: CodeType, code: string): string; - WriteDocomment(docommnet: string): void; - MoveCursorTo(docommnet: string): void; + GeneDocomment(code: string, codeType: CodeType): string; + WriteDocomment(code: string, codeType: CodeType, docommnet: string): void; + MoveCursorTo(code: string, codeType: CodeType, docommnet: string): void; dispose(): void; } diff --git a/src/Domain/Lang/DocommentDomainCSharp.ts b/src/Domain/Lang/DocommentDomainCSharp.ts index 97560d2..0274d6c 100644 --- a/src/Domain/Lang/DocommentDomainCSharp.ts +++ b/src/Domain/Lang/DocommentDomainCSharp.ts @@ -2,6 +2,7 @@ import {SyntacticAnalysisCSharp} from '../../SyntacticAnalysis/SyntacticAnalysis import {StringUtil} from '../../Utility/StringUtil'; import {DocommentDomain} from '../DocommentDomain'; import {CodeType} from '../IDocommentDomain'; +import {Position} from 'vscode'; export class DocommentDomainCSharp extends DocommentDomain { @@ -23,8 +24,20 @@ export class DocommentDomainCSharp extends DocommentDomain { // NG: Line is NOT /// (NG: ////) const activeLine: string = this._vsCodeApi.ReadLineAtCurrent(); if (activeLine == null) return false; - const isDocComment: boolean = (activeLine.match(/(?:[^/]\/{3}$)|(?:^\/{3}[^/])|(?:^\/{3}$)/) !== null); // fixme: to simple - if (!isDocComment) return false; + + if (isSlashKey) { + const isDocComment: boolean = (activeLine.match(/(?:[^/]\/{3}$)|(?:^\/{3}[^/])|(?:^\/{3}$)/) !== null); // fixme: to simple + if (!isDocComment) return false; + } + if (isEnterKey) { + const isDocComment: boolean = (activeLine.match(/\/{3}/) !== null); + if (!isDocComment) return false; + + const nextLine = this._vsCodeApi.ReadLine(this._vsCodeApi.GetActiveLine() + 2); + if (!nextLine.match(/\/{3}/)) return false; + + return true; + } // NG: Position is NOT /// const position: number = this._vsCodeApi.GetActiveCharPosition(); @@ -84,11 +97,14 @@ export class DocommentDomainCSharp extends DocommentDomain { /* method */ if (SyntacticAnalysisCSharp.IsMethod(code)) return CodeType.Method; + /* comment */ + if (SyntacticAnalysisCSharp.IsComment(code)) return CodeType.Comment; + return CodeType.None; } /* @override */ - public GeneDocomment(codeType: CodeType, code: string): string { + public GeneDocomment(code: string, codeType: CodeType): string { let paramNameList: Array = null; let hasReturn = false; @@ -118,8 +134,10 @@ export class DocommentDomainCSharp extends DocommentDomain { case CodeType.Property: hasReturn = SyntacticAnalysisCSharp.HasPropertyReturn(code); break; + case CodeType.Comment: + return '/// '; case CodeType.None: - return ''; + return '' default: return ''; } @@ -128,9 +146,29 @@ export class DocommentDomainCSharp extends DocommentDomain { } /* @implements */ - public MoveCursorTo(docomment: string): void { + public WriteDocomment(code: string, codeType: CodeType, docommnet: string): void { + const position: Position = this._vsCodeApi.GetActivePosition(); + + if (codeType === CodeType.Comment) { + const indentLen: number = StringUtil.GetIndent(code).length; + const insertPosition: Position = this._vsCodeApi.GetPosition(position.line + 1, indentLen); + this._vsCodeApi.InsertText(insertPosition, docommnet); + } else { + const insertPosition: Position = this._vsCodeApi.ShiftPositionChar(position, 1); + this._vsCodeApi.InsertText(insertPosition, docommnet); + } + } + + /* @implements */ + public MoveCursorTo(code: string, codeType: CodeType, docomment: string): void { const curPosition = this._vsCodeApi.GetActivePosition(); - this._vsCodeApi.MoveSelection(curPosition.line + 1, curPosition.character + 2); + + if (codeType === CodeType.Comment) { + const indentLen: number = StringUtil.GetIndent(code).length; + this._vsCodeApi.MoveSelection(curPosition.line + 1, indentLen + docomment.length); + } else { + this._vsCodeApi.MoveSelection(curPosition.line + 1, curPosition.character + 2); + } } diff --git a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts index 2452ee2..76b482e 100644 --- a/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts +++ b/src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts @@ -60,6 +60,10 @@ export class SyntacticAnalysisCSharp { return code.match(/[\w\S]\s+[\w\S]+\s*\(.*\)/) !== null; } + public static IsComment(code: string): boolean { + if (code === null) return false; + return code.match(/[ ]+/) !== null; + } public static GetMethodParamNameList(code: string): Array { if (code === null) return null; diff --git a/tsconfig.json b/tsconfig.json index 4406699..5a3f246 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "module": "commonjs", - "target": "ES5", + "target": "es5", "outDir": "out", "noLib": true, "sourceMap": true From 1626339130d9d427d13513aa8baa782d56fe5bdf Mon Sep 17 00:00:00 2001 From: k--kato Date: Sun, 7 Feb 2016 23:39:17 +0900 Subject: [PATCH 4/4] add snippets --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 6854235..90ccacb 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "displayName": "C# XML Documentation Comments", "description": "Generate C# XML documentation comments for ///", "categories": [ + "Snippets", "Other" ], "galleryBanner": {