Skip to content

Commit 1aef8bd

Browse files
committed
chore(showcase): take a Kotlin hover shot and Settings with Kotlin ready, for cstudy 0.31
The seed stage starts majority-element in Kotlin, and the Kotlin shot hovers groupingBy until its KDoc shows. Settings waits for the kotlin-lsp line. --accept-license passes a server's license to cstudy doctor --fix in the prepare stage, which accepts it in the throwaway workspace only, so its Gradle daemons run under the script's watch; prepare prints what doctor --fix printed.
1 parent 6dec3ff commit 1aef8bd

2 files changed

Lines changed: 51 additions & 7 deletions

File tree

‎tools/showcase/README.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ rm -rf /tmp/showcase-work /tmp/showcase-wheel
2626

2727
A run takes several minutes and runs one Chromium, `cstudy serve` and the language servers it starts, so close other heavy work first.
2828

29+
Kotlin's server, JetBrains' Kotlin LSP, comes under the JetBrains Free Plugin License Agreement, and `cstudy doctor --fix` downloads it only once that licence is accepted. Read it, then add `--accept-license kotlin-lsp` to the run: the prepare stage passes it to `cstudy doctor --fix`, which records the acceptance in the throwaway workspace only. Without it, the Kotlin hover and the settings shot wait for a server that never comes. The prepare stage prints what `cstudy doctor --fix` printed.
30+
2931
`--stages` runs part of it, in this order: `prepare` (virtual environment, `cstudy init --no-ide`, preferences, `cstudy doctor --fix`), `seed` (practice history), `videos`, `shots`, `mock`. A later stage needs the earlier ones, so rerun a single stage only against the same `--work` folder, and without `prepare`, which wants the folder empty. Run `videos` before `shots`, and `mock` last: a mock in progress adds a banner to every view.
3032

3133
`--shots` takes some of the screenshots of the `shots` stage, by name, such as `--shots web-ui-attempt,web-ui-settings`; a shot left out does not open its view, so leaving out `web-ui-health` starts no Gradle. `--variants` takes the screenshots in some themes and widths only, such as `--variants light-phone`: on a machine short of memory, one variant per run starts one Chromium and one Java language server at a time, and frees them in between. `--video-theme dark` records the animations in the dark theme.
3234

33-
When it ends, stop what it may have left: `ps -Ao pid,ppid,etime,command | rg -i "basedpyright|typescript-language-server|jdtls|gopls|rust-analyzer|uvicorn|cstudy serve|ms-playwright|GradleDaemon|KotlinCompileDaemon"`. The script stops the server and the browser, and the Gradle and Kotlin daemons that its own processes started (`cstudy doctor --fix`, the Health view and JDT LS start them): it looks at the processes below it every half second while it runs, notes the daemons it finds there, and stops those by PID at the end. A daemon that was running before, or that other work on this machine starts meanwhile, is never below the script, so it stays.
35+
When it ends, stop what it may have left: `ps -Ao pid,ppid,etime,command | rg -i "basedpyright|typescript-language-server|jdtls|kotlin-lsp|gopls|rust-analyzer|uvicorn|cstudy serve|ms-playwright|GradleDaemon|KotlinCompileDaemon"`. The script stops the server and the browser, and the Gradle and Kotlin daemons that its own processes started (`cstudy doctor --fix`, the Health view, JDT LS and the Kotlin LSP start them): it looks at the processes below it every half second while it runs, notes the daemons it finds there, and stops those by PID at the end. A daemon that was running before, or that other work on this machine starts meanwhile, is never below the script, so it stays.
3436

3537
## What it makes
3638

@@ -42,6 +44,7 @@ Desktop images are 1440 by 900, the phone ones 390 wide at 2x. A name is `<name>
4244
| `code-intelligence-error` | An undefined name underlined, with its message |
4345
| `autocomplete-list` | The completion list with its documentation panel |
4446
| `code-intelligence-java-hover` | The Javadoc tooltip on `getOrDefault` in top-k-frequent-elements (Java), from Eclipse JDT LS; the seed stage starts that attempt |
47+
| `code-intelligence-kotlin-hover` | The KDoc of `groupingBy` in majority-element (Kotlin), from JetBrains' Kotlin LSP and the standard library's sources in Gradle's cache; the seed stage starts that attempt |
4548
| `code-intelligence-go-hover` | The documentation of `strings.Split` in group-anagrams (Go), from gopls, with its links to `SplitN` and `Cut`; the seed stage starts that attempt |
4649
| `code-intelligence-rust-hover` | The documentation of `Vec` in product-except-self (Rust), from rust-analyzer and the toolchain's standard library; the seed stage starts that attempt |
4750
| `web-ui-problems` | The problem list |
@@ -70,5 +73,6 @@ Recording uses Playwright's `record_video_dir` with a small injected pointer, si
7073
- The script writes files only into `--work` and `--out`. Nothing it makes is committed for you.
7174
- It needs the language servers, so it runs `cstudy doctor --fix` with the network. After that it works offline.
7275
- A new language server needs a new feature shot, as Java's has, and a scene in `code_intelligence_scene` if the animation should show it. The health shot picks up new rows by itself; the settings shot also waits for each server's line, so a JDK outside 25 and 26 stops it instead of showing Java's `needs JDK 25 or 26`.
73-
- JDT LS says ready before its first Gradle import ends, so the Java shot hovers again until the Javadoc shows, for up to three minutes. The Go and Rust shots hover the same way. Each of the three waits for its server to stop before the next shot, so that two never run at once.
76+
- JDT LS says ready before its first Gradle import ends, so the Java shot hovers again until the Javadoc shows, for up to three minutes. The Kotlin LSP also imports the Gradle build first, so the Kotlin shot waits up to three minutes for ready and hovers again for up to five. The Go and Rust shots hover the same way. Each of the four waits for its server to stop before the next shot, so that two never run at once.
77+
- The Kotlin LSP imports Gradle with the selected JDK, 21 to 26, so the JDK 25 or 26 that Java needs serves both. JetBrains' builds stop about a month after release: the settings shot shows the build's last day, and an expired build needs a new `prepare`.
7478
- The Go and Rust shots need gopls, which `cstudy doctor --fix` builds with the selected Go, and rust-analyzer on `PATH` (`rustup component add rust-analyzer`), which the script never installs. The settings shot waits for both lines.

‎tools/showcase/showcase.py‎

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"code-intelligence-error",
4444
"autocomplete-list",
4545
"code-intelligence-java-hover",
46+
"code-intelligence-kotlin-hover",
4647
"code-intelligence-go-hover",
4748
"code-intelligence-rust-hover",
4849
"web-ui-problems",
@@ -106,6 +107,15 @@
106107
}
107108
"""
108109
JAVA_SLUG = "top-k-frequent-elements"
110+
MAJORITY_KOTLIN = """class Solution {
111+
fun majorityElement(nums: IntArray): Int {
112+
val counts = nums.asList().groupingBy { it }.eachCount()
113+
val half = nums.size / 2
114+
return counts.entries.first { (_, count) -> count > half }.key
115+
}
116+
}
117+
"""
118+
KOTLIN_SLUG = "majority-element"
109119
GROUP_ANAGRAMS_GO = """import (
110120
"slices"
111121
"strings"
@@ -356,7 +366,10 @@ def write_preferences(self, **changes: object) -> None:
356366
folder.mkdir(parents=True, exist_ok=True)
357367
(folder / "preferences.json").write_text(json.dumps({**PREFERENCES, **changes}) + "\n")
358368

359-
def prepare(self, wheel: Path) -> None:
369+
def prepare(self, wheel: Path, licenses: tuple[str, ...] = ()) -> None:
370+
"""`licenses` are the keys of the server licenses that you have read and accept for this
371+
throwaway workspace, such as `kotlin-lsp`; `cstudy doctor --fix` skips such a server
372+
without them."""
360373
say("prepare: virtual environment, workspace, language servers")
361374
if self.work.exists() and any(self.work.iterdir()):
362375
sys.exit(f"{self.work} is not empty; give --work an empty or new folder")
@@ -366,7 +379,8 @@ def prepare(self, wheel: Path) -> None:
366379
self.workspace.mkdir()
367380
self.cs("init", "--no-ide")
368381
self.write_preferences()
369-
self.cs("doctor", "--fix")
382+
accepted = [part for key in licenses for part in ("--accept-license", key)]
383+
say(self.cs("doctor", "--fix", *accepted).stdout.rstrip())
370384
self.cs("--version")
371385

372386
def seed(self) -> None:
@@ -395,6 +409,8 @@ def seed(self) -> None:
395409
self.cs("start", "move-zeroes", "--lang", "python", "--no-open")
396410
self.cs("start", JAVA_SLUG, "--lang", "java", "--no-open")
397411
self.write_java_stub(JAVA_SLUG, TOP_K_JAVA)
412+
self.cs("start", KOTLIN_SLUG, "--lang", "kotlin", "--no-open")
413+
self.write_code_after(self.kotlin_stub(KOTLIN_SLUG), "\nclass ", MAJORITY_KOTLIN)
398414
self.cs("start", GO_SLUG, "--lang", "go", "--no-open")
399415
self.write_code_after(self.go_stub(GO_SLUG), "\nfunc ", GROUP_ANAGRAMS_GO)
400416
self.cs("start", RUST_SLUG, "--lang", "rust", "--no-open")
@@ -427,6 +443,10 @@ def write_java_stub(self, slug: str, code: str) -> None:
427443
text = self.java_stub(slug).read_text()
428444
self.java_stub(slug).write_text(text[: text.index("\npublic class ") + 1] + code)
429445

446+
def kotlin_stub(self, slug: str) -> Path:
447+
practice = self.workspace / "jvm" / "kotlin" / "src" / "main" / "kotlin" / "practice"
448+
return practice / slug.replace("-", "_") / "Solution.kt"
449+
430450
def go_stub(self, slug: str) -> Path:
431451
name = slug.replace("-", "_")
432452
return self.workspace / "go" / "practice" / name / f"{name}.go"
@@ -689,8 +709,10 @@ def open_file(page: Page, name: str) -> None:
689709
page.wait_for_selector(".cm-content")
690710

691711

692-
def wait_ready(page: Page, server: str = "basedpyright") -> None:
693-
page.wait_for_function(f"document.body.innerText.includes('{server} · ready')")
712+
def wait_ready(page: Page, server: str = "basedpyright", timeout_ms: float = WAIT_MS) -> None:
713+
page.wait_for_function(
714+
f"document.body.innerText.includes('{server} · ready')", timeout=timeout_ms
715+
)
694716

695717

696718
def hover_until(page: Page, pointer: Pointer, line_text: str, token: str, text: str,
@@ -790,6 +812,18 @@ def feature_shots(app: Showcase, context: BrowserContext, variant: Variant) -> N
790812
page.close()
791813
app.wait_for_server_to_stop("jdtls")
792814

815+
if app.wants("code-intelligence-kotlin-hover"):
816+
page = app.attempt(context, KOTLIN_SLUG)
817+
open_file(page, "Solution.kt")
818+
wait_ready(page, "kotlin-lsp", timeout_ms=180_000)
819+
pointer = Pointer(page)
820+
hover_until(page, pointer, "groupingBy { it }", "groupingBy", "group-and-fold",
821+
limit_s=300)
822+
page.wait_for_timeout(400)
823+
app.screenshot(page, "code-intelligence-kotlin-hover", variant)
824+
page.close()
825+
app.wait_for_server_to_stop("kotlin-lsp")
826+
793827
if app.wants("code-intelligence-go-hover"):
794828
page = app.attempt(context, GO_SLUG)
795829
open_file(page, "group_anagrams.go")
@@ -877,6 +911,7 @@ def app_shots(app: Showcase, context: BrowserContext, variant: Variant) -> None:
877911
page.wait_for_selector("text=basedpyright 1.")
878912
page.wait_for_selector("text=typescript-language-server")
879913
page.wait_for_selector("text=jdtls 1.")
914+
page.wait_for_selector("text=/kotlin-lsp \\d/")
880915
page.wait_for_selector("text=gopls 0.")
881916
page.wait_for_selector("text=rust-analyzer 1.")
882917
page.wait_for_timeout(300)
@@ -1069,6 +1104,11 @@ def main() -> None:
10691104
"--variants", default=",".join(v.suffix for v in VARIANTS),
10701105
help="comma list of the screenshots' theme and width: light, dark, light-phone, dark-phone",
10711106
)
1107+
parser.add_argument(
1108+
"--accept-license", action="append", default=[], metavar="KEY",
1109+
help="with prepare: accept this server's license in the throwaway workspace, such as "
1110+
"kotlin-lsp, once you have read it; repeat for more",
1111+
)
10721112
args = parser.parse_args()
10731113
stages = [stage for stage in args.stages.split(",") if stage]
10741114
unknown = set(stages) - set(STAGES)
@@ -1089,7 +1129,7 @@ def main() -> None:
10891129
if "prepare" in stages:
10901130
if not args.wheel:
10911131
sys.exit("--wheel is needed to prepare")
1092-
app.prepare(args.wheel.resolve())
1132+
app.prepare(args.wheel.resolve(), tuple(args.accept_license))
10931133
if "seed" in stages:
10941134
app.seed()
10951135
if {"videos", "shots", "mock"} & set(stages):

0 commit comments

Comments
 (0)