Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PiE API autocomplete and tooltips #35

Merged
merged 32 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f1f6f0a
Add context-sensitive autocomplete
Hal-9k1 Oct 30, 2024
e6e7353
Try to improve autocomplete
Hal-9k1 Oct 30, 2024
3ede7d5
Reduce boilerplate in completions
snowNnik Nov 7, 2024
a857e66
Try to fix context position stuff
snowNnik Nov 7, 2024
1613680
Fix position-sensitive context completion
snowNnik Nov 7, 2024
f0cb420
Lint
snowNnik Nov 7, 2024
ffa80d9
Fix acequire import weirdness
snowNnik Nov 7, 2024
0c6e700
Fix typescript errors
snowNnik Nov 7, 2024
14d25e3
Document addEditorAutocomplete
Hal-9k1 Nov 7, 2024
6b1490b
Start adding tooltips
Hal-9k1 Nov 7, 2024
a884905
Uninstall redux
Hal-9k1 Nov 14, 2024
6ffd3cd
Add demo tooltip on everything
Hal-9k1 Nov 14, 2024
4219979
Improve context autocomplete
Hal-9k1 Nov 21, 2024
5560462
Fail to fix some bad completions
Hal-9k1 Nov 21, 2024
aa70a51
Somehow fix autocomplete
Hal-9k1 Nov 27, 2024
b8541a4
Fix typescript error in tooltips
Hal-9k1 Nov 27, 2024
7a4b5b4
Remove beforeCaret now that buf is only before caret
Hal-9k1 Nov 28, 2024
aaa1dfb
Extract text grabbing part of getCompletions to readApiCall.ts
Hal-9k1 Nov 28, 2024
896886c
Get tooltips working
Hal-9k1 Nov 28, 2024
9318e32
Fix empty returns in readApiCall
Hal-9k1 Nov 28, 2024
792aa2e
Fix problems with ace and jest
Hal-9k1 Nov 28, 2024
e3de3b8
Fully remove isInterrupted, make readApiCall break on strings
Hal-9k1 Nov 28, 2024
7d4ff5c
Lint
Hal-9k1 Nov 28, 2024
d325358
Move editor stuff to own folder
Hal-9k1 Nov 28, 2024
1bb3f04
Add tooltip doc for Robot.get_value as POC
Hal-9k1 Nov 29, 2024
7841683
Lint again
Hal-9k1 Nov 29, 2024
0d64fae
Fix typescript errors
Hal-9k1 Nov 29, 2024
612f36c
Change default props types again
Hal-9k1 Dec 5, 2024
fed6cfa
Remove entity in JSX preventing build
Hal-9k1 Dec 5, 2024
5376ecd
Merge branch 'master' into editor-robot-api
Hal-9k1 Dec 5, 2024
d31e7a3
Merge remote-tracking branch 'origin/master' into editor-robot-api
Hal-9k1 Dec 5, 2024
d790442
Lint for hopefully the last time this PR
Hal-9k1 Dec 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 3 additions & 90 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
}
},
"dependencies": {
"@reduxjs/toolkit": "^2.2.6",
"ace-builds": "^1.35.1",
"electron-debug": "^3.2.0",
"electron-log": "^4.4.8",
Expand All @@ -109,7 +108,6 @@
"react": "^18.2.0",
"react-ace": "^12.0.0",
"react-dom": "^18.2.0",
"react-redux": "^9.1.2",
"react-router-dom": "^6.16.0"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import { config as aceConfig } from 'ace-builds';
import App from '../renderer/App';

describe('App', () => {
beforeEach(() => {
aceConfig.set('basePath', 'node_modules/ace-builds/src-noconflict');
});
it('should render', () => {
expect(render(<App />)).toBeTruthy();
});
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
useLayoutEffect,
} from 'react';
import Topbar from './Topbar';
import Editor, { EditorContentStatus, KeyboardControlsStatus } from './Editor';
import Editor, {
EditorContentStatus,
KeyboardControlsStatus,
} from './editor/Editor';
import DeviceInfo from './DeviceInfo';
import AppConsole from './AppConsole';
import type AppConsoleMessage from '../common/AppConsoleMessage'; // No crypto package on the renderer
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/editor/ApiLink.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.ApiLink {
color: blue;
text-decoration: underline;
background-color: transparent;
border: none;
padding: 0;
cursor: pointer;
}
36 changes: 36 additions & 0 deletions src/renderer/editor/ApiLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import './ApiLink.css';

/**
* Links to a section of the student API documentation, opening the help window or just jumping to
* the appropriate section if the window is already open. The single text node child of this
* component is used as the link text.
* @param props
* @param props.dest - the section of the docs to jump to. TODO: figure out format
* @param props.code - whether to display the link text in a monospaced font.
*/
export default function ApiLink({
dest,
code = false,
children,
}: {
dest: string;
code?: boolean;
children: string;
}) {
const text = `(${children})[${dest}]`;
// Placeholder
return (
<button type="button" className="ApiLink">
{code ? <code>{text}</code> : text}
</button>
);
}
/**
* Default props for ApiLink.
*/
ApiLink.defaultProps = {
/**
* By default, link text is displayed in the inherited font.
*/
code: false,
};
File renamed without changes.
58 changes: 39 additions & 19 deletions src/renderer/Editor.tsx → src/renderer/editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { useState } from 'react';
import { useState, useEffect, useRef } from 'react';
import AceEditor from 'react-ace';
import 'ace-builds/src-noconflict/mode-python';
import uploadSvg from '../../assets/upload.svg';
import downloadSvg from '../../assets/download.svg';
import openSvg from '../../assets/open.svg';
import saveSvg from '../../assets/save.svg';
import saveAsSvg from '../../assets/save-as.svg';
import newFileSvg from '../../assets/new-file.svg';
import pieSvg from '../../assets/pie.svg';
import consoleSvg from '../../assets/console.svg';
import consoleClearSvg from '../../assets/console-clear.svg';
import zoomInSvg from '../../assets/zoom-in.svg';
import zoomOutSvg from '../../assets/zoom-out.svg';
import startRobot from '../../assets/start-robot.svg';
import stopRobot from '../../assets/stop-robot.svg';
import keyboardKeySvg from '../../assets/keyboard-key.svg';
import themeSvg from '../../assets/theme.svg';
import addEditorAutocomplete from './addEditorAutocomplete';
import addEditorTooltips from './addEditorTooltips';

import 'ace-builds/src-noconflict/mode-python';
import 'ace-builds/src-noconflict/snippets/python';
import 'ace-builds/src-noconflict/ext-language_tools';
import 'ace-builds/src-noconflict/ext-searchbox';
import 'ace-builds/src-noconflict/theme-chrome';
import 'ace-builds/src-noconflict/theme-clouds';
import 'ace-builds/src-noconflict/theme-dawn';
Expand All @@ -26,6 +16,22 @@ import 'ace-builds/src-noconflict/theme-tomorrow_night';
import 'ace-builds/src-noconflict/theme-clouds_midnight';
import 'ace-builds/src-noconflict/theme-ambiance';

import uploadSvg from '../../../assets/upload.svg';
import downloadSvg from '../../../assets/download.svg';
import openSvg from '../../../assets/open.svg';
import saveSvg from '../../../assets/save.svg';
import saveAsSvg from '../../../assets/save-as.svg';
import newFileSvg from '../../../assets/new-file.svg';
import pieSvg from '../../../assets/pie.svg';
import consoleSvg from '../../../assets/console.svg';
import consoleClearSvg from '../../../assets/console-clear.svg';
import zoomInSvg from '../../../assets/zoom-in.svg';
import zoomOutSvg from '../../../assets/zoom-out.svg';
import startRobot from '../../../assets/start-robot.svg';
import stopRobot from '../../../assets/stop-robot.svg';
import keyboardKeySvg from '../../../assets/keyboard-key.svg';
import themeSvg from '../../../assets/theme.svg';

import './Editor.css';

/**
Expand Down Expand Up @@ -162,10 +168,18 @@ export default function Editor({
}) {
const [opmode, setOpmode] = useState('auto');
const [fontSize, setFontSize] = useState(12);
const editorRef = useRef(null as AceEditor | null);

const zoomEditor = (increase: boolean) => {
setFontSize((old) => old + (increase ? 1 : -1));
};
useEffect(() => {
if (editorRef.current !== null) {
const { editor } = editorRef.current;
addEditorAutocomplete(editor);
addEditorTooltips(editor);
}
}, [editorRef]);

const [theme, setTheme] = useState('dawn'); // Default theme
const handleThemeChange = (newTheme: string) => {
Expand Down Expand Up @@ -278,7 +292,9 @@ export default function Editor({
name="Editor-toolbar-opmode"
>
{Object.entries(ACE_THEMES).map(([themeKey, themeName]) => (
<option value={themeKey}>{themeName}</option>
<option key={themeKey} value={themeKey}>
{themeName}
</option>
))}
</select>
</div>
Expand Down Expand Up @@ -325,7 +341,7 @@ export default function Editor({
</div>
<div className="Editor-ace-wrapper">
<div className="Editor-kbctrl-overlay">
<span>Keyboard input sent to robot &mdash; disable to edit code</span>
<span>Keyboard input sent to robot -- disable to edit code</span>
</div>
<AceEditor
theme={theme}
Expand All @@ -335,6 +351,10 @@ export default function Editor({
onChange={onChange}
value={content}
readOnly={keyboardControlsStatus === 'on'}
ref={editorRef}
enableBasicAutocompletion
enableLiveAutocompletion
enableSnippets
/>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions src/renderer/editor/HighlightedCode.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.HighlightedCode-editor .ace_scroller {
width: 100%;
}
.HighlightedCode-editor .ace_cursor {
opacity: 0;
}
.HighlightedCode-editor .ace_marker-layer {
display: none;
}
.HighlightedCode-editor .ace_print-margin {
display: none;
}
Loading
Loading