@ttsc/vscode 0.13.1 → 0.14.0-dev.20250530.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/README.md CHANGED
@@ -2,72 +2,62 @@
2
2
 
3
3
  ![banner of @ttsc/vscode](https://ttsc.dev/og.jpg)
4
4
 
5
- MIT licensed · [npm](https://www.npmjs.com/package/@ttsc/vscode) · [docs](https://ttsc.dev/docs) · [Discord](https://discord.gg/E94XhzrUCZ)
5
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/ttsc/blob/master/LICENSE) [![NPM Version](https://img.shields.io/npm/v/@ttsc/vscode.svg)](https://www.npmjs.com/package/@ttsc/vscode) [![NPM Downloads](https://img.shields.io/npm/dm/@ttsc/vscode.svg)](https://www.npmjs.com/package/@ttsc/vscode) [![Build Status](https://github.com/samchon/ttsc/workflows/test/badge.svg)](https://github.com/samchon/ttsc/actions?query=workflow%3Atest) [![Guide Documents](https://img.shields.io/badge/Guide-Documents-forestgreen)](https://ttsc.dev/docs) [![Discord Badge](https://img.shields.io/badge/discord-samchon-d91965?style=flat&labelColor=5866f2&logo=discord&logoColor=white&link=https://discord.gg/E94XhzrUCZ)](https://discord.gg/E94XhzrUCZ)
6
6
 
7
- VSCode extension for [`ttsc`](https://ttsc.dev) projects.
7
+ VS Code extension for [`ttsc`](https://ttsc.dev) projects. It shows TypeScript-Go diagnostics and `@ttsc/lint` lint and format inside your editor.
8
8
 
9
- Lint diagnostics, format hints, and plugin code actions appear in your editor live — the same diagnostics `ttsc` would emit at build time, shown as you type.
9
+ ## Setup
10
10
 
11
- ## Requirements
11
+ ### Requirements
12
12
 
13
13
  - **VS Code** 1.94 or later
14
14
  - **Node.js** 18 or later
15
- - **`ttsc` installed in your project** the extension uses the language server that ships with your project's `ttsc` package
15
+ - **`ttsc`, `@ttsc/lint`, and `@typescript/native-preview` in your project.** `@typescript/native-preview` is the TypeScript-Go engine `ttsc` runs on; it is a separate package that `ttsc` does not bundle.
16
16
 
17
17
  ```bash
18
18
  npm install -D ttsc @ttsc/lint @typescript/native-preview
19
19
  ```
20
20
 
21
- ## Install
21
+ ### Install
22
22
 
23
- The extension is not on the VS Code Marketplace yet. For now it ships as an npm package with a one-shot installer:
23
+ Not on the VS Code Marketplace yet. Run `npx @ttsc/vscode`; it downloads the package and installs the bundled `.vsix` into VS Code, nothing to keep as a dependency:
24
24
 
25
25
  ```bash
26
- npm install -D @ttsc/vscode
27
- npx ttsc-vscode
26
+ npx @ttsc/vscode
28
27
  ```
29
28
 
30
- `npx ttsc-vscode` calls `code --install-extension` with the `.vsix` bundled in the npm tarball VS Code picks it up immediately, no restart needed.
29
+ If the `code` CLI isn't on your `PATH`, run **Shell Command: Install 'code' command in PATH** from VS Code's command palette, then re-run `npx @ttsc/vscode`.
31
30
 
32
- If the `code` CLI isn't on your `PATH`, open VS Code first, run **Shell Command: Install 'code' command in PATH** from the command palette, then re-run `npx ttsc-vscode`. (As a manual fallback, VS Code → Extensions → "…" menu → **Install from VSIX** also works on the file `npx ttsc-vscode` would have used — it lives under `node_modules/@ttsc/vscode/dist/`.)
31
+ ### Format on save
33
32
 
34
- To uninstall:
33
+ Set `samchon.ttsc` as the default formatter and turn on `editor.formatOnSave` in `.vscode/settings.json`:
35
34
 
36
- ```bash
37
- npx ttsc-vscode uninstall
35
+ ```jsonc
36
+ "[typescript][typescriptreact]": {
37
+ "editor.defaultFormatter": "samchon.ttsc",
38
+ "editor.formatOnSave": true
39
+ }
38
40
  ```
39
41
 
40
- Marketplace release is tracked for v1; once it lands, the `npx` step goes away.
41
-
42
- ## What it adds
43
-
44
- The extension activates on any TypeScript, JavaScript, TSX, or JSX file inside a project that has `ttsc` installed.
42
+ Lint **fixes** stay off-save by default because they can change code meaning. Run `ttsc: Fix all lint issues` from the command palette, or opt in with `"editor.codeActionsOnSave": { "source.fixAll.ttsc": "explicit" }`.
45
43
 
46
- - **Live lint underlines.** Violations from `@ttsc/lint` (and any third-party rule plugins you've installed) appear in the same gutter as TypeScript type errors — same `error TSxxxxx` shape.
47
- - **Quick fixes** for autofixable rules under the lightbulb menu.
48
- - **Command palette entries:**
49
- - `ttsc: Apply lint fixes to current file`
50
- - `ttsc: Format current document`
51
- - `ttsc: Restart language server`
44
+ The format rules come from your project's `lint.config`, so format-on-save does nothing until that config has a `format` block.
52
45
 
53
- The extension's identifier inside VS Code is `samchon.ttsc`.
46
+ ## What it adds
54
47
 
55
- ## Settings
48
+ - TypeScript-Go diagnostics, hover, navigation, and completions.
49
+ - `@ttsc/lint` lint diagnostics, plus `ttsc: Fix all lint issues` and `ttsc: Format document` in the command palette.
50
+ - Format on save with `@ttsc/lint`'s rules, shown above.
51
+ - Monorepo-aware: each package uses its own `tsconfig` and `lint.config`.
56
52
 
57
- Open VS Code's settings (`Ctrl+,` / `Cmd+,`) and search for `ttsc`, or edit `settings.json` directly:
53
+ ## Troubleshooting
58
54
 
59
- | Setting | Default | Effect |
60
- | --- | --- | --- |
61
- | `ttsc.serverPath` | `""` | Absolute path to a language-server binary. Empty means use the one bundled with the project's `ttsc` install — almost always what you want. |
62
- | `ttsc.trace.server` | `"off"` | Set to `"messages"` or `"verbose"` to log LSP traffic. The log goes to **View → Output → ttsc**. Useful when diagnostics don't show up. |
55
+ No diagnostics? Confirm `ttsc` runs in the project (`npx ttsc --version`), then check **View → Output → ttsc** for the server log. For LSP tracing, set `ttsc.trace.server` to `"verbose"`.
63
56
 
64
- ## Troubleshooting
57
+ ## Sponsors
65
58
 
66
- If lint underlines don't appear after install:
59
+ [![Sponsors](https://raw.githubusercontent.com/samchon/sponsor-images/refs/heads/master/public/circle.png)](https://github.com/sponsors/samchon)
67
60
 
68
- 1. **Check the project has `ttsc`:** `npx ttsc --version`. If this errors, install `ttsc @ttsc/lint @typescript/native-preview` in the project first.
69
- 2. **Read the server log:** open **View → Output**, pick **ttsc** from the dropdown.
70
- 3. **Restart the server:** command palette → `ttsc: Restart language server`.
71
- 4. **Verbose tracing:** set `ttsc.trace.server` to `"verbose"`, repeat step 2.
61
+ Thanks for your support.
72
62
 
73
- If `npx ttsc-vscode` errors with `\`code\` CLI not found on PATH`: open VS Code → command palette → **Shell Command: Install 'code' command in PATH**, then retry the install.
63
+ Your [donation](https://github.com/sponsors/samchon) encourages `ttsc` development.
package/bin/install.js CHANGED
@@ -6,39 +6,105 @@ const path = require("node:path");
6
6
  const pkgRoot = path.resolve(__dirname, "..");
7
7
  const distDir = path.join(pkgRoot, "dist");
8
8
  const extensionId = "samchon.ttsc";
9
-
10
- const sub = process.argv[2] ?? "install";
9
+ const version = require(path.join(pkgRoot, "package.json")).version;
11
10
 
12
11
  function findVsix() {
13
12
  if (!fs.existsSync(distDir)) return null;
14
- const hits = fs.readdirSync(distDir).filter((f) => f.endsWith(".vsix"));
15
- return hits.length ? path.join(distDir, hits[0]) : null;
13
+ const expected = path.join(distDir, `ttsc-vscode-${version}.vsix`);
14
+ return fs.existsSync(expected) ? expected : null;
16
15
  }
17
16
 
18
- function runCode(args, vsixForFallback) {
19
- const r = cp.spawnSync("code", args, { stdio: "inherit" });
17
+ function createCodeCommand(
18
+ args,
19
+ platform = process.platform,
20
+ env = process.env,
21
+ ) {
22
+ if (platform === "win32") {
23
+ return {
24
+ command: env.ComSpec || "cmd.exe",
25
+ args: ["/d", "/s", "/c", quoteWindowsCommand(["code", ...args])],
26
+ };
27
+ }
28
+ return { command: "code", args };
29
+ }
30
+
31
+ function quoteWindowsCommand(args) {
32
+ return `"${args.map(quoteWindowsArg).join(" ")}"`;
33
+ }
34
+
35
+ function quoteWindowsArg(arg) {
36
+ return `"${String(arg).replace(/"/g, '\\"').replace(/%/g, "%%")}"`;
37
+ }
38
+
39
+ function spawnCode(args, vsixForFallback) {
40
+ const command = createCodeCommand(args);
41
+ const r = cp.spawnSync(command.command, command.args, { stdio: "inherit" });
20
42
  if (r.error && r.error.code === "ENOENT") {
21
- console.error("`code` CLI not found on PATH.");
22
- console.error("Either:");
23
- console.error(" - Open VSCode, then run \"Shell Command: Install 'code' command in PATH\" from the command palette.");
24
- if (vsixForFallback) {
25
- console.error(` - Or install manually: VSCode > Extensions > \"...\" menu > Install from VSIX > ${vsixForFallback}`);
26
- }
43
+ printCodeNotFound(vsixForFallback);
27
44
  process.exit(1);
28
45
  }
29
- process.exit(r.status ?? 1);
46
+ return r.status ?? 1;
47
+ }
48
+
49
+ function runCode(args, vsixForFallback) {
50
+ const status = spawnCode(args, vsixForFallback);
51
+ if (process.platform === "win32" && status !== 0) {
52
+ printCodeFailed(status, vsixForFallback);
53
+ }
54
+ process.exit(status);
55
+ }
56
+
57
+ function printCodeNotFound(vsixForFallback) {
58
+ console.error("`code` CLI not found on PATH.");
59
+ console.error("Either:");
60
+ console.error(
61
+ " - Open VS Code, then run \"Shell Command: Install 'code' command in PATH\" from the command palette.",
62
+ );
63
+ if (vsixForFallback) {
64
+ console.error(
65
+ ` - Or install manually: VS Code > Extensions > \"...\" menu > Install from VSIX > ${vsixForFallback}`,
66
+ );
67
+ }
68
+ }
69
+
70
+ function printCodeFailed(status, vsixForFallback) {
71
+ console.error(`VS Code CLI exited with status ${status}.`);
72
+ if (vsixForFallback) {
73
+ console.error(
74
+ `Install manually: VS Code > Extensions > "..." menu > Install from VSIX > ${vsixForFallback}`,
75
+ );
76
+ }
30
77
  }
31
78
 
32
- if (sub === "install") {
33
- const vsix = findVsix();
34
- if (!vsix) {
35
- console.error(`No .vsix bundled in ${distDir}. Reinstall @ttsc/vscode or report a packaging bug.`);
79
+ function main(argv = process.argv.slice(2)) {
80
+ const sub = argv[0] ?? "install";
81
+ if (sub === "install") {
82
+ const vsix = findVsix();
83
+ if (!vsix) {
84
+ console.error(
85
+ `No .vsix bundled in ${distDir}. Reinstall @ttsc/vscode or report a packaging bug.`,
86
+ );
87
+ process.exit(1);
88
+ }
89
+ // Remove any previously installed version first so versions do not pile up
90
+ // in VS Code. Ignore its exit status: the extension may not be installed.
91
+ spawnCode(["--uninstall-extension", extensionId], vsix);
92
+ runCode(["--install-extension", vsix, "--force"], vsix);
93
+ } else if (sub === "uninstall") {
94
+ runCode(["--uninstall-extension", extensionId]);
95
+ } else {
96
+ console.error(`Usage: npx @ttsc/vscode <install|uninstall>`);
36
97
  process.exit(1);
37
98
  }
38
- runCode(["--install-extension", vsix, "--force"], vsix);
39
- } else if (sub === "uninstall") {
40
- runCode(["--uninstall-extension", extensionId]);
41
- } else {
42
- console.error(`Usage: ttsc-vscode <install|uninstall>`);
43
- process.exit(1);
44
99
  }
100
+
101
+ if (require.main === module) {
102
+ main();
103
+ }
104
+
105
+ module.exports = {
106
+ createCodeCommand,
107
+ findVsix,
108
+ main,
109
+ quoteWindowsCommand,
110
+ };