Skip to content

Commit b0af101

Browse files
Improved documentation regarding internal scopes (#3086)
1 parent 3917870 commit b0af101

File tree

5 files changed

+110
-85
lines changed

5 files changed

+110
-85
lines changed

data/scopeSupportFacetInfos.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119

120120
### disqualifyDelimiter
121121

122-
- `disqualifyDelimiter` Used to disqualify a token from being treated as a surrounding pair delimiter. This will usually be operators containing `>` or `<`, eg `<`, `<=`, `->`, etc
122+
- `disqualifyDelimiter` Internally used to disqualify a token from being treated as a surrounding pair delimiter. This will usually be operators containing `>` or `<`, eg `<`, `<=`, `->`, etc.
123123

124124
### document
125125

@@ -259,7 +259,7 @@
259259

260260
### pairDelimiter
261261

262-
- `pairDelimiter` A pair delimiter, eg parentheses, brackets, braces, quotes, etc
262+
- `pairDelimiter` Internally used to add additional language specific surrounding pair delimiters in addition to the text based definitions. eg `r"`.
263263

264264
### paragraph
265265

@@ -336,11 +336,11 @@
336336

337337
### textFragment
338338

339-
- `textFragment.comment.block` Text fragment consisting of a block comment
340-
- `textFragment.comment.line` Text fragment consisting of a line comment
341-
- `textFragment.element` Text fragment consisting of a xml element interior
342-
- `textFragment.string.multiLine` Text fragment consisting of a multi-line string
343-
- `textFragment.string.singleLine` Text fragment consisting of a single-line string
339+
- `textFragment.comment.block` Internally used text fragment consisting of a block comment
340+
- `textFragment.comment.line` Internally used text fragment consisting of a line comment
341+
- `textFragment.element` Internally used text fragment consisting of a xml element interior
342+
- `textFragment.string.multiLine` Internally used text fragment consisting of a multi-line string
343+
- `textFragment.string.singleLine` Internally used text fragment consisting of a single-line string
344344

345345
### token
346346

packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -474,38 +474,6 @@ export const scopeSupportFacetInfos: Record<
474474
scopeType: "string",
475475
},
476476

477-
"textFragment.comment.line": {
478-
description: "Text fragment consisting of a line comment",
479-
scopeType: "textFragment",
480-
},
481-
"textFragment.comment.block": {
482-
description: "Text fragment consisting of a block comment",
483-
scopeType: "textFragment",
484-
},
485-
"textFragment.string.singleLine": {
486-
description: "Text fragment consisting of a single-line string",
487-
scopeType: "textFragment",
488-
},
489-
"textFragment.string.multiLine": {
490-
description: "Text fragment consisting of a multi-line string",
491-
scopeType: "textFragment",
492-
},
493-
"textFragment.element": {
494-
description: "Text fragment consisting of a xml element interior",
495-
scopeType: "textFragment",
496-
},
497-
498-
disqualifyDelimiter: {
499-
description:
500-
"Used to disqualify a token from being treated as a surrounding pair delimiter. This will usually be operators containing `>` or `<`, eg `<`, `<=`, `->`, etc",
501-
scopeType: "disqualifyDelimiter",
502-
},
503-
pairDelimiter: {
504-
description:
505-
"A pair delimiter, eg parentheses, brackets, braces, quotes, etc",
506-
scopeType: "pairDelimiter",
507-
},
508-
509477
"branch.if": {
510478
description: "An if branch",
511479
scopeType: "branch",
@@ -1044,6 +1012,43 @@ export const scopeSupportFacetInfos: Record<
10441012
description: "A unit in a css rule set",
10451013
scopeType: "unit",
10461014
},
1015+
1016+
// Internal scope facets
1017+
1018+
"textFragment.comment.line": {
1019+
description: "Internally used text fragment consisting of a line comment",
1020+
scopeType: "textFragment",
1021+
},
1022+
"textFragment.comment.block": {
1023+
description: "Internally used text fragment consisting of a block comment",
1024+
scopeType: "textFragment",
1025+
},
1026+
"textFragment.string.singleLine": {
1027+
description:
1028+
"Internally used text fragment consisting of a single-line string",
1029+
scopeType: "textFragment",
1030+
},
1031+
"textFragment.string.multiLine": {
1032+
description:
1033+
"Internally used text fragment consisting of a multi-line string",
1034+
scopeType: "textFragment",
1035+
},
1036+
"textFragment.element": {
1037+
description:
1038+
"Internally used text fragment consisting of a xml element interior",
1039+
scopeType: "textFragment",
1040+
},
1041+
1042+
disqualifyDelimiter: {
1043+
description:
1044+
"Internally used to disqualify a token from being treated as a surrounding pair delimiter. This will usually be operators containing `>` or `<`, eg `<`, `<=`, `->`, etc.",
1045+
scopeType: "disqualifyDelimiter",
1046+
},
1047+
pairDelimiter: {
1048+
description:
1049+
'Internally used to add additional language specific surrounding pair delimiters in addition to the text based definitions. eg `r"`.',
1050+
scopeType: "pairDelimiter",
1051+
},
10471052
};
10481053

10491054
function documentIter(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.anchor-with-sticky-navbar {
2+
scroll-margin-top: calc(var(--ifm-navbar-height) + 0.5rem);
3+
}

packages/cursorless-org-docs/src/docs/components/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { uriEncodeHashId } from "@cursorless/common";
22
import React from "react";
3+
import "./Header.css";
34

45
interface Props {
56
className?: string;
@@ -35,8 +36,7 @@ function renderHeader(
3536
id={encodedId}
3637
title={title}
3738
className={
38-
"scope-header anchorWithStickyNavbar_IncK" +
39-
(className ? " " + className : "")
39+
"anchor-with-sticky-navbar" + (className ? " " + className : "")
4040
}
4141
>
4242
{children}

packages/cursorless-org-docs/src/docs/components/ScopeVisualizer.tsx

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ export function ScopeVisualizer({ languageId, scopeTypeType }: Props) {
5252
scopeTypeType != null,
5353
);
5454

55+
const renderPublicScopesHeader = () => {
56+
return <H2>Scopes</H2>;
57+
};
58+
59+
const renderInternalScopesHeader = () => {
60+
return (
61+
<>
62+
<H2>Internal scopes</H2>
63+
64+
<p>
65+
The following are internal scopes. They are not intended for user
66+
interaction or spoken use. These scopes exist solely for internal
67+
Cursorless functionality.
68+
</p>
69+
</>
70+
);
71+
};
72+
5573
const renderOptions = () => {
5674
return (
5775
<div className="mb-4">
@@ -76,61 +94,60 @@ export function ScopeVisualizer({ languageId, scopeTypeType }: Props) {
7694
);
7795
};
7896

79-
const renderInternalScopes = () => {
80-
if (scopes.internal.length === 0) {
81-
return null;
82-
}
83-
return (
84-
<>
85-
<H2>Internal scopes</H2>
86-
87-
{languageId && (
88-
<p>
89-
The following are internal scopes. They are not intended for user
90-
interaction or spoken use. These scopes exist solely for internal
91-
Cursorless functionality.
92-
</p>
93-
)}
94-
95-
{scopes.internal.map((scope) =>
96-
renderScope(
97-
languageId,
98-
scopeTypeType,
99-
rangeType,
100-
renderWhitespace,
101-
scope,
102-
),
103-
)}
104-
</>
97+
const renderScopes = (scopes: Scope[]) => {
98+
return scopes.map((scope) =>
99+
renderScope(
100+
languageId,
101+
scopeTypeType,
102+
rangeType,
103+
renderWhitespace,
104+
scope,
105+
),
105106
);
106107
};
107108

108-
return (
109-
<>
110-
<H2>Scopes</H2>
111-
112-
{languageId && (
109+
// Specific language. Public scopes followed by (optional) internal scopes.
110+
if (languageId != null) {
111+
return (
112+
<>
113113
<p>
114114
Below are visualizations of all our scope tests for this language.
115115
These were created primarily for testing purposes rather than as
116116
documentation. There are quite a few, and they may feel a bit
117117
overwhelming from a documentation standpoint.
118118
</p>
119-
)}
120119

121-
{renderOptions()}
120+
{renderPublicScopesHeader()}
121+
{renderOptions()}
122+
{renderScopes(scopes.public)}
122123

123-
{scopes.public.map((scope) =>
124-
renderScope(
125-
languageId,
126-
scopeTypeType,
127-
rangeType,
128-
renderWhitespace,
129-
scope,
130-
),
131-
)}
124+
{scopes.internal.length > 0 && (
125+
<>
126+
{renderInternalScopesHeader()}
127+
{renderScopes(scopes.internal)}
128+
</>
129+
)}
130+
</>
131+
);
132+
}
132133

133-
{renderInternalScopes()}
134+
// Specific public scope
135+
if (scopes.public.length > 0) {
136+
return (
137+
<>
138+
{renderPublicScopesHeader()}
139+
{renderOptions()}
140+
{renderScopes(scopes.public)}
141+
</>
142+
);
143+
}
144+
145+
// Specific internal scope
146+
return (
147+
<>
148+
{renderInternalScopesHeader()}
149+
{renderOptions()}
150+
{renderScopes(scopes.internal)}
134151
</>
135152
);
136153
}
@@ -295,7 +312,7 @@ function getScopeFixtures(
295312
.forEach((scope) => {
296313
scope.facets.sort(facetComparator);
297314
scope.facets.forEach((f) => f.fixtures.sort(nameComparator));
298-
if (scopeTypeType == null && isScopeInternal(scope.scopeTypeType)) {
315+
if (isScopeInternal(scope.scopeTypeType)) {
299316
result.internal.push(scope);
300317
} else {
301318
result.public.push(scope);

0 commit comments

Comments
 (0)