Skip to content

Commit a11e798

Browse files
author
Keisuke KATO
committed
Merge pull request #5 from k--kato/add/snippets
add/snippets
2 parents 480fc89 + 1626339 commit a11e798

13 files changed

+182
-39
lines changed

.vscode/launch.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
1111
"stopOnEntry": false,
1212
"sourceMaps": true,
13-
"outDir": "out/src",
14-
"preLaunchTask": "npm"
13+
"outDir": "out/src"
1514
},
1615
{
1716
"name": "Launch Tests",
@@ -21,8 +20,7 @@
2120
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
2221
"stopOnEntry": false,
2322
"sourceMaps": true,
24-
"outDir": "out/test",
25-
"preLaunchTask": "npm"
23+
"outDir": "out/test"
2624
}
2725
]
2826
}

.vscode/tasks.json

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
"args": ["run"],
2323

2424
"tasks": [
25-
{
26-
"taskName": "npm"
27-
},
2825
{
2926
"taskName": "build",
3027
"suppressTaskName": true,

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 VSCode-Extension
3+
Copyright (c) 2016 VSCode-Extension
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# XML Documentation Comments Support for Visual Studio Code
22

3-
[![Build Status](https://travis-ci.org/k--kato/docomment.svg?branch=master)](https://travis-ci.org/k--kato/docomment)
4-
[![Coverage Status](https://coveralls.io/repos/k--kato/docomment/badge.svg?branch=master&service=github)](https://coveralls.io/github/k--kato/docomment?branch=master)
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)
55
[![License: MIT](http://img.shields.io/badge/license-MIT-orange.svg)](LICENSE)
66

77
Generate XML documentation comments for Visual Studio Code.
@@ -48,7 +48,7 @@ public int bb(string s, ref int y, void * z)
4848
Clone a copy of the repo:
4949

5050
```
51-
git clone https://github.com/k--kato/docomment.git
51+
git clone https://github.com/k--kato/vscode-docomment.git
5252
```
5353

5454
### Building the code

package.json

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "docomment",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"publisher": "k--kato",
55
"engines": {
66
"vscode": "^0.10.6"
77
},
88
"displayName": "C# XML Documentation Comments",
99
"description": "Generate C# XML documentation comments for ///",
1010
"categories": [
11+
"Snippets",
1112
"Other"
1213
],
1314
"galleryBanner": {
@@ -16,6 +17,12 @@
1617
},
1718
"main": "./out/src/extension",
1819
"contributes": {
20+
"snippets": [
21+
{
22+
"language": "csharp",
23+
"path": "./snippets/csharp.json"
24+
}
25+
]
1926
},
2027
"activationEvents": [
2128
"onLanguage:csharp"
@@ -27,12 +34,12 @@
2734
"dependencies": {
2835
},
2936
"devDependencies": {
30-
"typescript": "^1.6.2",
31-
"vscode": "0.10.x",
32-
"tslint": "^3.2.1",
37+
"typescript": "^1.7.5",
38+
"vscode": "^0.10.x",
39+
"tslint": "^3.3.0",
3340
"istanbul": "^0.4.2",
3441
"coveralls": "^2.11.6",
35-
"mocha": "^2.3.4",
42+
"mocha": "^2.4.5",
3643
"mocha-lcov-reporter": "^1.0.0"
3744
},
3845
"extensionDependencies": [
@@ -48,12 +55,12 @@
4855
},
4956
"icon": "images/docomment.png",
5057
"license": "MIT",
51-
"homepage": "https://github.com/k--kato/docomment#readme",
58+
"homepage": "https://github.com/k--kato/vscode-docomment#readme",
5259
"repository": {
5360
"type": "git",
54-
"url": "https://github.com/k--kato/docomment"
61+
"url": "https://github.com/k--kato/vscode-docomment"
5562
},
5663
"bugs": {
57-
"url": "https://github.com/k--kato/docomment/issues"
64+
"url": "https://github.com/k--kato/vscode-docomment/issues"
5865
}
5966
}

snippets/csharp.json

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
".source.charp": {
3+
"c": {
4+
"prefix": "<c>",
5+
"body": [ "<c>${text}</c>"],
6+
"description": "The <c> tag gives you a way to indicate that text within a description should be marked as code.Use <code> to indicate multiple lines as code."
7+
},
8+
"code": {
9+
"prefix": "<code>",
10+
"body": [ "<code>${content}</code>"],
11+
"description": "The <code> tag gives you a way to indicate multiple lines as code.Use <c> to indicate that text within a description should be marked as code."
12+
},
13+
"example": {
14+
"prefix": "<example>",
15+
"body": [ "<example>${description}</example>"],
16+
"description": "The <example> tag lets you specify an example of how to use a method or other library member.This commonly involves using the <code> tag."
17+
},
18+
"exception": {
19+
"prefix": "<exception>",
20+
"body": [ "<exception cref=\"${member}\">${description}</exception>"],
21+
"description": "The <exception> tag lets you specify which exceptions can be thrown.This tag can be applied to definitions for methods, properties, events, and indexers."
22+
},
23+
"include": {
24+
"prefix": "<include>",
25+
"body": [ "<include file='${filename}' path='${tagpath}[@name=\"${id}\"]' />"],
26+
"description": "The <include> tag lets you refer to comments in another file that describe the types and members in your source code."
27+
},
28+
"list": {
29+
"prefix": "<list>",
30+
"body": [ "<list type=\"${bullet}\"></list>"],
31+
"description": "The <listheader> 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."
32+
},
33+
"para": {
34+
"prefix": "<para>",
35+
"body": [ "<para>${content}</para>"],
36+
"description": "The <para> tag is for use inside a tag, such as <summary>, <remarks>, or <returns>, and lets you add structure to the text."
37+
},
38+
"param": {
39+
"prefix": "<param>",
40+
"body": [ "<param name=\"${name}\">${description}</param>"],
41+
"description": "The <param> 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 <param> tags."
42+
},
43+
"paramref": {
44+
"prefix": "<paramref>",
45+
"body": [ "<paramref name=\"${name}\"/>"],
46+
"description": "The <paramref> tag gives you a way to indicate that a word in the code comments, for example in a <summary> or <remarks> block refers to a parameter."
47+
},
48+
"permission": {
49+
"prefix": "<permission>",
50+
"body": [ "<permission cref=\"${member}\">${description}</permission>"],
51+
"description": "The <permission> tag lets you document the access of a member.The PermissionSet class lets you specify access to a member."
52+
},
53+
"remarks": {
54+
"prefix": "<remarks>",
55+
"body": [ "<remarks>${description}</remarks>"],
56+
"description": "The <remarks> tag is used to add information about a type, supplementing the information specified with <summary>."
57+
},
58+
"returns": {
59+
"prefix": "<returns>",
60+
"body": [ "<returns>${description}</returns>"],
61+
"description": "The <returns> tag should be used in the comment for a method declaration to describe the return value."
62+
},
63+
"see": {
64+
"prefix": "<see>",
65+
"body": [ "<see cref=\"${member}\"/>"],
66+
"description": "The <see> tag lets you specify a link from within text.Use <seealso> to indicate that text should be placed in a See Also section."
67+
},
68+
"seealso": {
69+
"prefix": "<seealso>",
70+
"body": [ "<seealso cref=\"${member}\"/>"],
71+
"description": "The <seealso> tag lets you specify the text that you might want to appear in a See Also section.Use <see> to specify a link from within text."
72+
},
73+
"summary": {
74+
"prefix": "<summary>",
75+
"body": [ "<summary>${description}</summary>"],
76+
"description": "The <summary> tag should be used to describe a type or a type member.Use <remarks> to add supplemental information to a type description."
77+
},
78+
"typeparam": {
79+
"prefix": "<typeparam>",
80+
"body": [ "<typeparam name=\"${name}\">${description}</typeparam>"],
81+
"description": "The <typeparam> tag should be used in the comment for a generic type or method declaration to describe a type parameter."
82+
},
83+
"typeparamref": {
84+
"prefix": "<typeparamref>",
85+
"body": [ "<typeparamref name=\"${name}\"/>"],
86+
"description": "Use this tag to enable consumers of the documentation file to format the word in some distinct way, for example in italics."
87+
},
88+
"value": {
89+
"prefix": "<value>",
90+
"body": [ "<value>${property-description}</value>"],
91+
"description": "The <value> tag lets you describe the value that a property represents."
92+
}
93+
}
94+
}

src/Api/VSCodeApi.ts

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

44
export class VSCodeApi {

src/Domain/DocommentDomain.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ export class DocommentDomain implements IDocommentDomain {
4545
if (codeType === null) return;
4646

4747
// Gene Comment
48-
const docomment = this.GeneDocomment(codeType, code);
48+
const docomment = this.GeneDocomment(code, codeType);
4949
console.log(docomment);
5050
if (StringUtil.IsNullOrWhiteSpace(docomment)) return;
5151

5252
// Write Comment
53-
this.WriteDocomment(docomment);
53+
this.WriteDocomment(code, codeType, docomment);
5454

5555
// Move Cursor to <Summary>
56-
this.MoveCursorTo(docomment);
56+
this.MoveCursorTo(code, codeType, docomment);
5757

5858
}
5959

@@ -73,19 +73,17 @@ export class DocommentDomain implements IDocommentDomain {
7373
}
7474

7575
/* @implements */
76-
public GeneDocomment(codeType: CodeType, code: string): string {
76+
public GeneDocomment(code: string, codeType: CodeType): string {
7777
return null;
7878
}
7979

8080
/* @implements */
81-
public WriteDocomment(docommnet: string): void {
82-
const position: Position = this._vsCodeApi.GetActivePosition();
83-
const shiftChar = this._vsCodeApi.ShiftPositionChar(position, 1);
84-
this._vsCodeApi.InsertText(shiftChar, docommnet);
81+
public WriteDocomment(code: string, codeType: CodeType, docommnet: string): void {
82+
// NOP
8583
}
8684

8785
/* @implements */
88-
public MoveCursorTo(docomment: string): void {
86+
public MoveCursorTo(code: string, codeType: CodeType, docomment: string): void {
8987
// NOP
9088
}
9189

src/Domain/IDocommentDomain.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {VSCodeApi} from '../Api/VSCodeApi';
66
*-----------------------------------------------------------------------*/
77
export enum CodeType {
88
None,
9+
Comment,
910
Namespace,
1011
Class,
1112
Interface,
@@ -39,9 +40,9 @@ export interface IDocommentDomain {
3940
*-----------------------------------------------------------------------*/
4041
IsTriggerDocomment(): boolean;
4142
GetCodeType(code: string): CodeType;
42-
GeneDocomment(codeType: CodeType, code: string): string;
43-
WriteDocomment(docommnet: string): void;
44-
MoveCursorTo(docommnet: string): void;
43+
GeneDocomment(code: string, codeType: CodeType): string;
44+
WriteDocomment(code: string, codeType: CodeType, docommnet: string): void;
45+
MoveCursorTo(code: string, codeType: CodeType, docommnet: string): void;
4546
dispose(): void;
4647

4748
}

src/Domain/Lang/DocommentDomainCSharp.ts

+44-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {SyntacticAnalysisCSharp} from '../../SyntacticAnalysis/SyntacticAnalysis
22
import {StringUtil} from '../../Utility/StringUtil';
33
import {DocommentDomain} from '../DocommentDomain';
44
import {CodeType} from '../IDocommentDomain';
5+
import {Position} from 'vscode';
56

67
export class DocommentDomainCSharp extends DocommentDomain {
78

@@ -23,8 +24,20 @@ export class DocommentDomainCSharp extends DocommentDomain {
2324
// NG: Line is NOT /// (NG: ////)
2425
const activeLine: string = this._vsCodeApi.ReadLineAtCurrent();
2526
if (activeLine == null) return false;
26-
const isDocComment: boolean = (activeLine.match(/(?:[^/]\/{3}$)|(?:^\/{3}[^/])|(?:^\/{3}$)/) !== null); // fixme: to simple
27-
if (!isDocComment) return false;
27+
28+
if (isSlashKey) {
29+
const isDocComment: boolean = (activeLine.match(/(?:[^/]\/{3}$)|(?:^\/{3}[^/])|(?:^\/{3}$)/) !== null); // fixme: to simple
30+
if (!isDocComment) return false;
31+
}
32+
if (isEnterKey) {
33+
const isDocComment: boolean = (activeLine.match(/\/{3}/) !== null);
34+
if (!isDocComment) return false;
35+
36+
const nextLine = this._vsCodeApi.ReadLine(this._vsCodeApi.GetActiveLine() + 2);
37+
if (!nextLine.match(/\/{3}/)) return false;
38+
39+
return true;
40+
}
2841

2942
// NG: Position is NOT ///
3043
const position: number = this._vsCodeApi.GetActiveCharPosition();
@@ -84,11 +97,14 @@ export class DocommentDomainCSharp extends DocommentDomain {
8497
/* method */
8598
if (SyntacticAnalysisCSharp.IsMethod(code)) return CodeType.Method;
8699

100+
/* comment */
101+
if (SyntacticAnalysisCSharp.IsComment(code)) return CodeType.Comment;
102+
87103
return CodeType.None;
88104
}
89105

90106
/* @override */
91-
public GeneDocomment(codeType: CodeType, code: string): string {
107+
public GeneDocomment(code: string, codeType: CodeType): string {
92108

93109
let paramNameList: Array<string> = null;
94110
let hasReturn = false;
@@ -118,8 +134,10 @@ export class DocommentDomainCSharp extends DocommentDomain {
118134
case CodeType.Property:
119135
hasReturn = SyntacticAnalysisCSharp.HasPropertyReturn(code);
120136
break;
137+
case CodeType.Comment:
138+
return '/// ';
121139
case CodeType.None:
122-
return '';
140+
return ''
123141
default:
124142
return '';
125143
}
@@ -128,9 +146,29 @@ export class DocommentDomainCSharp extends DocommentDomain {
128146
}
129147

130148
/* @implements */
131-
public MoveCursorTo(docomment: string): void {
149+
public WriteDocomment(code: string, codeType: CodeType, docommnet: string): void {
150+
const position: Position = this._vsCodeApi.GetActivePosition();
151+
152+
if (codeType === CodeType.Comment) {
153+
const indentLen: number = StringUtil.GetIndent(code).length;
154+
const insertPosition: Position = this._vsCodeApi.GetPosition(position.line + 1, indentLen);
155+
this._vsCodeApi.InsertText(insertPosition, docommnet);
156+
} else {
157+
const insertPosition: Position = this._vsCodeApi.ShiftPositionChar(position, 1);
158+
this._vsCodeApi.InsertText(insertPosition, docommnet);
159+
}
160+
}
161+
162+
/* @implements */
163+
public MoveCursorTo(code: string, codeType: CodeType, docomment: string): void {
132164
const curPosition = this._vsCodeApi.GetActivePosition();
133-
this._vsCodeApi.MoveSelection(curPosition.line + 1, curPosition.character + 2);
165+
166+
if (codeType === CodeType.Comment) {
167+
const indentLen: number = StringUtil.GetIndent(code).length;
168+
this._vsCodeApi.MoveSelection(curPosition.line + 1, indentLen + docomment.length);
169+
} else {
170+
this._vsCodeApi.MoveSelection(curPosition.line + 1, curPosition.character + 2);
171+
}
134172
}
135173

136174

src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export class SyntacticAnalysisCSharp {
6060
return code.match(/[\w\S]\s+[\w\S]+\s*\(.*\)/) !== null;
6161
}
6262

63+
public static IsComment(code: string): boolean {
64+
if (code === null) return false;
65+
return code.match(/[ ]+/) !== null;
66+
}
6367

6468
public static GetMethodParamNameList(code: string): Array<string> {
6569
if (code === null) return null;

test/TestData/coverageconfig.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"coverage": ["./coverage/coverage.json"],
3+
"sourcemapped": ["./out/src/*/**.js"],
4+
"automaticallyShow": true,
5+
"ignore": ["*.json"]
6+
}

0 commit comments

Comments
 (0)