coc-vscode-loader 1.0.3 → 1.1.1

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/lib/index.js CHANGED
@@ -41,38 +41,6 @@ var fs = __toESM(require("fs"));
41
41
  var os = __toESM(require("os"));
42
42
  var REMOTE_REGISTRY_URL = "https://raw.githubusercontent.com/coc-plugin/coc-vscode-registry/main/registry.json";
43
43
  var CACHE_PATH = path.join(os.homedir(), ".config", "coc", "converter-cache", "registry.json");
44
- var BUILTIN_REGISTRY = [
45
- {
46
- name: "volar",
47
- displayName: "Volar (Vue)",
48
- description: "Vue language support \u2014 template/script/style IntelliSense",
49
- type: "ts-bridge",
50
- source: { type: "github", repo: "vuejs/language-tools", subdir: "extensions/vscode" },
51
- url: "https://github.com/vuejs/language-tools",
52
- languages: ["vue"],
53
- categories: ["LSP", "TypeScript"]
54
- },
55
- {
56
- name: "prisma",
57
- displayName: "Prisma",
58
- description: "Prisma schema language support \u2014 syntax highlight, lint, format",
59
- type: "pure-lsp",
60
- source: { type: "github", repo: "prisma/language-tools", subdir: "packages/vscode" },
61
- url: "https://github.com/prisma/language-tools",
62
- languages: ["prisma"],
63
- categories: ["LSP"]
64
- },
65
- {
66
- name: "html-css-support",
67
- displayName: "HTML CSS Support",
68
- description: "CSS class name completion for HTML attributes",
69
- type: "direct-api",
70
- source: { type: "github", repo: "ecmel/vscode-html-css" },
71
- url: "https://github.com/ecmel/vscode-html-css",
72
- languages: ["html", "css"],
73
- categories: ["Completion"]
74
- }
75
- ];
76
44
  var cached = null;
77
45
  function loadCache() {
78
46
  try {
@@ -96,7 +64,7 @@ async function updateRegistry() {
96
64
  function getAllPackages() {
97
65
  if (cached) return cached;
98
66
  cached = loadCache();
99
- return cached || BUILTIN_REGISTRY;
67
+ return cached || [];
100
68
  }
101
69
  function getPackage(name) {
102
70
  return getAllPackages().find((p) => p.name === name);
@@ -113,12 +81,16 @@ function createInitialState() {
113
81
  const packages = getAllPackages().map((info) => {
114
82
  const installed = isInstalled(info.name);
115
83
  let commit;
84
+ let commitMsg;
85
+ let commitDate;
116
86
  if (installed) {
117
87
  try {
118
88
  const meta = JSON.parse(
119
89
  fs2.readFileSync(path2.join(os2.homedir(), ".config", "coc", "converter-cache", info.name, "meta.json"), "utf-8")
120
90
  );
121
91
  commit = meta.commit || void 0;
92
+ commitMsg = meta.msg || void 0;
93
+ commitDate = meta.date || void 0;
122
94
  } catch {
123
95
  }
124
96
  }
@@ -126,6 +98,8 @@ function createInitialState() {
126
98
  info,
127
99
  status: installed ? "installed" : "not-installed",
128
100
  commit,
101
+ commitMsg,
102
+ commitDate,
129
103
  progressLog: [],
130
104
  expanded: false,
131
105
  logExpanded: false
@@ -165,6 +139,9 @@ var StateManager = class {
165
139
  this.mutate((s) => {
166
140
  const pkg = s.packages.find((p) => p.info.name === name);
167
141
  if (pkg) {
142
+ if (status === "installing" || status === "updating" || status === "uninstalling") {
143
+ pkg.progressLog = [];
144
+ }
168
145
  pkg.status = status;
169
146
  if (extra?.progress !== void 0) pkg.progress = extra.progress;
170
147
  if (extra?.logEntry !== void 0) pkg.progressLog.push(extra.logEntry);
@@ -234,6 +211,26 @@ var StateManager = class {
234
211
  getPackage(name) {
235
212
  return this.state.packages.find((p) => p.info.name === name);
236
213
  }
214
+ refreshPackages() {
215
+ this.mutate((s) => {
216
+ const updated = getAllPackages();
217
+ const oldMap = new Map(s.packages.map((p) => [p.info.name, p]));
218
+ s.packages = updated.map((info) => {
219
+ const old = oldMap.get(info.name);
220
+ if (old) {
221
+ old.info = info;
222
+ return old;
223
+ }
224
+ return {
225
+ info,
226
+ status: isInstalled(info.name) ? "installed" : "not-installed",
227
+ progressLog: [],
228
+ expanded: false,
229
+ logExpanded: false
230
+ };
231
+ });
232
+ });
233
+ }
237
234
  };
238
235
 
239
236
  // src/tui.ts
@@ -259,10 +256,12 @@ function pluginDir(name) {
259
256
  }
260
257
  function converterCliPath() {
261
258
  const base = path3.resolve(__dirname, "..");
259
+ const cwd = process.cwd();
262
260
  const candidates = [
261
+ path3.join(base, "converter", "src", "cli.ts"),
263
262
  path3.join(base, "..", "converter", "src", "cli.ts"),
264
- path3.join(base, "..", "..", "converter", "src", "cli.ts"),
265
- path3.join(base, "..", "..", "..", "converter", "src", "cli.ts")
263
+ path3.join(cwd, "converter", "src", "cli.ts"),
264
+ path3.join(cwd, "..", "converter", "src", "cli.ts")
266
265
  ];
267
266
  for (const p of candidates) {
268
267
  if (fs3.existsSync(p)) return p;
@@ -313,14 +312,50 @@ async function convertSource(inputDir, name, onProgress) {
313
312
  await run("npx", ["tsx", cli, "convert", inputDir, "-o", build], cacheDir(name), () => {
314
313
  });
315
314
  }
316
- async function buildPackage(name, onProgress) {
315
+ async function buildPackage(name, inputDir, info, onProgress) {
317
316
  const build = buildDir(name);
318
317
  onProgress(3, 5, "Installing dependencies...", "npm install --legacy-peer-deps");
319
318
  await run("npm", ["install", "--legacy-peer-deps"], build, () => {
320
319
  });
320
+ onProgress(3, 5, "Running postinstall...", "npm run postinstall");
321
+ await run("npm", ["run", "postinstall", "--if-present"], build, () => {
322
+ }).catch(() => {
323
+ });
324
+ const serverDir = path3.join(inputDir, "server");
325
+ if (fs3.existsSync(serverDir) && fs3.existsSync(path3.join(serverDir, "package.json"))) {
326
+ onProgress(3, 5, "Installing server dependencies...", `npm install in ${serverDir}`);
327
+ await run("npm", ["install", "--legacy-peer-deps"], serverDir, () => {
328
+ });
329
+ const destServer = path3.join(build, "server");
330
+ if (fs3.existsSync(destServer)) fs3.rmSync(destServer, { recursive: true });
331
+ fs3.cpSync(serverDir, destServer, { recursive: true });
332
+ }
321
333
  onProgress(4, 5, "Building...", "node esbuild.mjs");
322
334
  await run("node", ["esbuild.mjs"], build, () => {
323
335
  });
336
+ if (info.serverBinary) {
337
+ const sb = info.serverBinary;
338
+ onProgress(4, 5, "Downloading language server...", `fetching ${sb.repo}`);
339
+ try {
340
+ const tagData = await runWithOutput("gh", ["api", `repos/${sb.repo}/releases/latest`, "--jq", ".tag_name"], os3.homedir());
341
+ const version = tagData.replace(/^v/, "");
342
+ const arch2 = os3.arch() === "arm64" ? "arm64" : "x64";
343
+ const platform = process.platform === "win32" ? "win32" : process.platform === "darwin" ? "darwin" : "linux";
344
+ const filename = sb.asset.replace("{{version}}", version).replace("{{platform}}", platform).replace("{{arch}}", arch2);
345
+ const url = `https://github.com/${sb.repo}/releases/download/${version}/${filename}`;
346
+ onProgress(4, 5, "Downloading...", `curl ${filename}`);
347
+ await run("curl", ["-sSL", url, "-o", path3.join(build, filename)], build, () => {
348
+ });
349
+ onProgress(4, 5, "Extracting...", `tar xzf ${filename}`);
350
+ const serverDir2 = path3.join(build, "server");
351
+ fs3.mkdirSync(serverDir2, { recursive: true });
352
+ await run("tar", ["xzf", filename, "-C", serverDir2], build, () => {
353
+ });
354
+ fs3.rmSync(path3.join(build, filename));
355
+ } catch {
356
+ onProgress(4, 5, "Warning: server download failed", "install server binary manually");
357
+ }
358
+ }
324
359
  }
325
360
  function extensionsPkgPath() {
326
361
  return path3.join(os3.homedir(), ".config", "coc", "extensions", "package.json");
@@ -347,8 +382,9 @@ function metaPath(name) {
347
382
  function saveMeta(name) {
348
383
  const srcDir = sourceDir(name);
349
384
  try {
350
- const commit = (0, import_child_process.execSync)("git", ["-C", srcDir, "rev-parse", "--short", "HEAD"], { encoding: "utf-8" }).toString().trim();
351
- fs3.writeFileSync(metaPath(name), JSON.stringify({ commit, updatedAt: Date.now() }, null, 2));
385
+ const log = (0, import_child_process.execSync)(`git -C "${srcDir}" log -1 --format="%h|%s|%ar"`, { encoding: "utf-8" }).toString().trim();
386
+ const [commit, msg, date] = log.split("|");
387
+ fs3.writeFileSync(metaPath(name), JSON.stringify({ commit, msg, date, updatedAt: Date.now() }, null, 2));
352
388
  } catch {
353
389
  }
354
390
  }
@@ -370,11 +406,26 @@ async function installPackage(state, name) {
370
406
  try {
371
407
  const input = await downloadSource(info, name, prog);
372
408
  await convertSource(input, name, prog);
373
- await buildPackage(name, prog);
409
+ await buildPackage(name, input, info, prog);
374
410
  await installToCoc(name, prog);
375
411
  saveMeta(name);
376
412
  state.setDirty();
377
413
  state.setPackageStatus(name, "installed");
414
+ try {
415
+ const meta = JSON.parse(fs3.readFileSync(metaPath(name), "utf-8"));
416
+ if (meta.commit) {
417
+ state.mutate((s) => {
418
+ const p = s.packages.find((p2) => p2.info.name === name);
419
+ if (p) {
420
+ p.commit = meta.commit;
421
+ p.commitMsg = meta.msg;
422
+ p.commitDate = meta.date;
423
+ p.updated = true;
424
+ }
425
+ });
426
+ }
427
+ } catch {
428
+ }
378
429
  } catch (e) {
379
430
  state.setPackageStatus(name, "failed", { error: e.message });
380
431
  }
@@ -424,11 +475,26 @@ async function updatePackage(state, name) {
424
475
  try {
425
476
  const input = await downloadSource(info, name, prog);
426
477
  await convertSource(input, name, prog);
427
- await buildPackage(name, prog);
478
+ await buildPackage(name, input, info, prog);
428
479
  await installToCoc(name, prog);
429
480
  saveMeta(name);
430
481
  state.setDirty();
431
482
  state.setPackageStatus(name, "installed");
483
+ try {
484
+ const meta = JSON.parse(fs3.readFileSync(metaPath(name), "utf-8"));
485
+ if (meta.commit) {
486
+ state.mutate((s) => {
487
+ const p = s.packages.find((p2) => p2.info.name === name);
488
+ if (p) {
489
+ p.commit = meta.commit;
490
+ p.commitMsg = meta.msg;
491
+ p.commitDate = meta.date;
492
+ p.updated = true;
493
+ }
494
+ });
495
+ }
496
+ } catch {
497
+ }
432
498
  } catch (e) {
433
499
  state.setPackageStatus(name, "failed", { error: e.message });
434
500
  }
@@ -912,6 +978,15 @@ var TUI = class {
912
978
  if (entry.hasUpdate) {
913
979
  buf.append(" \u2191", "CocConverterKey");
914
980
  }
981
+ if (entry.updated && entry.commit && entry.commitMsg) {
982
+ buf.nl();
983
+ const ln = buf.currentLine();
984
+ buf.append(` ${entry.commit} ${entry.commitMsg}`, "Comment");
985
+ if (entry.commitDate) {
986
+ buf.append(` (${entry.commitDate})`, "Comment");
987
+ }
988
+ pkgLineMap.set(ln, entry.info.name);
989
+ }
915
990
  if (entry.expanded) {
916
991
  buf.nl();
917
992
  for (const text of [
@@ -1070,6 +1145,8 @@ async function activate(context) {
1070
1145
  }
1071
1146
  })
1072
1147
  );
1148
+ updateRegistry().then(() => state.refreshPackages()).catch(() => {
1149
+ });
1073
1150
  import_coc2.window.showInformationMessage("coc-loader activated! Use :CocCommand loader.open");
1074
1151
  }
1075
1152
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coc-vscode-loader",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "description": "Run VS Code extensions seamlessly in coc.nvim",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [
@@ -24,16 +24,22 @@
24
24
  "coc": ">= 0.0.80"
25
25
  },
26
26
  "scripts": {
27
- "build": "node esbuild.mjs",
27
+ "bundle-converter": "rm -rf converter && cp -r ../converter ./converter && cd converter && npm install --legacy-peer-deps",
28
+ "build": "npm run bundle-converter && node esbuild.mjs",
28
29
  "prepare": "node esbuild.mjs"
29
30
  },
30
31
  "devDependencies": {
31
32
  "coc.nvim": "^0.0.83-next.18",
32
- "esbuild": "^0.25.0",
33
- "typescript": "^5.3.3"
33
+ "esbuild": "^0.28.1",
34
+ "typescript": "^6.0.3"
34
35
  },
35
36
  "activationEvents": [
36
37
  "onCommand:loader.open",
38
+ "onCommand:loader.install",
39
+ "onCommand:loader.uninstall",
40
+ "onCommand:loader.update",
41
+ "onCommand:loader.uninstallAll",
42
+ "onCommand:loader.updateRegistry",
37
43
  "onCommand:loader._dispatch"
38
44
  ],
39
45
  "contributes": {