cybertim / vscode-gengetset

Generate Getter and / or Setter Extension for Visual Studio Code
34 stars 17 forks source link

Optimize / Auto Imports, Generate Getters / Setters and Constructors

Simply click on the Light Bulb to add the missing import line

Import

Optimize all your import lines: add missing imports and remove unused

Optimize

Easily create a contructor based on privates.

Constructor

Quickly generate getters and setters for your class.

GetSet

Keep an eye on the eye-icon for quick info about the exports found.

Status

Changelog

v0.5.0

v0.4.2

v0.4.1

v0.4.0

v0.3.4 - v0.3.0

Install

Get VSCode and grab the extension from the VSCode Extension Market

Settings

  1. genGetSet.scoped (default: enabled) Only show private variables from current class based on cursor position.
  2. genGetSet.filter (default: enabled) Only show private variables which do not have a getter/setter method.
  3. genGetSet.importTypings (default: enabled) Create import lines based on definition files from /typings/.
  4. genGetSet.importNode (default: enabled) Create import lines based on definition files from /node_modules/.
  5. genGetSet.classic (default: disabled) use 'getValue' and 'setValue' instead of 'get value' and 'set value'.
  6. genGetSet.pathStringDelimiter (default: ') sets which quote use to generate import path.
  7. genGetSet.spacedImportLine (default: false) Adds spaces between the beginning and ending of the brackets in an import line.
  8. genGetSet.scanOnSave (default: false) Scan the workspace for imports when a document is saved.
  9. genGetSet.ignoredImportList (check settings) Imports like 'Promise' have many libraries but seldom need an import line.
  10. genGetSet.ignoredDictionaryList (check settings) Dictionaries like 'vscode' and 'tsconfig' which do not need an import line.
  11. genGetSet.ignoredLibraryPaths (check settings) Paths like 'dist' and 'src' which can be omitted in the import line.
  12. genGetSet.ignoredNodeLibraries (check settings) A list of node module libraries like 'chrome' and 'node' which can be ignored as an import line.

Usage

  1. Just place your cursor within a TypeScript class definition in the text editor window
  2. Open the command palette ctrl+shift+P / cmd+shift+P.
  3. Search for 'Import', 'Generate Getter', 'Setter' or 'Constructor'

or

  1. Just place your cursor within a TypeScript class definition in the text editor window
  2. Press alt+shift+G for a quick selection pop-up
  3. Select the preferred function from the pop-up menu

or

  1. Click on the little Eye-Icon in your statusbar
  2. Select the preferred function from the pop-up menu

The generated method will be placed at the cursors position.

Best Practice

Best practice is naming your variables with a _ for private use. The extension will remove the _ when generating the methods.

This: private _name: string;

Will render in:

public get name(): string {
    return this._name;
}

public set name(value: string) {
    this._name = value;
}

If there is no _ the method will start with a $.

This: private name: string;

Will render in:

public get $name(): string {
    return this.name;
}

public set $name(value: string) {
    this.name = value;
}

Known Problems

Always type your variables. Even when your variable is being initialized, else the extension cannot read the typing. Always do this: private _name: boolean = false;

This is a TypeScript only extension.

Contributors

Special thanks to the github users: AngelMunoz, edotassi, Aranir, buehler, EduwHS, Anexon, Tchoupinax, dball-adashi

Enjoy!