Skip to content

Commit

Permalink
Add user-controllable options #68
Browse files Browse the repository at this point in the history
  • Loading branch information
kasecato committed Jul 10, 2018
1 parent 310a03d commit 67966eb
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 45 deletions.
37 changes: 36 additions & 1 deletion README.md
Expand Up @@ -22,6 +22,41 @@ The menu under File > Preferences (Code > Preferences on Mac) provides entries t
{
// Press the Enter key to activate a command (Default: false)
"docomment.activateOnEnter": false,
// User-controllable options
"docomment.advanced": {
"cs": {
"namespace" : {
"attributes" : ["summary"]
},
"class" : {
"attributes" : ["summary", "typeparam"]
},
"interface" : {
"attributes" : ["summary", "typeparam"]
},
"struct" : {
"attributes" : ["summary"]
},
"enum" : {
"attributes" : ["summary"]
},
"delegate" : {
"attributes" : ["summary", "param", "typeparam", "returns"]
},
"field" : {
"attributes" : ["summary"]
},
"property" : {
"attributes" : ["summary", "value"]
},
"method" : {
"attributes" : ["summary", "param", "typeparam", "returns"]
},
"event" : {
"attributes" : ["summary"]
}
}
},
// Insert spaces when pressing Tab.
"editor.insertSpaces": true,
// The number of spaces a tab is equal to.
Expand All @@ -42,7 +77,7 @@ To enable publishing XML documentation:

## Installation

1. Install Visual Studio Code 1.22.0 or higher
1. Install Visual Studio Code 1.25.0 or higher
1. Launch Code
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`
Expand Down
154 changes: 153 additions & 1 deletion package.json
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.1",
"publisher": "k--kato",
"engines": {
"vscode": "^1.23.0"
"vscode": "^1.25.0"
},
"displayName": "C# XML Documentation Comments",
"description": "Generate C# XML documentation comments for ///",
Expand All @@ -24,6 +24,158 @@
"type": "boolean",
"default": false,
"description": "Press the Enter key to activate a command."
},
"docomment.advanced": {
"type": "object",
"description": "User-controllable options.",
"properties": {
"cs": {
"type": "object",
"description": "C# options.",
"properties": {
"namespace": {
"type": "object",
"properties": {
"attributes": {
"type": "array",
"default": ["summary"],
"items": {
"attribute": {
"type": "string"
}
}
}
}
},
"class": {
"type": "object",
"properties": {
"attributes": {
"type": "array",
"default": ["summary", "typeparam"],
"items": {
"attribute": {
"type": "string"
}
}
}
}
},
"interface": {
"type": "object",
"properties": {
"attributes": {
"type": "array",
"default": ["summary", "typeparam"],
"items": {
"attribute": {
"type": "string"
}
}
}
}
},
"struct": {
"type": "object",
"properties": {
"attributes": {
"type": "array",
"default": ["summary"],
"items": {
"attribute": {
"type": "string"
}
}
}
}
},
"enum": {
"type": "object",
"properties": {
"attributes": {
"type": "array",
"default": ["summary"],
"items": {
"attribute": {
"type": "string"
}
}
}
}
},
"delegate": {
"type": "object",
"properties": {
"attributes": {
"type": "array",
"default": ["summary", "param", "typeparam", "returns"],
"items": {
"attribute": {
"type": "string"
}
}
}
}
},
"field": {
"type": "object",
"properties": {
"attributes": {
"type": "array",
"default": ["summary", "value"],
"items": {
"attribute": {
"type": "string"
}
}
}
}
},
"property": {
"type": "object",
"properties": {
"attributes": {
"type": "array",
"default": ["summary", "value"],
"items": {
"attribute": {
"type": "string"
}
}
}
}
},
"method": {
"type": "object",
"properties": {
"attributes": {
"type": "array",
"default": ["summary", "param", "typeparam", "returns"],
"items": {
"attribute": {
"type": "string"
}
}
}
}
},
"event": {
"type": "object",
"properties": {
"attributes": {
"type": "array",
"default": ["summary"],
"items": {
"attribute": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Controller/DocommentController.ts
Expand Up @@ -68,6 +68,7 @@ export class DocommentController implements IDocommentController {

this._config = new Configuration();
this._config.activateOnEnter = confDocomment.get<boolean>(Configuration.ACTIVATE_ON_ENTER, false);
this._config.advanced = confDocomment.get<Object>(Configuration.ADVANCED);
this._config.eol = confFiles.get<string>(Configuration.EOL, '\n');
this._config.insertSpaces = confEditor.get<boolean>(Configuration.INSERT_SPACES, false);
this._config.detectIdentation = confEditor.get<boolean>(Configuration.DETECT_IDENTATION, true);
Expand Down
24 changes: 12 additions & 12 deletions src/Domain/IDocommentDomain.ts
Expand Up @@ -6,18 +6,18 @@ import {Configuration} from '../Entity/Config/Contributes/Configuration';
* Enum
*-----------------------------------------------------------------------*/
export enum CodeType {
None,
Comment,
Namespace,
Class,
Interface,
Struct,
Enum,
Delegate,
Field,
Property,
Method,
Event,
None = 'none',
Comment = 'comment',
Namespace = 'namespace',
Class = 'class',
Interface = 'interface',
Struct = 'struct',
Enum = 'enum',
Delegate = 'delegate',
Field = 'field',
Property = 'property',
Method = 'method',
Event = 'event',
}

export interface IDocommentDomain {
Expand Down
61 changes: 37 additions & 24 deletions src/Domain/Lang/DocommentDomainCSharp.ts
@@ -1,8 +1,9 @@
import {SyntacticAnalysisCSharp} from '../../SyntacticAnalysis/SyntacticAnalysisCSharp';
import {StringUtil} from '../../Utility/StringUtil';
import {DocommentDomain} from '../DocommentDomain';
import {CodeType} from '../IDocommentDomain';
import {Position} from 'vscode';
import { SyntacticAnalysisCSharp } from '../../SyntacticAnalysis/SyntacticAnalysisCSharp';
import { StringUtil } from '../../Utility/StringUtil';
import { DocommentDomain } from '../DocommentDomain';
import { CodeType } from '../IDocommentDomain';
import { Position } from 'vscode';
import { ConfigAdvancedCSharp, Attribute } from '../../Entity/Config/Lang/ConfigAdvancedCSharp';

export class DocommentDomainCSharp extends DocommentDomain {

Expand Down Expand Up @@ -169,7 +170,7 @@ export class DocommentDomainCSharp extends DocommentDomain {
return '';
}

return this.GeneSummary(code, genericList, paramNameList, hasReturn, hasValue);
return this.GeneSummary(code, codeType, genericList, paramNameList, hasReturn, hasValue);
}

/* @implements */
Expand Down Expand Up @@ -201,45 +202,57 @@ export class DocommentDomainCSharp extends DocommentDomain {
const indentBaseLine: string = this._vsCodeApi.ReadLineAtCurrent();
const indent: string = StringUtil.GetIndent(code, indentBaseLine, this._config.insertSpaces, this._config.detectIdentation);
const indentLen: number = StringUtil.GetIndentLen(indent, this._config.insertSpaces, this._config.detectIdentation);
this._vsCodeApi.MoveSelection(curPosition.line + 1, indentLen - 1 + docomment.length);
const line = curPosition.line + 1;
const character = indentLen - 1 + docomment.length;
this._vsCodeApi.MoveSelection(line, character);
}


/*-------------------------------------------------------------------------
* Private Method
*-----------------------------------------------------------------------*/

private GeneSummary(code: string, genericList: Array<string>, paramNameList: Array<string>, hasReturn: boolean, hasValue: boolean): string {
private GeneSummary(code: string, codeType: CodeType, genericList: Array<string>, paramNameList: Array<string>, hasReturn: boolean, hasValue: boolean): string {

let docommentList: Array<string> = new Array<string>();

/* <summary> */
docommentList.push('<summary>');
docommentList.push('');
docommentList.push('</summary>');
if (ConfigAdvancedCSharp.HasAttribute(this._config.advanced, codeType, Attribute.summary)) {
/* <summary> */
docommentList.push('<summary>');
docommentList.push('');
docommentList.push('</summary>');
}

/* <param> */
if (paramNameList !== null) {
paramNameList.forEach(name => {
docommentList.push('<param name="' + name + '"></param>');
});
if (ConfigAdvancedCSharp.HasAttribute(this._config.advanced, codeType, Attribute.param)) {
if (paramNameList !== null) {
paramNameList.forEach(name => {
docommentList.push('<param name="' + name + '"></param>');
});
}
}

/* <typeparam> */
if (genericList !== null) {
genericList.forEach(name => {
docommentList.push('<typeparam name="' + name + '"></typeparam>');
});
if (ConfigAdvancedCSharp.HasAttribute(this._config.advanced, codeType, Attribute.typeparam)) {
if (genericList !== null) {
genericList.forEach(name => {
docommentList.push('<typeparam name="' + name + '"></typeparam>');
});
}
}

/* <returns> */
if (hasReturn) {
docommentList.push('<returns></returns>');
if (ConfigAdvancedCSharp.HasAttribute(this._config.advanced, codeType, Attribute.returns)) {
if (hasReturn) {
docommentList.push('<returns></returns>');
}
}

/* <value> */
if (hasValue) {
docommentList.push('<value></value>');
if (ConfigAdvancedCSharp.HasAttribute(this._config.advanced, codeType, Attribute.value)) {
if (hasValue) {
docommentList.push('<value></value>');
}
}

// Format
Expand Down
16 changes: 9 additions & 7 deletions src/Entity/Config/Contributes/Configuration.ts
Expand Up @@ -3,23 +3,25 @@ export class Configuration {
/*-------------------------------------------------------------------------
* docomment
*-----------------------------------------------------------------------*/
public static KEY_DOCOMMENT: string = 'docomment';
public static ACTIVATE_ON_ENTER: string = 'activateOnEnter';
public static KEY_DOCOMMENT = 'docomment';
public static ACTIVATE_ON_ENTER = 'activateOnEnter';
public static ADVANCED = 'advanced';

/*-------------------------------------------------------------------------
* files
*-----------------------------------------------------------------------*/
public static KEY_FILES: string = 'files';
public static EOL: string = 'eol';
public static KEY_FILES = 'files';
public static EOL = 'eol';

/*-------------------------------------------------------------------------
* editor
*-----------------------------------------------------------------------*/
public static KEY_EDITOR: string = 'editor';
public static INSERT_SPACES: string = 'insertSpaces';
public static DETECT_IDENTATION: string = 'detectIndentation';
public static KEY_EDITOR = 'editor';
public static INSERT_SPACES = 'insertSpaces';
public static DETECT_IDENTATION = 'detectIndentation';

public activateOnEnter: boolean;
public advanced: Object;
public eol: string;
public insertSpaces: boolean;
public detectIdentation: boolean;
Expand Down

0 comments on commit 67966eb

Please sign in to comment.