croft-software 0.2.32

VSCode-style TUI written in Rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
//! What a VS Code extension corresponds to in croft (#352).
//!
//! croft cannot run VS Code extensions, but many of the popular ones name a
//! thing croft already has: a language server, a debug adapter, a test
//! runner, a theme, a viewer. `.vscode/extensions.json` and the user's
//! installed list (`code --list-extensions`) are the last part of a VS Code
//! profile, and "you have this, you do not need that, and this has no
//! equivalent" is a better answer than silence. The table is curated data;
//! the readers never download or execute anything.

use std::path::Path;

/// How a VS Code extension maps onto croft.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Status {
    /// croft ships the equivalent; nothing to install.
    Builtin,
    /// A catalog entry croft can install on request (`croft` names its id).
    Installable,
    /// No equivalent. The `note` says what, if anything, is planned.
    None,
}

/// One row of the table.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Mapping {
    /// The marketplace id, `publisher.name`, lowercase.
    pub vscode: &'static str,
    /// The croft extension id, catalog id, or feature that covers it; empty
    /// for `Status::None`.
    pub croft: &'static str,
    pub status: Status,
    /// One line for the user: what covers it, or what does not.
    pub note: &'static str,
}

/// The curated table.
pub const TABLE: &[Mapping] = &[
    Mapping {
        vscode: "ms-python.python",
        croft: "lsp-python",
        status: Status::Builtin,
        note: "Python language support ships built in (ty and ruff); basedpyright is an optional fallback used when already installed",
    },
    Mapping {
        vscode: "ms-python.vscode-pylance",
        croft: "lsp-python",
        status: Status::Builtin,
        note: "croft bundles ty; basedpyright is an optional fallback used when already installed",
    },
    Mapping {
        vscode: "ms-python.debugpy",
        croft: "dap-python",
        status: Status::Builtin,
        note: "debugpy is croft's bundled Python debug adapter",
    },
    Mapping {
        vscode: "ms-python.black-formatter",
        croft: "lsp-python",
        status: Status::Builtin,
        note: "ruff formats Python through the language server (format_on_save)",
    },
    Mapping {
        vscode: "ms-python.isort",
        croft: "lsp-python",
        status: Status::Builtin,
        note: "ruff sorts imports through the language server's code actions",
    },
    Mapping {
        vscode: "ms-toolsai.jupyter",
        croft: "notebook view",
        status: Status::Builtin,
        note: "notebooks render in place and their cells run (Notebook: Run All Cells)",
    },
    Mapping {
        vscode: "rust-lang.rust-analyzer",
        croft: "lsp-rust",
        status: Status::Builtin,
        note: "rust-analyzer ships built in",
    },
    Mapping {
        vscode: "vadimcn.vscode-lldb",
        croft: "dap-lldb",
        status: Status::Builtin,
        note: "CodeLLDB's job is croft's bundled LLDB debug adapter",
    },
    Mapping {
        vscode: "swellaby.vscode-rust-test-adapter",
        croft: "test-cargo",
        status: Status::Builtin,
        note: "the Test Explorer runs cargo tests built in",
    },
    Mapping {
        vscode: "golang.go",
        croft: "lsp-go",
        status: Status::Builtin,
        note: "gopls, delve debugging and the go test runner ship built in",
    },
    Mapping {
        vscode: "ms-vscode.cpptools",
        croft: "lsp-cpp",
        status: Status::Builtin,
        note: "clangd for C/C++ and LLDB for debugging ship built in",
    },
    Mapping {
        vscode: "ms-vscode.cpptools-extension-pack",
        croft: "lsp-cpp",
        status: Status::Builtin,
        note: "clangd and the LLDB adapter cover the pack",
    },
    Mapping {
        vscode: "llvm-vs-code-extensions.vscode-clangd",
        croft: "lsp-cpp",
        status: Status::Builtin,
        note: "clangd ships built in",
    },
    Mapping {
        vscode: "sumneko.lua",
        croft: "lsp-lua",
        status: Status::Builtin,
        note: "lua-language-server ships built in",
    },
    Mapping {
        vscode: "luals.lua-language-server",
        croft: "lsp-lua",
        status: Status::Builtin,
        note: "lua-language-server ships built in",
    },
    Mapping {
        vscode: "ms-vscode.cmake-tools",
        croft: "",
        status: Status::None,
        note: "no CMake integration; build through tasks.json or the terminal",
    },
    Mapping {
        vscode: "twxs.cmake",
        croft: "",
        status: Status::None,
        note: "no CMake syntax support yet",
    },
    Mapping {
        vscode: "ms-vscode.makefile-tools",
        croft: "",
        status: Status::None,
        note: "no Makefile integration; run make through tasks.json or the terminal",
    },
    Mapping {
        vscode: "ms-vscode.vscode-typescript-next",
        croft: "lsp-typescript",
        status: Status::Builtin,
        note: "typescript-language-server ships built in",
    },
    Mapping {
        vscode: "dbaeumer.vscode-eslint",
        croft: "",
        status: Status::None,
        note: "type diagnostics come from the TypeScript language server; eslint itself is not run",
    },
    Mapping {
        vscode: "esbenp.prettier-vscode",
        croft: "format_on_save",
        status: Status::Builtin,
        note: "Format Document and format on save run the project's Prettier (node_modules/.bin/prettier) when it has a Prettier config",
    },
    Mapping {
        vscode: "orta.vscode-jest",
        croft: "test-jest",
        status: Status::Builtin,
        note: "the Test Explorer runs Jest built in",
    },
    Mapping {
        vscode: "firsttris.vscode-jest-runner",
        croft: "test-jest",
        status: Status::Builtin,
        note: "the Test Explorer runs Jest built in",
    },
    Mapping {
        vscode: "vitest.explorer",
        croft: "test-vitest",
        status: Status::Builtin,
        note: "the Test Explorer runs Vitest built in",
    },
    Mapping {
        vscode: "ms-playwright.playwright",
        croft: "",
        status: Status::None,
        note: "no Playwright runner; run it from the terminal",
    },
    Mapping {
        vscode: "vue.volar",
        croft: "",
        status: Status::None,
        note: "no Vue language server bundled",
    },
    Mapping {
        vscode: "svelte.svelte-vscode",
        croft: "",
        status: Status::None,
        note: "no Svelte language server bundled",
    },
    Mapping {
        vscode: "bradlc.vscode-tailwindcss",
        croft: "",
        status: Status::None,
        note: "no Tailwind language server bundled",
    },
    Mapping {
        vscode: "dsznajder.es7-react-js-snippets",
        croft: "snippets",
        status: Status::Builtin,
        note: "croft has snippets; import-vscode brings yours across",
    },
    Mapping {
        vscode: "xabikos.javascriptsnippets",
        croft: "snippets",
        status: Status::Builtin,
        note: "croft has snippets; import-vscode brings yours across",
    },
    Mapping {
        vscode: "christian-kohler.path-intellisense",
        croft: "language servers",
        status: Status::Builtin,
        note: "path completion comes from the language servers",
    },
    Mapping {
        vscode: "redhat.vscode-yaml",
        croft: "lsp-yaml",
        status: Status::Builtin,
        note: "yaml-language-server ships built in",
    },
    Mapping {
        vscode: "tamasfe.even-better-toml",
        croft: "lsp-toml",
        status: Status::Builtin,
        note: "taplo ships built in",
    },
    Mapping {
        vscode: "bungcip.better-toml",
        croft: "lsp-toml",
        status: Status::Builtin,
        note: "taplo ships built in",
    },
    Mapping {
        vscode: "zainchen.json",
        croft: "lsp-json",
        status: Status::Builtin,
        note: "the JSON language server ships built in",
    },
    Mapping {
        vscode: "timonwong.shellcheck",
        croft: "lsp-bash",
        status: Status::Builtin,
        note: "bash-language-server runs shellcheck when it is installed",
    },
    Mapping {
        vscode: "foxundermoon.shell-format",
        croft: "lsp-bash",
        status: Status::Builtin,
        note: "bash-language-server formats through shfmt when it is installed",
    },
    Mapping {
        vscode: "mads-hartmann.bash-ide-vscode",
        croft: "lsp-bash",
        status: Status::Builtin,
        note: "bash-language-server ships built in",
    },
    Mapping {
        vscode: "ms-vscode.powershell",
        croft: "",
        status: Status::None,
        note: "no PowerShell support",
    },
    Mapping {
        vscode: "ms-dotnettools.csharp",
        croft: "",
        status: Status::None,
        note: "no C# language server bundled",
    },
    Mapping {
        vscode: "ms-dotnettools.csdevkit",
        croft: "",
        status: Status::None,
        note: "no C# language server bundled",
    },
    Mapping {
        vscode: "redhat.java",
        croft: "",
        status: Status::None,
        note: "no Java language server bundled",
    },
    Mapping {
        vscode: "vscjava.vscode-java-pack",
        croft: "",
        status: Status::None,
        note: "no Java language server bundled",
    },
    Mapping {
        vscode: "dart-code.dart-code",
        croft: "",
        status: Status::None,
        note: "no Dart support",
    },
    Mapping {
        vscode: "dart-code.flutter",
        croft: "",
        status: Status::None,
        note: "no Flutter support",
    },
    Mapping {
        vscode: "hashicorp.terraform",
        croft: "",
        status: Status::None,
        note: "no Terraform language server bundled",
    },
    Mapping {
        vscode: "ms-kubernetes-tools.vscode-kubernetes-tools",
        croft: "",
        status: Status::None,
        note: "no Kubernetes integration",
    },
    Mapping {
        vscode: "ms-azuretools.vscode-docker",
        croft: "",
        status: Status::None,
        note: "no Docker integration; the terminal is one keystroke away",
    },
    Mapping {
        vscode: "ms-vscode-remote.remote-ssh",
        croft: "croft remote",
        status: Status::Builtin,
        note: "croft remote opens a workspace over SSH with the same UI",
    },
    Mapping {
        vscode: "ms-vscode-remote.remote-containers",
        croft: "croft devcontainer",
        status: Status::Builtin,
        note: "croft devcontainer builds the .devcontainer image and opens croft inside it",
    },
    Mapping {
        vscode: "ms-vscode-remote.remote-wsl",
        croft: "",
        status: Status::None,
        note: "no WSL integration; run croft inside WSL",
    },
    Mapping {
        vscode: "ms-vsliveshare.vsliveshare",
        croft: "croft attach",
        status: Status::Builtin,
        note: "croft attach (or croft <host> over SSH) shares one live session with each person's caret",
    },
    Mapping {
        vscode: "eamodio.gitlens",
        croft: "inline blame",
        status: Status::Builtin,
        note: "inline blame, the SCM view, and the Timeline ship built in",
    },
    Mapping {
        vscode: "donjayamanne.githistory",
        croft: "timeline",
        status: Status::Builtin,
        note: "the Timeline view shows a file's history",
    },
    Mapping {
        vscode: "mhutchie.git-graph",
        croft: "commit graph",
        status: Status::Builtin,
        note: "the Source Control view's COMMITS graph ships built in",
    },
    Mapping {
        vscode: "github.vscode-pull-request-github",
        croft: "croft pr",
        status: Status::Builtin,
        note: "croft pr <n> or Source Control: Review Pull Request reviews a pull request in the editor",
    },
    Mapping {
        vscode: "github.copilot",
        croft: "navigator",
        status: Status::Builtin,
        note: "the Navigator (Cmd+I) covers code assistance",
    },
    Mapping {
        vscode: "github.copilot-chat",
        croft: "navigator",
        status: Status::Builtin,
        note: "the Navigator (Cmd+I) is croft's chat",
    },
    Mapping {
        vscode: "continue.continue",
        croft: "navigator",
        status: Status::Builtin,
        note: "the Navigator (Cmd+I) covers it",
    },
    Mapping {
        vscode: "saoudrizwan.claude-dev",
        croft: "navigator",
        status: Status::Builtin,
        note: "run Claude Code in a terminal pane",
    },
    Mapping {
        vscode: "anthropic.claude-code",
        croft: "navigator",
        status: Status::Builtin,
        note: "run Claude Code in a terminal pane",
    },
    Mapping {
        vscode: "tabnine.tabnine-vscode",
        croft: "",
        status: Status::None,
        note: "no inline completion provider beyond the language servers",
    },
    Mapping {
        vscode: "vscodevim.vim",
        croft: "vim",
        status: Status::Builtin,
        note: "Vim keybindings ship as a built-in extension",
    },
    Mapping {
        vscode: "github.github-vscode-theme",
        croft: "themes",
        status: Status::Builtin,
        note: "GitHub Dark ships built in; other variants import with croft theme-import",
    },
    Mapping {
        vscode: "zhuangtongfa.material-theme",
        croft: "themes",
        status: Status::Builtin,
        note: "One Dark Pro ships built in; other variants import with croft theme-import",
    },
    Mapping {
        vscode: "dracula-theme.theme-dracula",
        croft: "themes",
        status: Status::Builtin,
        note: "Dracula ships built in",
    },
    Mapping {
        vscode: "enkia.tokyo-night",
        croft: "themes",
        status: Status::Builtin,
        note: "Tokyo Night ships built in",
    },
    Mapping {
        vscode: "pkief.material-icon-theme",
        croft: "file icons",
        status: Status::Builtin,
        note: "file icons ship built in (Nerd Font glyphs)",
    },
    Mapping {
        vscode: "vscode-icons-team.vscode-icons",
        croft: "file icons",
        status: Status::Builtin,
        note: "file icons ship built in (Nerd Font glyphs)",
    },
    Mapping {
        vscode: "formulahendry.code-runner",
        croft: "tasks",
        status: Status::Builtin,
        note: "run through tasks.json or the terminal; a Markdown code block runs with Cmd+Enter",
    },
    Mapping {
        vscode: "vscode.emmet",
        croft: "emmet",
        status: Status::Builtin,
        note: "Emmet abbreviations expand with Cmd+Opt+Shift+E in HTML, XML and JSX buffers",
    },
    Mapping {
        vscode: "formulahendry.auto-rename-tag",
        croft: "lsp-html",
        status: Status::Builtin,
        note: "paired tags rename together through the language server's linked editing",
    },
    Mapping {
        vscode: "formulahendry.auto-close-tag",
        croft: "tag auto-close",
        status: Status::Builtin,
        note: "typing `>` after an HTML/XML/JSX opening tag inserts the matching closing tag",
    },
    Mapping {
        vscode: "streetsidesoftware.code-spell-checker",
        croft: "",
        status: Status::None,
        note: "no spell checker",
    },
    Mapping {
        vscode: "usernamehw.errorlens",
        croft: "PROBLEMS",
        status: Status::Builtin,
        note: "diagnostics paint inline and in PROBLEMS",
    },
    Mapping {
        vscode: "aaron-bond.better-comments",
        croft: "comment tag highlighting",
        status: Status::Builtin,
        note: "TODO/FIXME/XXX/BUG/HACK/NOTE/WARNING recoloured in comments",
    },
    Mapping {
        vscode: "coenraads.bracket-pair-colorizer-2",
        croft: "bracket colours",
        status: Status::Builtin,
        note: "bracket pair colours ship built in (disable_bracket_colors)",
    },
    Mapping {
        vscode: "oderwat.indent-rainbow",
        croft: "indent guides",
        status: Status::Builtin,
        note: "indent guides ship built in (disable_indent_guides)",
    },
    Mapping {
        vscode: "naumovs.color-highlight",
        croft: "colour swatches",
        status: Status::Builtin,
        note: "colour literals are tinted in place, in any file",
    },
    Mapping {
        vscode: "ritwickdey.liveserver",
        croft: "",
        status: Status::None,
        note: "no live server",
    },
    Mapping {
        vscode: "ms-vscode.live-server",
        croft: "",
        status: Status::None,
        note: "no live server",
    },
    Mapping {
        vscode: "humao.rest-client",
        croft: "http files",
        status: Status::Builtin,
        note: ".http files: HTTP: Send Request Under Caret, or Copy Request as curl",
    },
    Mapping {
        vscode: "yzhang.markdown-all-in-one",
        croft: "markdown preview",
        status: Status::Builtin,
        note: "the Markdown preview (Cmd+Shift+V) ships built in",
    },
    Mapping {
        vscode: "davidanson.vscode-markdownlint",
        croft: "lsp-markdown",
        status: Status::Builtin,
        note: "rumdl ships built in: markdownlint's rules with quick fixes, reading .markdownlint.* configs",
    },
    Mapping {
        vscode: "rvben.rumdl",
        croft: "lsp-markdown",
        status: Status::Builtin,
        note: "rumdl ships built in",
    },
    Mapping {
        vscode: "arr.marksman",
        croft: "lsp-markdown",
        status: Status::Builtin,
        note: "marksman ships built in",
    },
    Mapping {
        vscode: "bierner.markdown-mermaid",
        croft: "",
        status: Status::None,
        note: "the Markdown preview does not render Mermaid",
    },
    Mapping {
        vscode: "gruntfuggly.todo-tree",
        croft: "",
        status: Status::None,
        note: "no TODO tree; search (Cmd+Shift+F) finds them",
    },
    Mapping {
        vscode: "wayou.vscode-todo-highlight",
        croft: "",
        status: Status::None,
        note: "no TODO highlighting",
    },
    Mapping {
        vscode: "mechatroner.rainbow-csv",
        croft: "csv",
        status: Status::Builtin,
        note: "the CSV viewer ships built in",
    },
    Mapping {
        vscode: "tomoki1207.pdf",
        croft: "pdf",
        status: Status::Builtin,
        note: "the PDF viewer ships built in",
    },
    Mapping {
        vscode: "hediet.vscode-drawio",
        croft: "",
        status: Status::None,
        note: "no diagram editor",
    },
    Mapping {
        vscode: "mikestead.dotenv",
        croft: "core-languages",
        status: Status::Builtin,
        note: ".env files highlight through the core languages",
    },
    Mapping {
        vscode: "editorconfig.editorconfig",
        croft: ".editorconfig support",
        status: Status::Builtin,
        note: "indent_style/indent_size/tab_width, end_of_line, trim_trailing_whitespace and insert_final_newline are applied per file",
    },
    Mapping {
        vscode: "sonarsource.sonarlint-vscode",
        croft: "",
        status: Status::None,
        note: "no SonarLint; diagnostics come from the language servers",
    },
    Mapping {
        vscode: "hbenl.vscode-test-explorer",
        croft: "test explorer",
        status: Status::Builtin,
        note: "the Test Explorer ships built in",
    },
];

/// The row for `id` (`publisher.name`, any case), if it has one.
pub fn lookup(id: &str) -> Option<&'static Mapping> {
    TABLE
        .iter()
        .find(|m| m.vscode.eq_ignore_ascii_case(id.trim()))
}

/// Extension ids a workspace recommends in `<root>/.vscode/extensions.json`
/// (JSONC: comments and trailing commas are allowed there), in file order.
/// A missing or unreadable file is no recommendations.
pub fn workspace_recommendations(root: &Path) -> Vec<String> {
    let path = root.join(".vscode").join("extensions.json");
    let Ok(raw) = std::fs::read_to_string(&path) else {
        return Vec::new();
    };
    let Ok(doc) = serde_json::from_str::<serde_json::Value>(&crate::tasks::strip_jsonc(&raw))
    else {
        return Vec::new();
    };
    doc["recommendations"]
        .as_array()
        .map(|list| {
            list.iter()
                .filter_map(|v| v.as_str())
                .map(str::to_string)
                .collect()
        })
        .unwrap_or_default()
}

/// How long `code --list-extensions` may take before it is given up on.
/// Usually instant; a stale lock or a slow network share can wedge it.
pub const LIST_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(3);

/// Extension ids VS Code reports installed, via `code --list-extensions`.
/// Best effort: no `code` on PATH, a failure, or no answer within
/// [`LIST_TIMEOUT`] is an empty list. Runs a process, so callers invoke it
/// on an explicit user action, not per frame; and it is bounded, because
/// that action runs on the render thread and an unbounded `.output()` on a
/// hung child would freeze croft with no way out (the `gui_path` probe has
/// the same shape and the same scar).
pub fn installed_via_code() -> Vec<String> {
    let mut cmd = std::process::Command::new("code");
    cmd.arg("--list-extensions");
    installed_via(cmd, LIST_TIMEOUT)
}

/// [`installed_via_code`] over an explicit command and bound, for tests.
pub fn installed_via(mut cmd: std::process::Command, timeout: std::time::Duration) -> Vec<String> {
    let Ok(mut child) = cmd
        .stdin(std::process::Stdio::null())
        .stdout(std::process::Stdio::piped())
        .stderr(std::process::Stdio::null())
        .spawn()
    else {
        return Vec::new();
    };
    let Some(mut stdout) = child.stdout.take() else {
        return Vec::new();
    };
    let (tx, rx) = std::sync::mpsc::channel();
    std::thread::spawn(move || {
        let mut buf = Vec::new();
        let _ = std::io::Read::read_to_end(&mut stdout, &mut buf);
        let _ = tx.send(buf);
    });
    let out = rx.recv_timeout(timeout).ok();
    // Answered or wedged, it must not outlive the call holding a pipe open.
    // The reap runs off-thread: a child in uninterruptible sleep cannot be
    // killed, and a synchronous wait() would wedge the frame after all.
    let _ = child.kill();
    std::thread::spawn(move || {
        let _ = child.wait();
    });
    let Some(out) = out else {
        return Vec::new();
    };
    String::from_utf8_lossy(&out)
        .lines()
        .map(str::trim)
        .filter(|l| l.contains('.'))
        .map(str::to_string)
        .collect()
}

/// One extension the user has or is recommended, with its croft row.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Comparison {
    pub id: String,
    pub mapping: Option<&'static Mapping>,
}

impl Comparison {
    /// The status to show: an unknown id reads as no equivalent.
    pub fn status(&self) -> Status {
        self.mapping.map_or(Status::None, |m| m.status)
    }
}

/// Look every id up, dropping duplicates (case-insensitively), ordered
/// built-in first, then installable, then the rest, each group by id.
pub fn compare<I: IntoIterator<Item = String>>(ids: I) -> Vec<Comparison> {
    let mut seen = std::collections::BTreeSet::new();
    let mut rows: Vec<Comparison> = ids
        .into_iter()
        .filter_map(|id| {
            let id = id.trim().to_lowercase();
            (!id.is_empty() && seen.insert(id.clone())).then(|| Comparison {
                mapping: lookup(&id),
                id,
            })
        })
        .collect();
    rows.sort_by(|a, b| a.status().cmp(&b.status()).then_with(|| a.id.cmp(&b.id)));
    rows
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn the_table_covers_the_popular_extensions_with_unique_lowercase_ids() {
        assert!(TABLE.len() >= 50, "{} rows", TABLE.len());
        let mut seen = std::collections::BTreeSet::new();
        for m in TABLE {
            assert_eq!(
                m.vscode,
                m.vscode.to_lowercase(),
                "{} is not lowercase",
                m.vscode
            );
            assert!(m.vscode.contains('.'), "{} is not publisher.name", m.vscode);
            assert!(seen.insert(m.vscode), "{} appears twice", m.vscode);
            assert!(!m.note.is_empty(), "{} has no note", m.vscode);
            match m.status {
                Status::None => assert!(
                    m.croft.is_empty(),
                    "{} maps to nothing but names {}",
                    m.vscode,
                    m.croft
                ),
                _ => assert!(
                    !m.croft.is_empty(),
                    "{} has a status but no croft target",
                    m.vscode
                ),
            }
        }
    }

    /// The acceptance triple from #352, and that a built-in target is a real
    /// bundled extension id or a feature, never a typo.
    #[test]
    fn the_acceptance_examples_resolve() {
        assert_eq!(
            lookup("rust-lang.rust-analyzer").map(|m| (m.status, m.croft)),
            Some((Status::Builtin, "lsp-rust"))
        );
        assert_eq!(
            lookup("ms-python.python").map(|m| (m.status, m.croft)),
            Some((Status::Builtin, "lsp-python"))
        );
        assert_eq!(
            lookup("esbenp.prettier-vscode").map(|m| m.status),
            Some(Status::Builtin)
        );
        assert_eq!(
            lookup("Rust-Lang.Rust-Analyzer").map(|m| m.vscode),
            Some("rust-lang.rust-analyzer"),
            "lookup is case-insensitive"
        );
        assert_eq!(lookup("nobody.nothing"), None);
        // Every built-in target that looks like an extension id is one croft
        // bundles, so the panel's "you have this" is true.
        let bundled: Vec<String> =
            crate::lsp::manifest::summaries(crate::lsp::manifest::BUNDLED_MANIFESTS)
                .into_iter()
                .map(|s| s.id)
                .collect();
        for m in TABLE.iter().filter(|m| m.status == Status::Builtin) {
            if m.croft.starts_with("lsp-")
                || m.croft.starts_with("dap-")
                || m.croft.starts_with("test-")
            {
                assert!(
                    bundled.contains(&m.croft.to_string()),
                    "{} names {} which croft does not bundle: {bundled:?}",
                    m.vscode,
                    m.croft
                );
            }
        }
        // And every installable target is a catalog entry.
        for m in TABLE.iter().filter(|m| m.status == Status::Installable) {
            assert!(
                crate::mcp::catalog::is_catalog_entry(m.croft),
                "{} names {} which the catalog does not have",
                m.vscode,
                m.croft
            );
        }
    }

    /// #1595: the features this build ships are built in, named by what
    /// covers them, and the gaps that remain stay gaps.
    #[test]
    fn rows_for_shipped_features_are_built_in() {
        for (id, croft) in [
            ("mhutchie.git-graph", "commit graph"),
            ("github.vscode-pull-request-github", "croft pr"),
            ("humao.rest-client", "http files"),
            ("ms-vscode-remote.remote-containers", "croft devcontainer"),
            ("naumovs.color-highlight", "colour swatches"),
            ("ms-vsliveshare.vsliveshare", "croft attach"),
        ] {
            let m = lookup(id).unwrap();
            assert_eq!((m.status, m.croft), (Status::Builtin, croft), "{id}");
        }
        for id in ["ms-python.python", "ms-python.vscode-pylance"] {
            let note = lookup(id).unwrap().note;
            assert!(
                note.contains("ty") && !note.contains("(pyright)"),
                "{id}: {note}"
            );
            // basedpyright is not provisioned, so no note may claim it ships.
            assert!(
                note.contains("optional fallback used when already installed")
                    && !note.contains("basedpyright and"),
                "{id}: {note}"
            );
        }
        // Negative: what croft still lacks is still reported as missing.
        for id in [
            "ritwickdey.liveserver",
            "ms-vscode.live-server",
            "tabnine.tabnine-vscode",
            "streetsidesoftware.code-spell-checker",
        ] {
            assert_eq!(lookup(id).map(|m| m.status), Some(Status::None), "{id}");
        }
    }

    /// #1595: a note shown to users never points at a tracker issue, which
    /// goes stale the day it closes.
    #[test]
    fn no_note_cites_an_issue_number() {
        for m in TABLE {
            let cites = m
                .note
                .split('#')
                .skip(1)
                .any(|rest| rest.starts_with(|c: char| c.is_ascii_digit()));
            assert!(!cites, "{}: {}", m.vscode, m.note);
        }
    }

    #[test]
    fn workspace_recommendations_read_jsonc_and_tolerate_absence() {
        let dir = tempfile::tempdir().unwrap();
        assert!(workspace_recommendations(dir.path()).is_empty());
        std::fs::create_dir(dir.path().join(".vscode")).unwrap();
        std::fs::write(
            dir.path().join(".vscode").join("extensions.json"),
            "{\n  // See https://go.microsoft.com/fwlink/?LinkId=827846\n  \"recommendations\": [\n    \"rust-lang.rust-analyzer\",\n    \"ms-python.python\",\n  ],\n  \"unwantedRecommendations\": [\"ms-vscode.cpptools\"],\n}\n",
        )
        .unwrap();
        assert_eq!(
            workspace_recommendations(dir.path()),
            vec![
                "rust-lang.rust-analyzer".to_string(),
                "ms-python.python".to_string()
            ]
        );
    }

    /// The listing is bounded: a child that never answers is given up on
    /// within the timeout, and a normal one is read in full.
    #[test]
    fn listing_installed_extensions_gives_up_on_a_hung_child() {
        let mut fast = std::process::Command::new("/bin/sh");
        fast.args(["-c", "printf 'a.b\\nnot-an-id\\nc.d\\n'"]);
        assert_eq!(
            installed_via(fast, std::time::Duration::from_secs(5)),
            vec!["a.b".to_string(), "c.d".to_string()]
        );
        let mut hung = std::process::Command::new("/bin/sh");
        hung.args(["-c", "sleep 30"]);
        let started = std::time::Instant::now();
        assert!(installed_via(hung, std::time::Duration::from_millis(300)).is_empty());
        assert!(
            started.elapsed() < std::time::Duration::from_secs(5),
            "waited {:?} on a hung child",
            started.elapsed()
        );
        let missing = std::process::Command::new("/definitely/not/here");
        assert!(installed_via(missing, std::time::Duration::from_secs(1)).is_empty());
    }

    #[test]
    fn compare_dedups_and_orders_builtin_then_installable_then_none() {
        let rows = compare(vec![
            "nobody.nothing".to_string(),
            "MS-Python.Python".to_string(),
            "rust-lang.rust-analyzer".to_string(),
            "ms-python.python".to_string(),
        ]);
        let ids: Vec<&str> = rows.iter().map(|r| r.id.as_str()).collect();
        assert_eq!(
            ids,
            [
                "ms-python.python",
                "rust-lang.rust-analyzer",
                "nobody.nothing"
            ]
        );
        assert_eq!(rows[0].status(), Status::Builtin);
        assert_eq!(rows[2].status(), Status::None);
        assert!(rows[2].mapping.is_none());
    }
}