Skip to content

Commit a3e3e95

Browse files
committed
initial comit & first logic
1 parent bba68f5 commit a3e3e95

10 files changed

+124
-37
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
charset = utf-8
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[{*.js,*.mjs,*.ts,*.json,*.yml}]
11+
indent_size = 2
12+
indent_style = space

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package.json
2+
package-lock.json

.prettierrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"overrides": [
5+
{
6+
"files": ["**/.*rc", "**/*.json"],
7+
"options": { "parser": "json" }
8+
}
9+
]
10+
}

extension.js

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
1-
// The module 'vscode' contains the VS Code extensibility API
2-
// Import the module and reference it with the alias vscode in your code below
31
const vscode = require('vscode');
2+
const Client = require('./lib/client.js');
43

5-
// This method is called when your extension is activated
6-
// Your extension is activated the very first time the command is executed
74

8-
/**
9-
* @param {vscode.ExtensionContext} context
10-
*/
115
function activate(context) {
12-
13-
// Use the console to output diagnostic information (console.log) and errors (console.error)
14-
// This line of code will only be executed once when your extension is activated
156
console.log('Congratulations, your extension "htmlclasses-parser" is now active!');
167

17-
// The command has been defined in the package.json file
18-
// Now provide the implementation of the command with registerCommand
19-
// The commandId parameter must match the command field in package.json
208
const disposable = vscode.commands.registerCommand('htmlclasses-parser.helloWorld', () => {
21-
// The code you place here will be executed every time your command is executed
22-
23-
// Display a message box to the user
249
vscode.window.showInformationMessage('Hello World from htmlClasses-parser!');
2510
});
2611

27-
context.subscriptions.push(disposable);
12+
const test = vscode.commands.registerCommand('htmlclasses-parser.test', () => {
13+
const window = vscode.window;
14+
const client = new Client(window);
15+
16+
const classes = client.convert();
17+
client.print(classes.toString());
18+
});
19+
context.subscriptions.push(disposable, test);
2820
}
2921

3022
// This method is called when your extension is deactivated

jsconfig.json

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
{
2-
"compilerOptions": {
3-
"module": "Node16",
4-
"target": "ES2022",
5-
"checkJs": true, /* Typecheck .js files. */
6-
"lib": [
7-
"ES2022"
8-
]
9-
},
10-
"exclude": [
11-
"node_modules"
12-
]
2+
"compilerOptions": {
3+
"module": "Node16",
4+
"target": "ES2022",
5+
"checkJs": true /* Typecheck .js files. */,
6+
"lib": ["ES2022"]
7+
},
8+
"exclude": ["node_modules"]
139
}

lib/client.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Client {
2+
#window;
3+
#editor;
4+
#document;
5+
highlighted;
6+
7+
constructor(window) {
8+
if (window === null) return;
9+
this.#window = window;
10+
this.#editor = window.activeTextEditor;
11+
this.#document = this.#editor.document;
12+
}
13+
14+
copy() {
15+
let highlighted = this.#document.getText(this.#editor.selection);
16+
if (highlighted.length === 0) highlighted = this.#document.getText();
17+
this.highlighted = highlighted;
18+
return this.highlighted;
19+
}
20+
21+
print(message) {
22+
if (message === null) return;
23+
this.#window.showInformationMessage(message);
24+
}
25+
26+
convert() {
27+
this.copy();
28+
const results = [];
29+
const REGEX = /("((?:\\.|[^"\\])*)")/g;
30+
const classes = this.highlighted.match(REGEX);
31+
for (const className of classes) results.push(className.slice(1, -1));
32+
// separate the classes if they are written with space (class="class1 class2")
33+
// classes can be written with single quotes
34+
return results;
35+
}
36+
}
37+
38+
39+
module.exports = Client;

package-lock.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+11-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
"activationEvents": [],
1313
"main": "./extension.js",
1414
"contributes": {
15-
"commands": [{
16-
"command": "htmlclasses-parser.helloWorld",
17-
"title": "Hello World"
18-
}]
15+
"commands": [
16+
{
17+
"command": "htmlclasses-parser.helloWorld",
18+
"title": "Hello World"
19+
},
20+
{
21+
"command": "htmlclasses-parser.test",
22+
"title": "htmlclasses test"
23+
}
24+
]
1925
},
2026
"scripts": {
2127
"lint": "eslint .",
@@ -26,6 +32,7 @@
2632
"@types/vscode": "^1.85.0",
2733
"@types/mocha": "^10.0.6",
2834
"@types/node": "18.x",
35+
"prettier": "^3.1.1",
2936
"eslint": "^8.56.0",
3037
"typescript": "^5.3.3",
3138
"@vscode/test-cli": "^0.0.4",

test/extension.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const vscode = require('vscode');
66
// const myExtension = require('../extension');
77

88
suite('Extension Test Suite', () => {
9-
vscode.window.showInformationMessage('Start all tests.');
9+
vscode.window.showInformationMessage('Start all tests.');
1010

11-
test('Sample test', () => {
12-
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
13-
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
14-
});
11+
test('Sample test', () => {
12+
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
13+
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
14+
});
1515
});

tsconfig.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"moduleResolution": "node",
5+
"strict": true,
6+
"baseUrl": ".",
7+
"preserveWatchOutput": true,
8+
"allowJs": true,
9+
"noEmit": true,
10+
"skipLibCheck": true
11+
},
12+
"include": ["*", "**/*"]
13+
}

0 commit comments

Comments
 (0)