tailwint 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lsp.js +51 -2
- package/package.json +1 -1
package/dist/lsp.js
CHANGED
|
@@ -3,8 +3,55 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { spawn } from "child_process";
|
|
5
5
|
import { resolve } from "path";
|
|
6
|
-
import { existsSync } from "fs";
|
|
6
|
+
import { existsSync, readFileSync } from "fs";
|
|
7
7
|
const DEBUG = process.env.DEBUG === "1";
|
|
8
|
+
let workspaceRoot = "";
|
|
9
|
+
let vscodeSettings = null;
|
|
10
|
+
/** Load .vscode/settings.json once, cache the result. */
|
|
11
|
+
function loadVscodeSettings() {
|
|
12
|
+
if (vscodeSettings !== null)
|
|
13
|
+
return vscodeSettings;
|
|
14
|
+
const settingsPath = resolve(workspaceRoot, ".vscode/settings.json");
|
|
15
|
+
if (!existsSync(settingsPath)) {
|
|
16
|
+
vscodeSettings = {};
|
|
17
|
+
return vscodeSettings;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
// Strip single-line comments (// ...) and trailing commas for JSON compat
|
|
21
|
+
const raw = readFileSync(settingsPath, "utf-8")
|
|
22
|
+
.replace(/\/\/[^\n]*/g, "")
|
|
23
|
+
.replace(/,\s*([\]}])/g, "$1");
|
|
24
|
+
vscodeSettings = JSON.parse(raw);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
vscodeSettings = {};
|
|
28
|
+
}
|
|
29
|
+
return vscodeSettings;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Extract a section from flat VS Code settings into a nested object.
|
|
33
|
+
* e.g. section "tailwindCSS" turns { "tailwindCSS.lint.cssConflict": "error" }
|
|
34
|
+
* into { lint: { cssConflict: "error" } }
|
|
35
|
+
*/
|
|
36
|
+
function getSettingsSection(section) {
|
|
37
|
+
const settings = loadVscodeSettings();
|
|
38
|
+
const prefix = section + ".";
|
|
39
|
+
const result = {};
|
|
40
|
+
for (const [key, value] of Object.entries(settings)) {
|
|
41
|
+
if (!key.startsWith(prefix))
|
|
42
|
+
continue;
|
|
43
|
+
const path = key.slice(prefix.length).split(".");
|
|
44
|
+
let target = result;
|
|
45
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
46
|
+
if (!(path[i] in target) || typeof target[path[i]] !== "object") {
|
|
47
|
+
target[path[i]] = {};
|
|
48
|
+
}
|
|
49
|
+
target = target[path[i]];
|
|
50
|
+
}
|
|
51
|
+
target[path[path.length - 1]] = value;
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
8
55
|
let server;
|
|
9
56
|
let serverDead = false;
|
|
10
57
|
let msgId = 0;
|
|
@@ -33,6 +80,7 @@ export function resetState() {
|
|
|
33
80
|
diagTarget = 0;
|
|
34
81
|
diagTargetResolve = null;
|
|
35
82
|
diagWaiters.clear();
|
|
83
|
+
vscodeSettings = null;
|
|
36
84
|
}
|
|
37
85
|
/** Returns a promise that resolves when @/tailwindCSS/projectInitialized fires. */
|
|
38
86
|
export function waitForProjectReady(timeoutMs = 15_000) {
|
|
@@ -153,7 +201,7 @@ function processMessages() {
|
|
|
153
201
|
if (msg.id != null && msg.method) {
|
|
154
202
|
let result = null;
|
|
155
203
|
if (msg.method === "workspace/configuration") {
|
|
156
|
-
result = (msg.params?.items || []).map(() => ({})
|
|
204
|
+
result = (msg.params?.items || []).map((item) => item.section ? getSettingsSection(item.section) : {});
|
|
157
205
|
}
|
|
158
206
|
server.stdin.write(encode({ jsonrpc: "2.0", id: msg.id, result }));
|
|
159
207
|
continue;
|
|
@@ -220,6 +268,7 @@ function drainAll(reason) {
|
|
|
220
268
|
diagWaiters.clear();
|
|
221
269
|
}
|
|
222
270
|
export function startServer(root) {
|
|
271
|
+
workspaceRoot = root;
|
|
223
272
|
const bin = findLanguageServer(root);
|
|
224
273
|
server = spawn(bin, ["--stdio"], { stdio: ["pipe", "pipe", "pipe"] });
|
|
225
274
|
server.on("error", (err) => {
|