Skip to content

Commit 2e7622d

Browse files
committed
added log manager for javascript manager
1 parent 77c1da6 commit 2e7622d

File tree

6 files changed

+72
-24
lines changed

6 files changed

+72
-24
lines changed

README.md

+24-20
Original file line numberDiff line numberDiff line change
@@ -8,80 +8,84 @@ The aim of this extension is to increase productivity by unifying set of actions
88
Select a text of a file and open the *editor commands* _(ctrl+shift+P / cmd+shift+P)_ and search for one of the next commands:
99

1010
#### >Copy Selection
11-
copy the selection in a new file
11+
copy the selection in a new file.
1212

1313
---
1414
#### >Move Selection
15-
move the selection in a new file, results in having the original text deleated
15+
Move the selection in a new file, results in having the original text deleated.
1616

1717
---
1818
#### >Isolate Selection
19-
isolate the selection, results in having the content of the document replaced with just the selected text
19+
Isolate the selection, results in having the content of the document replaced with just the selected text.
2020

2121
---
2222
#### >Search Selection
23-
search for the selection on *google*
23+
Search for the selection on *google*.
2424

2525
---
2626
#### >URL Encode Selection
27-
it will replace the selected text with a URL encoded version of it
27+
It will replace the selected text with a URL encoded version of it.
2828

2929
---
3030
#### >Base64 Encode Selection
31-
it will replace the selected text with a Base64 encoded version of it
31+
It will replace the selected text with a Base64 encoded version of it.
3232

3333
---
3434
#### >URL Decode Selection
35-
it will replace the selected text with a URL decoded version of it
35+
It will replace the selected text with a URL decoded version of it.
3636

3737
---
3838
#### >Base64 Decode Selection
39-
it will replace the selected text with a Base64 decoded version of it
39+
It will replace the selected text with a Base64 decoded version of it.
4040

4141
---
4242
#### >Lowercase Selection
43-
turns the selected text to lowercase
43+
Turns the selected text to lowercase.
4444

4545
---
4646
#### >Uppercase Selection
47-
turns the selected text to uppercase
47+
Turns the selected text to uppercase.
4848

4949
---
5050
#### >Camel to Snake case Selection
51-
the selected camel case text will be turned to snake case _(eg. callAsync -> call\_async)_
51+
The selected camel case text will be turned to snake case _(eg. callAsync -> call\_async)_.
5252

5353
---
5454
#### >Snake to Camel case Selection
55-
the selected snake case text will be turned to camel case _(eg. call\_async -> callAsync)_
55+
The selected snake case text will be turned to camel case _(eg. call\_async -> callAsync)_.
5656

5757
---
5858
#### >Kebab to Camel case Selection
59-
the selected kebab case text will be turned to camel case _(eg. call-async -> callAsync)_
59+
The selected kebab case text will be turned to camel case _(eg. call-async -> callAsync)_.
6060

6161
---
6262
#### >Camel to Kebab case Selection
63-
the selected camel case text will be turned to kebab case _(eg. callAsync -> call-async)_
63+
The selected camel case text will be turned to kebab case _(eg. callAsync -> call-async)_.
6464

6565
---
6666
#### >Kebab to Snake case Selection
67-
the selected kebab case text will be turned to snake case _(eg. call-sync -> call\_async)_
67+
The selected kebab case text will be turned to snake case _(eg. call-sync -> call\_async)_.
6868

6969
---
7070
#### >Snake to Kebab case Selection
71-
the selected snake case text will be turned to kebab case _(eg. call\_sync -> call-async)_
71+
The selected snake case text will be turned to kebab case _(eg. call\_sync -> call-async)_.
7272

7373
---
7474
#### >Length of Selection
75-
pops an alert, in the bottom right corner, with the information of the length of the selected text
75+
Pops an alert, in the bottom right corner, with the information of the length of the selected text.
7676

7777
---
7878
#### >Number of non ASCII Characters in Selection
79-
pops an alert, in the bottom right corner, with the information of the number of non ascii characters in the selected text
79+
Pops an alert, in the bottom right corner, with the information of the number of non ascii characters in the selected text.
8080

8181
---
8282
#### >Reverse Selection
83-
It will reverse the selection, line by line
83+
It will reverse the selection, line by line.
84+
85+
---
86+
#### >Log Selection
87+
Puts the selection in a log call, just after the line of the selection. The log will include an log ID. _**Currently only works for JavaScript._
8488

8589
---
8690
#### >Lorem Ipsum on Selection
87-
replaces the selection with *lorem ipsum*, if nothing is selected will replace the whole line where the cursor is placed
91+
Replaces the selection with *lorem ipsum*, if nothing is selected will replace the whole line where the cursor is placed.

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Selection Manager",
44
"description": "Manage selected text of a file.",
55
"icon": "images/manage-selection.png",
6-
"version": "0.0.21",
6+
"version": "0.0.22",
77
"license": "MIT",
88
"engines": {
99
"vscode": "^1.66.0"
@@ -31,7 +31,8 @@
3131
"onCommand:selection-manager.length",
3232
"onCommand:selection-manager.lorem-ipsum",
3333
"onCommand:selection-manager.non-ascii",
34-
"onCommand:selection-manager.reverse"
34+
"onCommand:selection-manager.reverse",
35+
"onCommand:selection-manager.log"
3536
],
3637
"main": "./dist/extension.js",
3738
"contributes": {
@@ -115,6 +116,10 @@
115116
{
116117
"command": "selection-manager.reverse",
117118
"title": "Reverse Selection"
119+
},
120+
{
121+
"command": "selection-manager.log",
122+
"title": "Log Selection"
118123
}
119124
]
120125
},

src/extension.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import {
1919
loremIpsumManager,
2020
nonAsciiManager,
2121
reverseManager,
22+
logManager,
23+
snakeToKebabManager
2224
} from './managers';
23-
import { snakeToKebabManager } from './managers/snakeToKebab';
2425

2526
export function activate(context: vscode.ExtensionContext) {
2627
console.log(
@@ -47,7 +48,8 @@ export function activate(context: vscode.ExtensionContext) {
4748
['selection-manager.length', lengthManager],
4849
['selection-manager.lorem-ipsum', loremIpsumManager],
4950
['selection-manager.non-ascii', nonAsciiManager],
50-
['selection-manager.reverse', reverseManager]
51+
['selection-manager.reverse', reverseManager],
52+
['selection-manager.log', logManager],
5153
];
5254

5355
dispose.forEach(([key, manager]) => context.subscriptions.push(vscode.commands.registerCommand(key, manager)));

src/managers/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export * from './length';
1414
export * from './kebabToCamel';
1515
export * from './camelToKebab';
1616
export * from './kebabToSnake';
17+
export * from './snakeToKebab';
1718
export * from './snakeToCamel';
1819
export * from './loremIpsum';
1920
export * from './nonAscii';
2021
export * from './reverse';
22+
export * from './log';

src/managers/log.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as vscode from 'vscode';
2+
import { getRandomNumberInRange } from '../utils';
3+
4+
export async function logManager(): Promise<void> {
5+
const editor = vscode.window.activeTextEditor;
6+
7+
if (!editor) return;
8+
9+
const selectedText = editor.document.getText(editor.selection);
10+
11+
const language = vscode.window.activeTextEditor?.document.languageId;
12+
13+
if (!language) return;
14+
15+
if (!['javascript'].includes(language)) {
16+
vscode.window.showInformationMessage(`${language} is currently not supported for this functionality`);
17+
return;
18+
}
19+
20+
const cursorOnLine = editor.selection.start.line;
21+
22+
const line = editor.document.lineAt(cursorOnLine);
23+
24+
const indentChars = line.text.split(/\S/g)[0];
25+
26+
const text = `${line.text}
27+
${indentChars}console.log(\`-------- log start | log id: ${getRandomNumberInRange(1000000, 9999999)} | log time: \${new Date().toISOString()} --------\`);
28+
${indentChars}console.log(${selectedText});
29+
${indentChars}console.log("-------- log end --------");
30+
`;
31+
32+
editor.edit(edit => edit.replace(line.range, text));
33+
}

src/utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ export const snakeToKebab = (str: string): string => str.replace(/_/g, "-");
3131
export const generateLoremIpsum = (): string => lorem.generator.generateRandomSentence();
3232

3333
export const removeAsciiCharacters = (str: string): string => str.replace(/[ -~]/g, "");
34+
35+
export const getRandomNumberInRange = (fromOrTo: number, to?: number) => Math.floor(Math.random() * (to ? to : fromOrTo)) + (to ? fromOrTo : 0);

0 commit comments

Comments
 (0)