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

Commit b256bc2

Browse files
committed
Finished work
1 parent c9c0a69 commit b256bc2

File tree

6 files changed

+81
-11
lines changed

6 files changed

+81
-11
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#### Features
99
- Debug functionalities *(for easier bug reporting)*
10-
- Edit option added
1110
#### Improvements
1211
- Path resolvement
1312
#### Patches

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ You will be prompted for the snippet name to delete.
4141
> "Delete snippet"
4242
4343

44+
##### **snippet-injector:toggledebug**
45+
This command toggles all debugging options for the package.
46+
Debug informations are logged in Atom's console.
47+
48+
*Please notice that this command is just available through command palette!*
49+
50+
51+
##### **snippet-injector:toggle-time-debug**
52+
This command toggles debugging of function durations.
53+
Debug informations are logged in Atom's console.
54+
55+
*Name in menus:*
56+
> "Toggle timing debug"
57+
58+
59+
##### **snippet-injector:toggle-object-debug**
60+
This command toggles debugging of the package state.
61+
Debug informations are logged in Atom's console.
62+
63+
*Name in menus:*
64+
> "Toggle object debug"
65+
66+
4467
---
4568

4669
### External Sources

lib/debug.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"timings": false,
1111
"objectLogging": false
1212
},
13-
"usrPref": null
14-
}
13+
"usrPref": {
14+
"timings": false,
15+
"objectLogging": false
16+
}
17+
}

lib/snippet-injector.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export default {
4242
this.subscriptions.add(atom.commands.add('atom-workspace', {
4343
'snippet-injector:create': () => this.create(),
4444
'snippet-injector:insert': () => this.insert(),
45-
'snippet-injector:delete': () => this.delete()
45+
'snippet-injector:delete': () => this.delete(),
46+
'snippet-injector:toggle-time-debug': () => this.debugTime(),
47+
'snippet-injector:toggle-object-debug': () => this.debugObjects(),
48+
'snippet-injector:toggledebug': () => this.debug()
4649
}));
4750

4851
if(this.debug.allowDebug) {
@@ -76,6 +79,37 @@ export default {
7679
return new Object();
7780
},
7881

82+
debug() {
83+
this.debugTime();
84+
this.debugObjects();
85+
}
86+
87+
debugTime() {
88+
if(this.debug.allowDebug) {
89+
this.debug.usrPref.timings = !this.debug.usrPref.timings;
90+
if(this.debug.usrPref.timings) {
91+
atom.notifications.addInfo('Enabled timings debug.', {detail: 'Changes take effect on next full restart of Atom.'});
92+
} else {
93+
atom.notifications.addInfo('Disabled timings debug.', {detail: 'Changes take effect on next full restart of Atom.'});
94+
}
95+
} else {
96+
atom.notifications.addWarning('Cannot toggle debug mode since it is disabled.', null);
97+
}
98+
},
99+
100+
debugObjects() {
101+
if(this.debug.allowDebug) {
102+
this.debug.usrPref.objectLogging = !this.debug.usrPref.objectLogging;
103+
if(this.debug.usrPref.objectLogging) {
104+
atom.notifications.addInfo('Enabled object debug.', {detail: 'Changes take effect on next full restart of Atom.'});
105+
} else {
106+
atom.notifications.addInfo('Disabled object debug.', {detail: 'Changes take effect on next full restart of Atom.'});
107+
}
108+
} else {
109+
atom.notifications.addWarning('Cannot toggle debug mode since it is disabled.', null);
110+
}
111+
},
112+
79113
create() {
80114
console.groupCollapsed("Snippet Injector - DEBUG");
81115
console.time("snippet-injector:create duration");

lib/storage.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export default class Storage {
7070
}
7171

7272
if(Util.isset(snippet,Snippet)) {
73-
fs.writeFileSync(this.storageDir+this.dir+snippet.getUID().split(' ').join('-')+'.json',JSON.stringify(snippet,null,2));
74-
var temp = fs.existsSync(this.storageDir+this.dir+snippet.getUID().split(' ').join('-')+'.json');
73+
fs.writeFileSync(path.join(this.storageDir,this.dir,snippet.getUID().split(' ').join('-')+'.json'),JSON.stringify(snippet,null,2));
74+
var temp = fs.existsSync(path.join(this.storageDir,this.dir,snippet.getUID().split(' ').join('-')+'.json'));
7575
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
7676
console.timeEnd("storage:store duration");
7777
}
@@ -91,7 +91,7 @@ export default class Storage {
9191
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
9292
console.time("storage:retrieveFiles duration");
9393
}
94-
var temp = fs.readdirSync(this.storageDir+this.dir);
94+
var temp = fs.readdirSync(path.join(this.storageDir,this.dir));
9595
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
9696
console.timeEnd("storage:retrieveFiles duration");
9797
}
@@ -106,7 +106,7 @@ export default class Storage {
106106
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
107107
console.time("storage:retrieveFile duration");
108108
}
109-
var temp = fs.readFileSync(this.storageDir+this.dir+uid.split(' ').join('-')+'.json');
109+
var temp = fs.readFileSync(path.join(this.storageDir,this.dir,uid.split(' ').join('-')+'.json'));
110110
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
111111
console.timeEnd("storage:retrieveFile duration");
112112
}
@@ -135,8 +135,8 @@ export default class Storage {
135135
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
136136
console.time("storage:deleteFile duration");
137137
}
138-
if(fs.existsSync(this.storageDir+this.dir+uid.split(' ').join('-')+'.json')) {
139-
fs.unlinkSync(this.storageDir+this.dir+uid.split(' ').join('-')+'.json');
138+
if(fs.existsSync(path.join(this.storageDir,this.dir,uid.split(' ').join('-')+'.json'))) {
139+
fs.unlinkSync(path.join(this.storageDir,this.dir,uid.split(' ').join('-')+'.json'));
140140
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
141141
console.timeEnd("storage:deleteFile duration");
142142
}
@@ -166,7 +166,7 @@ export default class Storage {
166166
var _this = this;
167167
files.forEach(function(current) {
168168
if(current.endsWith('.snippet.json')) {
169-
fs.renameSync(store+current,store+current.replace('.snippet.json','.json'));
169+
fs.renameSync(path.join(store,current),path.join(store,current.replace('.snippet.json','.json')));
170170
current = current.replace('.snippet.json','');
171171
} else {
172172
current = current.replace('.json','');

menus/snippet-injector.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
{
4040
"label": "Delete Snippet",
4141
"command": "snippet-injector:delete"
42+
},
43+
{
44+
"type": "separator"
45+
},
46+
{
47+
"label": "Toggle timing debug",
48+
"command": "snippet-injector:toggle-time-debug"
49+
},
50+
{
51+
"label": "Toggle object debug",
52+
"command": "snippet-injector:toggle-object-debug"
4253
}
4354
]
4455
}

0 commit comments

Comments
 (0)