Skip to content

Commit 469d445

Browse files
authored
Feature/refactor document manager (buehler#131)
* rename the class and the jsdoc * rename the files * add the object manager interface and implement it * adding basic class manager structure * adding basic create method and tests * refactor changeable, adding tests * adding basic remove method and test skeleton * add jsdoc lint rule * adding types to declarations * fix test * add function without rettype * adding types to declarations * test for a typeguard * fix export typed stuff * adding tests for types * rename propertyvisibility * adding visibility to a method * add and remove methods from a class, with tests * correctly test changeables and add methods with name * fix bug, move enum for sorting matters * adding first commit actions and tests * adding generation of properties * adding more tests and cases * insert properties in between * code proeprty specials * add type to params, add generation of methods * require jsdoc for private methods * add method generator * first generated method * calculate if emtpy line should be deleted on method removal * do filter constructor injected properties * coding tests * remove only * add lint to pkgjson * missing JS doc * Documentation * changelog * ups.
1 parent 96f3803 commit 469d445

25 files changed

+1819
-197
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased]
6+
#### Added
7+
- Classmanager that can modify classes in a document ([#127](https://github.com/buehler/typescript-hero/issues/127))
68

79
## [0.10.1]
810
#### Added

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
"precompile": "del ./out",
4040
"compile": "tsc -w --sourceMap",
4141
"postinstall": "node ./node_modules/vscode/bin/install",
42-
"pretest": "tslint -c tslint.json --project tsconfig.json -e \"test/**/*.*\"",
42+
"pretest": "npm run lint",
4343
"test": "node ./node_modules/vscode/bin/test",
44+
"lint": "tslint -c tslint.json --project tsconfig.json -e \"test/**/*.*\"",
4445
"build": "del ./out && tsc",
4546
"package": "npm run build && del './*.vsix' && vsce package"
4647
},
@@ -58,6 +59,7 @@
5859
"sinon": "^1.17.6",
5960
"sinon-chai": "^2.8.0",
6061
"tslint": "^3.15.1",
62+
"tslint-jsdoc-rules": "^0.1.2",
6163
"vscode": "^1.0.0"
6264
},
6365
"dependencies": {

src/TypeScriptHero.ts

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export class TypeScriptHero implements Disposable {
2828
this.extensions.forEach(o => o.initialize(context));
2929
}
3030

31+
/**
32+
* Disposes TypeScript Hero.
33+
*
34+
*
35+
* @memberOf TypeScriptHero
36+
*/
3137
public dispose(): void {
3238
this.logger.info('Deactivation event called. Disposing TypeScriptHero.');
3339
for (let ext of this.extensions) {

src/caches/ResolveIndex.ts

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { ExtensionConfig } from '../ExtensionConfig';
2-
import { ModuleDeclaration, TsDeclaration, TsExportableDeclaration } from '../models/TsDeclaration';
2+
import {
3+
ModuleDeclaration,
4+
TsDeclaration,
5+
TsExportableDeclaration,
6+
TsTypedExportableDeclaration
7+
} from '../models/TsDeclaration';
38
import { TsAllFromExport, TsAssignedExport, TsFromExport, TsNamedFromExport } from '../models/TsExport';
49
import { TsFile, TsNamedResource, TsResource } from '../models/TsResource';
510
import { TsResourceParser } from '../parser/TsResourceParser';
@@ -22,6 +27,13 @@ export type ResourceIndex = { [declaration: string]: DeclarationInfo[] };
2227

2328
type Resources = { [name: string]: TsResource };
2429

30+
/**
31+
* Returns the name of the node folder. Is used as the library name for indexing.
32+
* (e.g. ./node_modules/webpack returns webpack)
33+
*
34+
* @param {string} path
35+
* @returns {string}
36+
*/
2537
function getNodeLibraryName(path: string): string {
2638
let dirs = path.split(/\/|\\/),
2739
nodeIndex = dirs.indexOf('node_modules');
@@ -297,7 +309,7 @@ export class ResolveIndex {
297309
*
298310
* @memberOf ResolveIndex
299311
*/
300-
private async parseResources(files: TsFile[], cancellationToken?: CancellationToken): Promise<Resources> {
312+
private async parseResources(files: TsFile[] = [], cancellationToken?: CancellationToken): Promise<Resources> {
301313
let parsedResources: Resources = {};
302314

303315
for (let file of files) {
@@ -324,8 +336,9 @@ export class ResolveIndex {
324336
return;
325337
}
326338
let resource = parsedResources[key];
327-
resource.declarations = resource.declarations
328-
.filter(o => o instanceof TsExportableDeclaration && o.isExported);
339+
resource.declarations = resource.declarations.filter(
340+
o => (o instanceof TsExportableDeclaration || o instanceof TsTypedExportableDeclaration) && o.isExported
341+
);
329342
this.processResourceExports(parsedResources, resource);
330343
}
331344

@@ -423,7 +436,9 @@ export class ResolveIndex {
423436
}
424437
} else {
425438
if (ex instanceof TsAssignedExport) {
426-
for (let lib of ex.exported.filter(o => !(o instanceof TsExportableDeclaration))) {
439+
for (let lib of ex.exported.filter(
440+
o => !(o instanceof TsExportableDeclaration) && !(o instanceof TsTypedExportableDeclaration))
441+
) {
427442
this.processResourceExports(parsedResources, lib as TsResource, processedResources);
428443
}
429444
this.processAssignedExport(parsedResources, ex, resource);
@@ -500,11 +515,14 @@ export class ResolveIndex {
500515
exportingLib: TsResource
501516
): void {
502517
tsExport.exported.forEach(exported => {
503-
if (exported instanceof TsExportableDeclaration) {
518+
if (exported instanceof TsExportableDeclaration || exported instanceof TsTypedExportableDeclaration) {
504519
exportingLib.declarations.push(exported);
505520
} else {
506521
exportingLib.declarations.push(
507-
...exported.declarations.filter(o => o instanceof TsExportableDeclaration && o.isExported)
522+
...exported.declarations.filter(
523+
o => (o instanceof TsExportableDeclaration || o instanceof TsTypedExportableDeclaration) &&
524+
o.isExported
525+
)
508526
);
509527
exported.declarations = [];
510528
}

src/extensions/CodeFixExtension.ts

+20
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,24 @@ export class CodeFixExtension extends BaseExtension {
2828
this.logger.info('Extension instantiated.');
2929
}
3030

31+
/**
32+
* Returns command items for this extension.
33+
*
34+
* @returns {CommandQuickPickItem[]}
35+
*
36+
* @memberOf CodeFixExtension
37+
*/
3138
public getGuiCommands(): CommandQuickPickItem[] {
3239
return [];
3340
}
3441

42+
/**
43+
* Initializes the extension.
44+
*
45+
* @param {ExtensionContext} context
46+
*
47+
* @memberOf CodeFixExtension
48+
*/
3549
public initialize(context: ExtensionContext): void {
3650
context.subscriptions.push(commands.registerCommand(
3751
'typescriptHero.codeFix.executeCodeAction',
@@ -41,6 +55,12 @@ export class CodeFixExtension extends BaseExtension {
4155
this.logger.info('Initialized.');
4256
}
4357

58+
/**
59+
* Disposes the extension.
60+
*
61+
*
62+
* @memberOf CodeFixExtension
63+
*/
4464
public dispose(): void {
4565
this.logger.info('Dispose called.');
4666
}

src/extensions/ResolveExtension.ts

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ResolveIndex } from '../caches/ResolveIndex';
2-
import { DocumentController } from '../controllers/DocumentController';
32
import { ExtensionConfig } from '../ExtensionConfig';
3+
import { ImportManager } from '../managers/ImportManager';
44
import { CommandQuickPickItem, ResolveQuickPickItem } from '../models/QuickPickItems';
55
import { TshCommand } from '../models/TshCommand';
66
import { TsResourceParser } from '../parser/TsResourceParser';
@@ -29,6 +29,13 @@ const resolverOk = 'Resolver $(check)',
2929
TYPESCRIPT = 'typescript',
3030
TYPESCRIPT_REACT = 'typescriptreact';
3131

32+
/**
33+
* Compares the ignorepatterns (if they have the same elements ignored).
34+
*
35+
* @param {string[]} local
36+
* @param {string[]} config
37+
* @returns {boolean}
38+
*/
3239
function compareIgnorePatterns(local: string[], config: string[]): boolean {
3340
if (local.length !== config.length) {
3441
return false;
@@ -78,6 +85,13 @@ export class ResolveExtension extends BaseExtension {
7885
this.logger.info('Extension instantiated.');
7986
}
8087

88+
/**
89+
* Returns command items for this extension.
90+
*
91+
* @returns {CommandQuickPickItem[]}
92+
*
93+
* @memberOf ResolveExtension
94+
*/
8195
public getGuiCommands(): CommandQuickPickItem[] {
8296
return [
8397
new CommandQuickPickItem(
@@ -113,6 +127,13 @@ export class ResolveExtension extends BaseExtension {
113127
];
114128
}
115129

130+
/**
131+
* Initializes the extension.
132+
*
133+
* @param {ExtensionContext} context
134+
*
135+
* @memberOf ResolveExtension
136+
*/
116137
public initialize(context: ExtensionContext): void {
117138
context.subscriptions.push(
118139
commands.registerTextEditorCommand('typescriptHero.resolve.addImport', () => this.addImport())
@@ -176,6 +197,12 @@ export class ResolveExtension extends BaseExtension {
176197
this.logger.info('Initialized.');
177198
}
178199

200+
/**
201+
* Disposes the extension.
202+
*
203+
*
204+
* @memberOf ResolveExtension
205+
*/
179206
public dispose(): void {
180207
this.logger.info('Dispose called.');
181208
}
@@ -255,7 +282,7 @@ export class ResolveExtension extends BaseExtension {
255282
return;
256283
}
257284
try {
258-
let ctrl = await DocumentController.create(window.activeTextEditor.document);
285+
let ctrl = await ImportManager.create(window.activeTextEditor.document);
259286
await ctrl.addMissingImports(this.index).commit();
260287
} catch (e) {
261288
this.logger.error('An error happend during import fixing', e);
@@ -273,7 +300,7 @@ export class ResolveExtension extends BaseExtension {
273300
*/
274301
private async organizeImports(): Promise<boolean> {
275302
try {
276-
let ctrl = await DocumentController.create(window.activeTextEditor.document);
303+
let ctrl = await ImportManager.create(window.activeTextEditor.document);
277304
return await ctrl.organizeImports().commit();
278305
} catch (e) {
279306
this.logger.error('An error happend during "organize imports".', { error: e });
@@ -291,7 +318,7 @@ export class ResolveExtension extends BaseExtension {
291318
* @memberOf ResolveExtension
292319
*/
293320
private async addImportToDocument(item: ResolveQuickPickItem): Promise<boolean> {
294-
let ctrl = await DocumentController.create(window.activeTextEditor.document);
321+
let ctrl = await ImportManager.create(window.activeTextEditor.document);
295322
return await ctrl.addDeclarationImport(item.declarationInfo).commit();
296323
}
297324

src/extensions/RestartDebuggerExtension.ts

+20
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ export class RestartDebuggerExtension extends BaseExtension {
3939
this.logger.info('Extension instantiated.');
4040
}
4141

42+
/**
43+
* Returns command items for this extension.
44+
*
45+
* @returns {CommandQuickPickItem[]}
46+
*
47+
* @memberOf RestartDebuggerExtension
48+
*/
4249
public getGuiCommands(): CommandQuickPickItem[] {
4350
return [
4451
new CommandQuickPickItem(
@@ -53,6 +60,13 @@ export class RestartDebuggerExtension extends BaseExtension {
5360
];
5461
}
5562

63+
/**
64+
* Initializes the extension.
65+
*
66+
* @param {ExtensionContext} context
67+
*
68+
* @memberOf RestartDebuggerExtension
69+
*/
5670
public initialize(context: ExtensionContext): void {
5771
this.configure();
5872
context.subscriptions.push(commands.registerCommand('typescriptHero.restartDebugger.toggle', () => {
@@ -65,6 +79,12 @@ export class RestartDebuggerExtension extends BaseExtension {
6579
this.logger.info('Initialized.');
6680
}
6781

82+
/**
83+
* Disposes the extension.
84+
*
85+
*
86+
* @memberOf RestartDebuggerExtension
87+
*/
6888
public dispose(): void {
6989
this.logger.info('Dispose called.');
7090
if (this.fileWatcher) {

0 commit comments

Comments
 (0)