Skip to content

Commit

Permalink
Merge pull request #5 from k--kato/add/snippets
Browse files Browse the repository at this point in the history
add/snippets
  • Loading branch information
Keisuke KATO committed Feb 7, 2016
2 parents 480fc89 + 1626339 commit a11e798
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 39 deletions.
6 changes: 2 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "out/src",
"preLaunchTask": "npm"
"outDir": "out/src"
},
{
"name": "Launch Tests",
Expand All @@ -21,8 +20,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "out/test",
"preLaunchTask": "npm"
"outDir": "out/test"
}
]
}
3 changes: 0 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
"args": ["run"],

"tasks": [
{
"taskName": "npm"
},
{
"taskName": "build",
"suppressTaskName": true,
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "docomment",
"version": "0.0.3",
"version": "0.0.4",
"publisher": "k--kato",
"engines": {
"vscode": "^0.10.6"
},
"displayName": "C# XML Documentation Comments",
"description": "Generate C# XML documentation comments for ///",
"categories": [
"Snippets",
"Other"
],
"galleryBanner": {
Expand All @@ -16,6 +17,12 @@
},
"main": "./out/src/extension",
"contributes": {
"snippets": [
{
"language": "csharp",
"path": "./snippets/csharp.json"
}
]
},
"activationEvents": [
"onLanguage:csharp"
Expand All @@ -27,12 +34,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": [
Expand All @@ -48,12 +55,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"
}
}
94 changes: 94 additions & 0 deletions snippets/csharp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
".source.charp": {
"c": {
"prefix": "<c>",
"body": [ "<c>${text}</c>"],
"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."
},
"code": {
"prefix": "<code>",
"body": [ "<code>${content}</code>"],
"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."
},
"example": {
"prefix": "<example>",
"body": [ "<example>${description}</example>"],
"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."
},
"exception": {
"prefix": "<exception>",
"body": [ "<exception cref=\"${member}\">${description}</exception>"],
"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."
},
"include": {
"prefix": "<include>",
"body": [ "<include file='${filename}' path='${tagpath}[@name=\"${id}\"]' />"],
"description": "The <include> tag lets you refer to comments in another file that describe the types and members in your source code."
},
"list": {
"prefix": "<list>",
"body": [ "<list type=\"${bullet}\"></list>"],
"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."
},
"para": {
"prefix": "<para>",
"body": [ "<para>${content}</para>"],
"description": "The <para> tag is for use inside a tag, such as <summary>, <remarks>, or <returns>, and lets you add structure to the text."
},
"param": {
"prefix": "<param>",
"body": [ "<param name=\"${name}\">${description}</param>"],
"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."
},
"paramref": {
"prefix": "<paramref>",
"body": [ "<paramref name=\"${name}\"/>"],
"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."
},
"permission": {
"prefix": "<permission>",
"body": [ "<permission cref=\"${member}\">${description}</permission>"],
"description": "The <permission> tag lets you document the access of a member.The PermissionSet class lets you specify access to a member."
},
"remarks": {
"prefix": "<remarks>",
"body": [ "<remarks>${description}</remarks>"],
"description": "The <remarks> tag is used to add information about a type, supplementing the information specified with <summary>."
},
"returns": {
"prefix": "<returns>",
"body": [ "<returns>${description}</returns>"],
"description": "The <returns> tag should be used in the comment for a method declaration to describe the return value."
},
"see": {
"prefix": "<see>",
"body": [ "<see cref=\"${member}\"/>"],
"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."
},
"seealso": {
"prefix": "<seealso>",
"body": [ "<seealso cref=\"${member}\"/>"],
"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."
},
"summary": {
"prefix": "<summary>",
"body": [ "<summary>${description}</summary>"],
"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."
},
"typeparam": {
"prefix": "<typeparam>",
"body": [ "<typeparam name=\"${name}\">${description}</typeparam>"],
"description": "The <typeparam> tag should be used in the comment for a generic type or method declaration to describe a type parameter."
},
"typeparamref": {
"prefix": "<typeparamref>",
"body": [ "<typeparamref name=\"${name}\"/>"],
"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": "<value>",
"body": [ "<value>${property-description}</value>"],
"description": "The <value> tag lets you describe the value that a property represents."
}
}
}
2 changes: 1 addition & 1 deletion src/Api/VSCodeApi.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
16 changes: 7 additions & 9 deletions src/Domain/DocommentDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Summary>
this.MoveCursorTo(docomment);
this.MoveCursorTo(code, codeType, docomment);

}

Expand All @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions src/Domain/IDocommentDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {VSCodeApi} from '../Api/VSCodeApi';
*-----------------------------------------------------------------------*/
export enum CodeType {
None,
Comment,
Namespace,
Class,
Interface,
Expand Down Expand Up @@ -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;

}
50 changes: 44 additions & 6 deletions src/Domain/Lang/DocommentDomainCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();
Expand Down Expand Up @@ -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<string> = null;
let hasReturn = false;
Expand Down Expand Up @@ -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 '';
}
Expand All @@ -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);
}
}


Expand Down
4 changes: 4 additions & 0 deletions src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
if (code === null) return null;
Expand Down
6 changes: 6 additions & 0 deletions test/TestData/coverageconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"coverage": ["./coverage/coverage.json"],
"sourcemapped": ["./out/src/*/**.js"],
"automaticallyShow": true,
"ignore": ["*.json"]
}
Loading

0 comments on commit a11e798

Please sign in to comment.