Skip to content

Commit 2532c4e

Browse files
committed
bug fixes, dist build
1 parent c8f2eef commit 2532c4e

6 files changed

Lines changed: 79 additions & 32 deletions

File tree

.vscode/server.crt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICfjCCAecCFGoKwe9jqvLXZUsAKK8R9rBoxQBVMA0GCSqGSIb3DQEBCwUAMH4x
3+
CzAJBgNVBAYTAklOMRMwEQYDVQQIDApBaml0IEt1bWFyMQwwCgYDVQQHDANCU1Ax
4+
DjAMBgNVBAoMBUZYREJHMQwwCgYDVQQLDANERVYxDTALBgNVBAMMBEFqaXQxHzAd
5+
BgkqhkiG9w0BCQEWEG1lQGFqaXRrdW1hci5kZXYwHhcNMjIwODIxMDc0NjI1WhcN
6+
MjMwODIxMDc0NjI1WjB+MQswCQYDVQQGEwJJTjETMBEGA1UECAwKQWppdCBLdW1h
7+
cjEMMAoGA1UEBwwDQlNQMQ4wDAYDVQQKDAVGWERCRzEMMAoGA1UECwwDREVWMQ0w
8+
CwYDVQQDDARBaml0MR8wHQYJKoZIhvcNAQkBFhBtZUBhaml0a3VtYXIuZGV2MIGf
9+
MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQClD9GyID1GNGCdsq8vshf2h/tMUzxW
10+
mWqOoBi8ZSUrQGoZJ4vxSk5+kPkSvaZzj4zs+LnUMqIXPu1KSIXflVRXzAvh5VIE
11+
7M0ithYYbGPSyviUWpatdLCvLCOPXZPTXc+66mY7RnCVzlBqGKOR2H4goeGWq0zG
12+
Q+V3pAM7gLUJsQIDAQABMA0GCSqGSIb3DQEBCwUAA4GBAHpMjw8nYPtJ20jO2i6M
13+
kJg09Hk91g63HEx4noV8WallM80exNYWJgzNI69UIRdh78QAEknJh43TSF61bVpo
14+
i+mtBHzZLyPv4LHKNN+6eBoMxi58tbWVZXQB4awW6d1AstHY10aSygOmOUKLtGxr
15+
lYt6v4QwWrm3j7oNCDRDwxlj
16+
-----END CERTIFICATE-----

.vscode/server.key

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
Proc-Type: 4,ENCRYPTED
3+
DEK-Info: DES-EDE3-CBC,F6E1E7807FC07585
4+
5+
1RxeEBdxtQ0+Erd+wmDLuaHy07d81+5uqCBZ1FVkzFOReCwDHFvqT9pyo00soIBJ
6+
ECcUOQyVoV7XyQKZVna+XwQJ8WoiF7R0dVeP7q1E8whFhVD+ybnwvCHSe9Zv1DTo
7+
8R74rrAqRRKOf0aFEt2DR3sO9vdljOQY0JSTOefFisJs++FSDGSMPzyoUjyGzix+
8+
jOcbA9BjPoossVRNSNta9q7IMZRvYnF+mqbeKrlQ7dDV6BBCICJ15syzp0FFZcry
9+
7Upmstp+HtFphDr1ABaXlbSzPIzj+lYBro4vV4v/FuyGigwzYhiftTzypz0sVV2u
10+
yOSIGkQkNrg+0iaD35BuLzuZnKvlmjwBeFL0xlN0oh2yUSqveTUwiyGXhJxqjuKe
11+
lK9LEkKFtkj+BB0gwKy0aHNYM7Z3F2FfNGd/FlxxEbZMfORm03W/I3ploJLKk6kO
12+
H69Rkh+5lPsO0q89YBuqptiJH4cgKSup+yWH8LASbz+nuxLEKJTasJZJFEFxO62v
13+
gVHARgwv/V5HYqE4FF860mQs/ZiRVJfTN1HWZ4OpEHjJMuDhWLCyqxHeLMvL8nxd
14+
5qm9cGoguHWmv7JLe/R238AZhYg6eBybg+WAqOJZ2LdMQjAKFa5+oWezCAk1uLI9
15+
v12C5EBYZFI7znx2C4A+YAN7a3HAf+p6o467c1aL/8CQdb37soSpdnAKApx1uFBp
16+
TBxPrNXBOkND/bdU/w4E1lqMPg5KPFNn3gYe7YTB0fG4YqrBfpA0uswBdNHf4u4E
17+
u2Q99Fw9dIsj/BMkwFxTWM0Mb119VPyZm5nd5L4Y0GZmhND4UyVV0A==
18+
-----END RSA PRIVATE KEY-----

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"liveServer.settings.https": {
3+
"enable": true, //set it true to enable the feature.
4+
"cert": "D:/Github/deadlyjack/acode-plugin-prettier/.vscode/server.crt",
5+
"key": "D:/Github/deadlyjack/acode-plugin-prettier/.vscode/server.key",
6+
"passphrase": "1234"
7+
}
8+
}

dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
},
2020
"scripts": {
2121
"build": "webpack"
22-
}
22+
},
23+
"browserslist": [
24+
"> 0.25%, not dead"
25+
]
2326
}

src/main.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import prettierParserMeriyah from "prettier/parser-meriyah";
1111
import prettierParserPostcss from "prettier/parser-postcss";
1212
import prettierParserTypescript from "prettier/parser-typescript";
1313
import prettierParserYaml from "prettier/parser-yaml";
14+
import plugin from '../plugin.json';
1415

1516
const plugins = [
1617
prettierParserBabel,
@@ -27,9 +28,12 @@ const plugins = [
2728
prettierParserYaml,
2829
];
2930

30-
const pluginId = "acode.plugin.prettier";
31+
const pluginId = plugin.id;
3132

3233
class Prettier {
34+
constructor() {
35+
this.run = this.run.bind(this);
36+
}
3337
static inferParser(filename) {
3438
switch (filename.slice(filename.lastIndexOf(".") + 1)) {
3539
case "html":
@@ -80,14 +84,36 @@ class Prettier {
8084

8185
async init() {
8286
const config = appSettings.value[pluginId];
87+
const extensions = [
88+
"html",
89+
"htm",
90+
"css",
91+
"scss",
92+
"less",
93+
"js",
94+
"cjs",
95+
"es",
96+
"mjs",
97+
"jsx",
98+
"ts",
99+
"tsx",
100+
"vue",
101+
"json",
102+
"hbs",
103+
"handlebars",
104+
"md",
105+
"yaml",
106+
"yml",
107+
];
108+
109+
acode.registerFormatter(pluginId, extensions, this.run);
83110
}
84111

85112
async run() {
86113
const { editor, activeFile } = editorManager;
87114
const code = editor.getValue();
88115
const cursorPos = editor.getCursorPosition();
89116
const parser = Prettier.inferParser(activeFile.name);
90-
console.log("biraj's parser is", parser);
91117
const res = prettier.formatWithCursor(code, {
92118
parser,
93119
cursorOffset: this.#cursorPosTocursorOffset(cursorPos),
@@ -96,12 +122,12 @@ class Prettier {
96122
});
97123
editor.setValue(res.formatted);
98124
const { row, column } = this.#cursorOffsetTocursorPos(res.cursorOffset);
99-
setTimeout(() => {
100-
editor.gotoLine(row + 1, column - 1);
101-
}, 100);
125+
editor.gotoLine(row + 1, column - 1);
102126
}
103127

104-
destroy() {}
128+
destroy() {
129+
acode.unregisterFormatter(plugin.id);
130+
}
105131

106132
#cursorPosTocursorOffset(cursorPos) {
107133
let { row, column } = cursorPos;
@@ -145,28 +171,4 @@ if (window.acode) {
145171
acode.setPluginUnmount(pluginId, () => {
146172
prettier.destroy();
147173
});
148-
149-
const extensions = [
150-
"html",
151-
"htm",
152-
"css",
153-
"scss",
154-
"less",
155-
"js",
156-
"cjs",
157-
"es",
158-
"mjs",
159-
"jsx",
160-
"ts",
161-
"tsx",
162-
"vue",
163-
"json",
164-
"hbs",
165-
"handlebars",
166-
"md",
167-
"yaml",
168-
"yml",
169-
];
170-
171-
acode.registerFormatter(pluginId, extensions, prettier.run.bind(prettier));
172174
}

0 commit comments

Comments
 (0)