Skip to content

Commit ee77cd5

Browse files
committed
add reserved keywords and objects
1 parent 323f8c5 commit ee77cd5

File tree

5 files changed

+122
-11
lines changed

5 files changed

+122
-11
lines changed

client/modules/IDE/components/show-hint.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,19 @@
275275
}
276276
}
277277

278-
function displayHint(name, type) {
278+
function displayHint(name, type, p5) {
279279
return `<p class="${type}-item">\
280280
<span class="${type}-name hint-name">${name}</span>\
281281
<span class="hint-hidden">, </span>\
282282
<span class="hint-type">${type}</span>\
283283
<span class="hint-hidden">, </span>\
284-
<a href="https://p5js.org/reference/#/p5/${name}" role="link" onclick="event.stopPropagation()" target="_blank">\
284+
${
285+
p5
286+
? `<a href="https://p5js.org/reference/#/p5/${name}" role="link" onclick="event.stopPropagation()" target="_blank">\
285287
<span class="hint-hidden">open ${name} reference</span>\
286-
<span aria-hidden="true">&#10132;</span></a></p>`;
288+
<span aria-hidden="true">&#10132;</span></a>`
289+
: `<span class="no-link-placeholder"><span class="hint-hidden">no reference for ${name}</span></span>`
290+
}</p>`;
287291
}
288292

289293
function getInlineHintSuggestion(focus, tokenLength) {
@@ -377,7 +381,7 @@
377381
const name = getText(cur);
378382

379383
if (cur.item && cur.item.type) {
380-
cur.displayText = displayHint(name, cur.item.type);
384+
cur.displayText = displayHint(name, cur.item.type, cur.item.p5);
381385
}
382386

383387
elt.appendChild(e);

client/styles/abstracts/_variables.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ $themes: (
123123
hint-item-border-bottom-color: $white,
124124
hint-fun-text-color: #0B7CA9,
125125
hint-var-text-color: #D52889,
126+
hint-keyword-text-color: #7A5A3A,
126127
hint-type-text-color: $medium-dark,
127128
hint-arrow-color: $lightest,
128129
hint-arrow-background-color: #ed225ddd,
129130
hint-arrow-background-active-color: $p5js-active-pink,
130131
hint-arrow-focus-outline-color: $middle-dark,
132+
hint-no-link-background-color: $medium-light,
131133
hint-item-hover-background-color: #f4f4f4,
132134
hint-item-active-text-color: $white,
133135
hint-item-active-background-color: $middle-gray,
@@ -224,11 +226,13 @@ $themes: (
224226
hint-item-border-bottom-color: $darker,
225227
hint-fun-text-color: #0F9DD7,
226228
hint-var-text-color: #DE4A9B,
229+
hint-keyword-text-color: #B58318,
227230
hint-type-text-color: $light,
228231
hint-arrow-color: $lightest,
229232
hint-arrow-background-color: #ed225ddd,
230233
hint-arrow-background-active-color: $p5js-active-pink,
231234
hint-arrow-focus-outline-color: #cfcfcf,
235+
hint-no-link-background-color: $medium-dark,
232236
hint-item-hover-background-color: $medium-dark,
233237
hint-item-active-text-color: $darker,
234238
hint-item-active-background-color: #cfcfcf,
@@ -325,11 +329,13 @@ $themes: (
325329
hint-item-border-bottom-color: $medium-dark,
326330
hint-fun-text-color: #00FFFF,
327331
hint-var-text-color: #FFA9D9,
332+
hint-keyword-text-color: #F5DC23,
328333
hint-type-text-color: $middle-light,
329334
hint-arrow-color: $darker,
330335
hint-arrow-background-color: #F5DC23DD,
331336
hint-arrow-background-active-color: #F5DC23,
332337
hint-arrow-focus-outline-color: $lighter,
338+
hint-no-link-background-color: $medium-dark,
333339
hint-item-hover-background-color: $dark,
334340
hint-item-active-text-color: $lighter,
335341
hint-item-active-background-color: unset,

client/styles/components/_hints.scss

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@
3131
height: 100%;
3232
}
3333

34-
.fun-name {
34+
.fun-name, .obj-name {
3535
color: getThemifyVariable('hint-fun-text-color');
3636
}
3737

3838
.var-name {
3939
color: getThemifyVariable('hint-var-text-color');
4040
}
41+
42+
.keyword-name {
43+
color: getThemifyVariable('hint-keyword-text-color');
44+
}
4145

4246
.hint-type {
4347
color: getThemifyVariable('hint-type-text-color');
@@ -57,6 +61,11 @@
5761
outline-offset: #{-3 / $base-font-size}rem;
5862
}
5963
}
64+
65+
.no-link-placeholder {
66+
background: getThemifyVariable('hint-no-link-background-color');
67+
pointer-events: none;
68+
}
6069

6170
li.CodeMirror-hint-active:not(.unfocused) {
6271
background: getThemifyVariable('hint-item-active-background-color');
@@ -75,13 +84,17 @@
7584
color: getThemifyVariable('hint-item-active-text-color');
7685
}
7786

78-
.fun-name {
87+
.fun-name, .obj-name {
7988
background-color: getThemifyVariable('hint-fun-text-color');
8089
}
8190

8291
.var-name {
8392
background-color: getThemifyVariable('hint-var-text-color');
8493
}
94+
95+
.keyword-name {
96+
background-color: getThemifyVariable('hint-keyword-text-color');
97+
}
8598

8699
.hint-type, .plain-hint-item {
87100
color: getThemifyVariable('hint-item-active-type-text-color');
@@ -140,7 +153,7 @@
140153
@extend %hidden-element;
141154
}
142155

143-
a {
156+
a, .no-link-placeholder {
144157
position: absolute;
145158
top: 0;
146159
right: 0;
@@ -168,8 +181,8 @@
168181
@include themify() {
169182
.autocomplete-inline-hinter {
170183
// make the border left look like a cursor and animate like a cursor
171-
border-left: #{1.2 / $base-font-size}rem solid getThemifyVariable(hint-inline-text-color);
172-
animation: inline-hint-caret-blink 1s step-end infinite;
184+
// border-left: #{1.2 / $base-font-size}rem solid getThemifyVariable(hint-inline-text-color);
185+
// animation: inline-hint-caret-blink 1s step-end infinite;
173186
pointer-events: none;
174187

175188
.inline-hinter-suggestion {

client/utils/p5-hinter.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/scripts/update-p5-hinter.js

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,77 @@ const axios = require('axios');
66
// return d.split('\n')[0].replace('<p>', '');
77
// };
88

9+
const reservedKeywords = [
10+
'await',
11+
'break',
12+
'case',
13+
'catch',
14+
'class',
15+
'const',
16+
'continue',
17+
'debugger',
18+
'default',
19+
'delete',
20+
'do',
21+
'else',
22+
'export',
23+
'extends',
24+
'finally',
25+
'for',
26+
'function',
27+
'if',
28+
'import',
29+
'in',
30+
'instanceof',
31+
'new',
32+
'return',
33+
'super',
34+
'switch',
35+
'this',
36+
'throw',
37+
'try',
38+
'typeof',
39+
'var',
40+
'void',
41+
'while',
42+
'with',
43+
'yield',
44+
'let'
45+
];
46+
47+
const reservedObjects = [
48+
'Array',
49+
'Boolean',
50+
'Date',
51+
'Error',
52+
'Function',
53+
'JSON',
54+
'Math',
55+
'Number',
56+
'Object',
57+
'RegExp',
58+
'String',
59+
'Promise',
60+
'Set',
61+
'Map',
62+
'Symbol',
63+
'WeakMap',
64+
'WeakSet',
65+
'ArrayBuffer',
66+
'DataView',
67+
'Int32Array',
68+
'Uint32Array',
69+
'Float32Array',
70+
'window',
71+
'document',
72+
'navigator',
73+
'console',
74+
'localStorage',
75+
'sessionStorage',
76+
'history',
77+
'location'
78+
];
79+
980
axios
1081
.get('https://p5js.org/reference/data.json')
1182
.then((response) => {
@@ -37,11 +108,28 @@ axios
37108
p5Keywords.push({
38109
text: obj.name,
39110
type,
40-
params
111+
params,
112+
p5: true
41113
});
42114
}
43115
});
44116

117+
reservedKeywords.forEach((keyword) => {
118+
p5Keywords.push({
119+
text: keyword,
120+
type: 'keyword',
121+
p5: false
122+
});
123+
});
124+
125+
reservedObjects.forEach((keyword) => {
126+
p5Keywords.push({
127+
text: keyword,
128+
type: 'obj',
129+
p5: false
130+
});
131+
});
132+
45133
const keywords = JSON.stringify(p5Keywords);
46134

47135
let generatedCode = '/* eslint-disable */\n';

0 commit comments

Comments
 (0)