Skip to content

Commit ebbbe07

Browse files
Added checkbox to decide if missing private scopes should be visible in the docs (#2998)
1 parent 2c3d9fd commit ebbbe07

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

packages/cursorless-org-docs/src/docs/contributing/MissingLanguageScopes.tsx

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,34 @@ import {
99
} from "@cursorless/common";
1010
import React, { useEffect, useState } from "react";
1111

12-
export function MissingLanguageScopes(): React.JSX.Element[] {
13-
return Object.keys(languageScopeSupport)
14-
.sort()
15-
.map((languageId) => <Language key={languageId} languageId={languageId} />);
12+
export function MissingLanguageScopes(): React.JSX.Element {
13+
const [showPrivate, setShowPrivate] = useState(false);
14+
const languageIds = Object.keys(languageScopeSupport).sort();
15+
16+
return (
17+
<>
18+
<label className="ml-1">
19+
<input
20+
type="checkbox"
21+
checked={showPrivate}
22+
onChange={(e) => setShowPrivate(e.target.checked)}
23+
/>
24+
Show private scopes
25+
</label>
26+
27+
{languageIds.map((languageId) => (
28+
<Language languageId={languageId} showPrivate={showPrivate} />
29+
))}
30+
</>
31+
);
1632
}
1733

1834
function Language({
1935
languageId,
36+
showPrivate,
2037
}: {
2138
languageId: string;
39+
showPrivate: boolean;
2240
}): React.JSX.Element | null {
2341
const scopeSupport = languageScopeSupport[languageId] ?? {};
2442

@@ -28,8 +46,10 @@ function Language({
2846
const unspecifiedFacets = scopeSupportFacets.filter(
2947
(facet) => scopeSupport[facet] == null,
3048
);
49+
const unsupportedScopes = facetsToScopes(unsupportedFacets, showPrivate);
50+
const unspecifiedScopes = facetsToScopes(unspecifiedFacets, showPrivate);
3151

32-
if (unsupportedFacets.length === 0 && unspecifiedFacets.length === 0) {
52+
if (unsupportedScopes.length === 0 && unspecifiedScopes.length === 0) {
3353
return null;
3454
}
3555

@@ -42,30 +62,22 @@ function Language({
4262
<a href={`../../user/languages/${languageId}`}>link</a>
4363
</small>
4464
</h3>
45-
{renderFacets("Unsupported", unsupportedFacets)}
46-
{renderFacets("Unspecified", unspecifiedFacets)}
65+
66+
{renderFacets("Unsupported", unsupportedScopes)}
67+
{renderFacets("Unspecified", unspecifiedScopes)}
4768
</>
4869
);
4970
}
5071

5172
function renderFacets(
5273
title: string,
53-
facets: ScopeSupportFacet[],
74+
scopes: string[],
5475
): React.JSX.Element | null {
5576
const [open, setOpen] = useState(false);
56-
const [scopes, setScopes] = useState<string[]>([]);
5777

5878
useEffect(() => {
59-
const scopes = Array.from(
60-
new Set(
61-
facets.map((f) =>
62-
serializeScopeType(scopeSupportFacetInfos[f].scopeType),
63-
),
64-
),
65-
).sort();
66-
setScopes(scopes);
6779
setOpen(scopes.length < 4);
68-
}, []);
80+
}, [scopes]);
6981

7082
if (scopes.length === 0) {
7183
return null;
@@ -98,6 +110,18 @@ function renderFacets(
98110
);
99111
}
100112

113+
function facetsToScopes(facets: ScopeSupportFacet[], showPrivate: boolean) {
114+
return Array.from(
115+
new Set(
116+
facets.map((f) =>
117+
serializeScopeType(scopeSupportFacetInfos[f].scopeType),
118+
),
119+
),
120+
)
121+
.filter((scope) => showPrivate || !scope.startsWith("private."))
122+
.sort();
123+
}
124+
101125
function serializeScopeType(
102126
scopeType: SimpleScopeTypeType | ScopeType,
103127
): string {

0 commit comments

Comments
 (0)