Skip to content

Commit f24e63c

Browse files
committed
remove streams
1 parent ec2cc09 commit f24e63c

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

.DS_Store

0 Bytes
Binary file not shown.

extension.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ function activate(context) {
77

88
const run = vscode.commands.registerCommand('htmlclasses-parser.run', () => {
99
const fileType = window.activeTextEditor?.document.fileName;
10-
if (!fileType.endsWith('html') && !fileType.endsWith('jsx') &&
11-
!fileType.endsWith('tsx') && !fileType.endsWith('vue')) return;
10+
if (
11+
!fileType.endsWith('html') &&
12+
!fileType.endsWith('jsx') &&
13+
!fileType.endsWith('tsx') &&
14+
!fileType.endsWith('vue')
15+
)
16+
return;
1217
client.convert();
1318
});
1419
context.subscriptions.push(run);

lib/client.js

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const stream = require('node:stream');
21
const htmlparser2 = require('htmlparser2');
32
const vscode = require('vscode');
43

@@ -15,13 +14,13 @@ class Client {
1514
this.#document = this.#editor.document;
1615
}
1716

18-
async *#highlighted() {
19-
// to rewrite
17+
#highlighted() {
2018
const highlighted = this.#editor.selection;
21-
const selectionRange = new vscode.Range(highlighted.start.line, 0, highlighted.end.line, 999);
22-
const selected = this.#document.getText(selectionRange);
23-
if (selected.length === 0) yield this.#document.getText();
24-
yield selected;
19+
const start = highlighted.start.line;
20+
const end = highlighted.end.line;
21+
if (start === end) return this.#document.getText();
22+
const selectionRange = new vscode.Range(start, 0, end, 1000);
23+
return this.#document.getText(selectionRange);
2524
}
2625

2726
/** @param {string} message */
@@ -48,7 +47,9 @@ class Client {
4847
// }
4948

5049
convert() {
51-
const readable = stream.Readable.from(this.#highlighted());
50+
const highlighted = this.#highlighted();
51+
console.log(highlighted);
52+
// const readable = stream.Readable.from(this.#highlighted());
5253
const classes = new Set();
5354
const parser = new htmlparser2.Parser({
5455
onattribute(attribute, value) {
@@ -61,20 +62,9 @@ class Client {
6162
}
6263
},
6364
});
64-
const createTransformStream = () => {
65-
const options = {
66-
async transform(chunk, encoding, next) {
67-
parser.write(chunk.toString());
68-
next();
69-
},
70-
};
71-
return new stream.Transform(options);
72-
};
73-
return readable.pipe(createTransformStream()).on('finish', () => {
74-
createTransformStream().destroy();
75-
vscode.env.clipboard.writeText([...classes.values()].join('\n'));
76-
this.print('done');
77-
});
65+
parser.write(highlighted);
66+
vscode.env.clipboard.writeText([...classes.values()].join('\n'));
67+
this.print('Classes are copied to the clipboard');
7868
}
7969
}
8070

0 commit comments

Comments
 (0)