Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit 644f005

Browse files
committed
WIP: Debug
1 parent 7c0cd69 commit 644f005

File tree

4 files changed

+85
-8
lines changed

4 files changed

+85
-8
lines changed

lib/debug.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"allowDebug": true,
3+
"debug": {
4+
"warn":"Snippet Injector launched in Debug-Mode. This will reveal several information about the package here.",
5+
"info": "You can safely ignore this since it doesn't change the default package behavior.\nTo disable this outputs, run the 'snippet-injector:toggledebug' command within Atom."
6+
},
7+
"groupTitle": "Snippet Injector - DEBUG INFO",
8+
"default": {
9+
"timings": false,
10+
"object-logging": false
11+
},
12+
"usrPref": null
13+
}

lib/snippet-injector.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export default {
1212
storage: null,
1313

1414
activate(state) {
15+
console.groupCollapsed("Snippet Injector - DEBUG");
16+
console.time("snippet-injector:activate duration");
17+
1518
this.storage = new Storage({dir: '/storage/snippet-injector/snippets/'});
1619
this.storage.migrate();
1720

@@ -21,6 +24,9 @@ export default {
2124
'snippet-injector:insert': () => this.insert(),
2225
'snippet-injector:delete': () => this.delete()
2326
}));
27+
28+
console.timeEnd("snippet-injector:activate duration");
29+
console.groupEnd();
2430
},
2531

2632
deactivate() {
@@ -34,6 +40,9 @@ export default {
3440
},
3541

3642
create() {
43+
console.groupCollapsed("Snippet Injector - DEBUG");
44+
console.time("snippet-injector:create duration");
45+
3746
var selection = atom.workspace.getActiveTextEditor().getSelectedText();
3847
var grammar = atom.workspace.getActiveTextEditor().getGrammar().name;
3948
var storage = this.storage;
@@ -65,17 +74,26 @@ export default {
6574
}
6675
}
6776
});
77+
78+
console.timeEnd("snippet-injector:create duration");
79+
console.groupEnd();
6880
},
6981

7082
insert() {
83+
console.groupCollapsed("Snippet Injector - DEBUG");
84+
console.time("snippet-injector:insert duration");
85+
7186
var storage = this.storage;
7287
var filenames = storage.retrieveFiles();
7388
if(filenames.length > 0) {
7489
var listitems = new Array();
7590
var icons = new Array();
7691
filenames.forEach(function(currentValue) {
7792
var elem = new Snippet(JSON.parse(storage.retrieveFile(currentValue.replace('.json',''))));
78-
listitems.push(elem.getUID());
93+
listitems.push({
94+
title: elem.getTitle(),
95+
uid: elem.getUID()
96+
});
7997
icons.push(elem.getLang());
8098
});
8199

@@ -102,9 +120,15 @@ export default {
102120
} else {
103121
atom.notifications.addWarning('No snippets found in the local storage directory.', null);
104122
}
123+
124+
console.timeEnd("snippet-injector:insert duration");
125+
console.groupEnd();
105126
},
106127

107128
delete() {
129+
console.groupCollapsed("Snippet Injector - DEBUG");
130+
console.time("snippet-injector:delete duration");
131+
108132
var storage = this.storage;
109133
var fileNames = storage.retrieveFiles();
110134
if(fileNames.length > 0) {
@@ -136,5 +160,8 @@ export default {
136160
} else {
137161
atom.notifications.addWarning('No snippets found in the local storage directory.', null);
138162
}
163+
164+
console.timeEnd("snippet-injector:delete duration");
165+
console.groupEnd();
139166
}
140167
};

lib/storage.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export default class Storage {
3030
destroy() {}
3131

3232
init(directory) {
33+
console.time("storage:init duration");
34+
3335
var store = this.storageDir;
3436
var divider;
3537

@@ -54,13 +56,20 @@ export default class Storage {
5456
}
5557
});
5658
this.dir = temp;
59+
60+
console.timeEnd("storage:init duration");
5761
}
5862

5963
store(snippet) {
64+
console.time("storage:store duration");
65+
6066
if(Util.isset(snippet,Snippet)) {
6167
fs.writeFileSync(this.storageDir+this.dir+snippet.getUID().split(' ').join('-')+'.json',JSON.stringify(snippet));
62-
return fs.existsSync(this.storageDir+this.dir+snippet.getUID().split(' ').join('-')+'.json');
68+
var temp = fs.existsSync(this.storageDir+this.dir+snippet.getUID().split(' ').join('-')+'.json');
69+
console.timeEnd("storage:store duration");
70+
return temp;
6371
} else {
72+
console.timeEnd("storage:store duration");
6473
return false;
6574
}
6675
}
@@ -69,15 +78,21 @@ export default class Storage {
6978
if(this.dir === '') {
7079
throw new TypeError('Storage directory has not been initialized.');
7180
} else {
72-
return fs.readdirSync(this.storageDir+this.dir);
81+
console.time("storage:retrieveFiles duration");
82+
var temp = fs.readdirSync(this.storageDir+this.dir);
83+
console.timeEnd("storage:retrieveFiles duration");
84+
return temp;
7385
}
7486
}
7587

7688
retrieveFile(uid) {
7789
if(this.dir === '') {
7890
throw new TypeError('Storage directory has not been initialized.');
7991
} else {
80-
return fs.readFileSync(this.storageDir+this.dir+uid.split(' ').join('-')+'.json');
92+
console.time("storage:retrieveFile duration");
93+
var temp = fs.readFileSync(this.storageDir+this.dir+uid.split(' ').join('-')+'.json');
94+
console.timeEnd("storage:retrieveFile duration");
95+
return temp;
8196
}
8297
}
8398

@@ -99,10 +114,13 @@ export default class Storage {
99114
if(this.dir === '') {
100115
throw new TypeError('Storage directory has not been initialized.');
101116
} else {
117+
console.time("storage:deleteFile duration");
102118
if(fs.existsSync(this.storageDir+this.dir+uid.split(' ').join('-')+'.json')) {
103119
fs.unlinkSync(this.storageDir+this.dir+uid.split(' ').join('-')+'.json');
120+
console.timeEnd("storage:deleteFile duration");
104121
return true;
105122
} else {
123+
console.timeEnd("storage:deleteFile duration");
106124
return false;
107125
}
108126
}
@@ -112,6 +130,8 @@ export default class Storage {
112130
if(this.dir === '') {
113131
throw new TypeError('Storage directory has not been initialized.');
114132
} else {
133+
console.time("storage:migrate duration");
134+
115135
var files = this.retrieveFiles();
116136
if(files.length > 0) {
117137
var changed = 0;
@@ -149,6 +169,8 @@ export default class Storage {
149169
atom.notifications.addSuccess('Successfully migrated snippets to newer version.', {detail: migrated});
150170
}
151171
}
172+
173+
console.timeEnd("storage:migrate duration");
152174
}
153175
}
154176
}

lib/util.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export default class Util {
2626
} else if(typeof callback !== 'function') {
2727
throw TypeError('Param \'callback\' has to be a function.');
2828
} else {
29+
console.time("util.js:promptUser duration");
30+
2931
const inputPrompt = document.createElement('div');
3032
inputPrompt.id = 'input-prompt';
3133

@@ -78,6 +80,8 @@ export default class Util {
7880
window.addEventListener('keyup', handleKey, true);
7981

8082
modal.show();
83+
84+
console.timeEnd("util.js:promptUser duration");
8185
}
8286
}
8387

@@ -87,6 +91,8 @@ export default class Util {
8791
} else if(typeof callback !== 'function') {
8892
throw TypeError('Param \'callback\' has to be a function.');
8993
} else {
94+
console.time("util.js:promptSearch duration");
95+
9096
const searchPrompt = document.createElement('div');
9197
searchPrompt.id = 'search-prompt';
9298

@@ -114,8 +120,8 @@ export default class Util {
114120
listDOMstring += IconHelper.getIconTag('default');
115121
}
116122
}
117-
listDOMstring += '<p class="value">';
118-
listDOMstring += currentValue;
123+
listDOMstring += '<p class="value" data-id="'+currentValue.uid+'">';
124+
listDOMstring += currentValue.title;
119125
listDOMstring += '</p></li>';
120126
});
121127
listDOMstring += '</ol><button class="btn btn-default" id="prompt-cancel">'+options.btncancel+'</button>';
@@ -179,6 +185,8 @@ export default class Util {
179185
window.addEventListener('keyup',handleKey,true)
180186

181187
modal.show();
188+
189+
console.timeEnd("util.js:promptSearch duration");
182190
}
183191
}
184192

@@ -188,6 +196,8 @@ export default class Util {
188196
} else if(typeof callback !== 'function') {
189197
throw TypeError('Param \'callback\' has to be a function.');
190198
} else {
199+
console.time("util.js:promptDelete duration");
200+
191201
const deletePrompt = document.createElement('div');
192202
deletePrompt.id = 'delete-prompt';
193203
$('#delete-prompt').addClass('control-group');
@@ -237,6 +247,8 @@ export default class Util {
237247
});
238248

239249
modal.show();
250+
251+
console.timeEnd("util.js:promptDelete duration");
240252
}
241253
}
242254

@@ -289,11 +301,12 @@ export default class Util {
289301
id += timestamp.substr(rand,this.getRandomInt(0,timestamp.length-rand));
290302
}
291303
}
292-
293304
return id;
294305
}
295306

296307
static generateUID(options) {
308+
console.time("util.js:generateUID duration");
309+
297310
var uid = '';
298311
if(typeof options === 'object') {
299312
if(this.isset(options.unique,'boolean') && options.unique && this.isset(options.tester,'function')) {
@@ -314,13 +327,15 @@ export default class Util {
314327
uid = this._gen();
315328
}
316329

330+
console.timeEnd("util.js:generateUID duration");
317331
return uid;
318332
}
319333

320334
static getRandomInt(min, max) {
321335
var min = Math.ceil(min);
322336
var max = Math.floor(max);
323-
return Math.floor(Math.random() * (max - min)) + min;
337+
var temp = Math.floor(Math.random() * (max - min)) + min;
338+
return ;
324339
}
325340

326341
static getPackageVersion() {

0 commit comments

Comments
 (0)