Skip to content

Commit 5f8e369

Browse files
Refactoring
1 parent 2c4d721 commit 5f8e369

37 files changed

+209
-119
lines changed

packages/common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export * from "./types/TreeSitter";
9393
export * from "./types/tutorial.types";
9494
export * from "./util";
9595
export * from "./util/camelCaseToAllDown";
96+
export * from "./util/capitalize";
9697
export * from "./util/clientSupportsFallback";
9798
export * from "./util/CompositeKeyDefaultMap";
9899
export * from "./util/CompositeKeyMap";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function capitalize(str: string) {
2+
return str.charAt(0).toUpperCase() + str.slice(1);
3+
}

packages/cursorless-org-docs/src/docs/user/languages/ScopeSupport.tsx

Lines changed: 0 additions & 82 deletions
This file was deleted.

packages/cursorless-org-docs/src/docs/user/languages/c.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Language from "./Language";
1+
import { Language } from "./components/Language";
22

33
# C
44

packages/cursorless-org-docs/src/docs/user/languages/clojure.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Language from "./Language";
1+
import { Language } from "./components/Language";
22

33
# Clojure
44

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
2-
import ScopeSupport from "./ScopeSupport";
2+
import { ScopeSupport } from "./ScopeSupport";
33

44
interface Props {
55
languageId: string;
66
}
77

8-
export default function Language({ languageId }: Props) {
8+
export function Language({ languageId }: Props) {
99
return <ScopeSupport languageId={languageId} />;
1010
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import {
2+
ScopeSupportFacetLevel,
3+
languageScopeSupport,
4+
scopeSupportFacets,
5+
} from "@cursorless/common";
6+
import React from "react";
7+
import { ScopeSupportForLevel } from "./ScopeSupportForLevel";
8+
9+
interface Props {
10+
languageId: string;
11+
}
12+
13+
export function ScopeSupport({ languageId }: Props): JSX.Element {
14+
const scopesSorted = [...scopeSupportFacets].sort();
15+
const scopeSupport = languageScopeSupport[languageId] ?? {};
16+
17+
const supportedScopes = scopesSorted.filter(
18+
(facet) => scopeSupport[facet] === ScopeSupportFacetLevel.supported,
19+
);
20+
const supportedLegacyScopes = scopesSorted.filter(
21+
(facet) => scopeSupport[facet] === ScopeSupportFacetLevel.supportedLegacy,
22+
);
23+
const unsupportedScopes = scopesSorted.filter(
24+
(facet) => scopeSupport[facet] === ScopeSupportFacetLevel.unsupported,
25+
);
26+
const unspecifiedScopes = scopesSorted.filter(
27+
(facet) => scopeSupport[facet] == null,
28+
);
29+
30+
return (
31+
<>
32+
<ScopeSupportForLevel
33+
facets={supportedScopes}
34+
title={"Supported facets"}
35+
description={"These facets are supported"}
36+
/>
37+
38+
<ScopeSupportForLevel
39+
facets={supportedLegacyScopes}
40+
title={"Supported Legacy facets"}
41+
description={
42+
"These facets are supported with the legacy implementation and should be migrated to the new implementation"
43+
}
44+
/>
45+
46+
<ScopeSupportForLevel
47+
facets={unsupportedScopes}
48+
title={"Unsupported facets"}
49+
description={
50+
<>
51+
These facets are not supported yet and needs a developer to
52+
implement them. <br />
53+
We would happily accept
54+
[contributions](https://www.cursorless.org/docs/contributing/adding-a-new-scope).
55+
</>
56+
}
57+
/>
58+
59+
<ScopeSupportForLevel
60+
facets={unspecifiedScopes}
61+
title={"Unspecified facets"}
62+
description={
63+
<>
64+
These facets are unspecified <br />
65+
<i>
66+
Note that in many instances we actually do support these scopes,
67+
but we have not yet updated `languageScopeSupport` to reflect this
68+
fact. We would happily accept
69+
[contributions](https://www.cursorless.org/docs/contributing/adding-a-new-scope).
70+
</i>
71+
</>
72+
}
73+
/>
74+
</>
75+
);
76+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import {
2+
camelCaseToAllDown,
3+
capitalize,
4+
groupBy,
5+
type ScopeSupportFacet,
6+
type ScopeSupportFacetInfo,
7+
scopeSupportFacetInfos,
8+
type ScopeType,
9+
type SimpleScopeTypeType,
10+
} from "@cursorless/common";
11+
import React from "react";
12+
13+
interface Props {
14+
facets: ScopeSupportFacet[];
15+
title: string;
16+
description: React.ReactNode;
17+
}
18+
19+
export function ScopeSupportForLevel({
20+
facets,
21+
title,
22+
description,
23+
}: Props): JSX.Element | null {
24+
if (facets.length === 0) {
25+
return null;
26+
}
27+
const facetInfos = facets.map(
28+
(facet): AugmentedFacetInfo => ({
29+
facet,
30+
...scopeSupportFacetInfos[facet],
31+
}),
32+
);
33+
const scopeGroups: Map<string, AugmentedFacetInfo[]> = groupBy(
34+
facetInfos,
35+
(facetInfo) => serializeScopeType(facetInfo.scopeType),
36+
);
37+
const scopeTypes = Array.from(scopeGroups.keys()).sort();
38+
return (
39+
<div>
40+
<h3>{title}</h3>
41+
<p>{description}</p>
42+
43+
{scopeTypes.map((scopeType) => {
44+
const facetInfos = scopeGroups.get(scopeType) ?? [];
45+
return (
46+
<div key={scopeType}>
47+
<h4>{prettifyScopeType(scopeType)}</h4>
48+
<ul>
49+
{facetInfos.map((facetInfo) => {
50+
return (
51+
<li key={facetInfo.facet}>
52+
<b title={facetInfo.facet}>
53+
{prettifyFacet(facetInfo.facet)}
54+
</b>
55+
: {facetInfo.description}
56+
</li>
57+
);
58+
})}
59+
</ul>
60+
</div>
61+
);
62+
})}
63+
</div>
64+
);
65+
}
66+
67+
interface AugmentedFacetInfo extends ScopeSupportFacetInfo {
68+
facet: ScopeSupportFacet;
69+
}
70+
71+
function prettifyScopeType(scopeType: string): string {
72+
return capitalize(camelCaseToAllDown(scopeType));
73+
}
74+
75+
function prettifyFacet(facet: ScopeSupportFacet): string {
76+
const parts = facet.split(".").map(camelCaseToAllDown);
77+
if (parts.length === 1) {
78+
return capitalize(parts[0]);
79+
}
80+
const isIteration = parts[parts.length - 1] === "iteration";
81+
if (isIteration) {
82+
parts.pop();
83+
}
84+
const name = capitalize(parts.slice(1).join(" "));
85+
return isIteration ? `${name} (iteration)` : name;
86+
}
87+
88+
function serializeScopeType(
89+
scopeType: SimpleScopeTypeType | ScopeType,
90+
): string {
91+
if (typeof scopeType === "string") {
92+
return scopeType;
93+
}
94+
return scopeType.type;
95+
}

packages/cursorless-org-docs/src/docs/user/languages/cpp.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Language from "./Language";
1+
import { Language } from "./components/Language";
22

33
# C++
44

packages/cursorless-org-docs/src/docs/user/languages/csharp.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Language from "./Language";
1+
import { Language } from "./components/Language";
22

33
# C#
44

0 commit comments

Comments
 (0)