Skip to content

Commit 788f1a9

Browse files
authored
Autocomplete feature (#1051)
* Add autocompletion and documentation display (#2) Add autocompletion and documentation display for builtins * Integrate code autocompletion * Bump js-slang version, handle editor prepend * Comment
1 parent 9638650 commit 788f1a9

File tree

23 files changed

+218
-14
lines changed

23 files changed

+218
-14
lines changed

package-lock.json

Lines changed: 23 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"draft-js": "^0.10.5",
4646
"flexboxgrid": "^6.3.1",
4747
"flexboxgrid-helpers": "^1.1.3",
48-
"js-slang": "^0.4.20",
48+
"js-slang": "^0.4.23",
4949
"jwt-decode": "^2.2.0",
5050
"lodash": "^4.17.13",
5151
"lz-string": "^1.4.4",

src/actions/actionTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const END_CLEAR_CONTEXT = 'END_CLEAR_CONTEXT';
4040
export const ENSURE_LIBRARIES_LOADED = 'ENSURE_LIBRARIES_LOADED';
4141
export const EVAL_EDITOR = 'EVAL_EDITOR';
4242
export const EVAL_REPL = 'EVAL_REPL';
43+
export const PROMPT_AUTOCOMPLETE = 'PROMPT_AUTOCOMPLETE';
4344
// For interpreting code blocks silently (e.g. prepend) BEFORE the test case is run
4445
export const EVAL_SILENT = 'EVAL_SILENT';
4546
export const EVAL_TESTCASE = 'EVAL_TESTCASE';

src/actions/workspaces.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,16 @@ export const updateHasUnsavedChanges = (
209209
workspaceLocation,
210210
hasUnsavedChanges
211211
});
212+
213+
export const promptAutocomplete = (
214+
workspaceLocation: WorkspaceLocation,
215+
row: number,
216+
column: number,
217+
callback: any // TODO: define a type for this
218+
) =>
219+
action(actionTypes.PROMPT_AUTOCOMPLETE, {
220+
workspaceLocation,
221+
row,
222+
column,
223+
callback
224+
});

src/components/Playground.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export interface IDispatchProps {
104104
handleDebuggerResume: () => void;
105105
handleDebuggerReset: () => void;
106106
handleToggleEditorAutorun: () => void;
107+
handlePromptAutocomplete: (row: number, col: number, callback: any) => void;
107108
}
108109

109110
type PlaygroundState = {
@@ -272,6 +273,7 @@ class Playground extends React.Component<IPlaygroundProps, PlaygroundState> {
272273
handleDeclarationNavigate: this.props.handleDeclarationNavigate,
273274
handleEditorEval: this.props.handleEditorEval,
274275
handleEditorValueChange: this.props.handleEditorValueChange,
276+
handlePromptAutocomplete: this.props.handlePromptAutocomplete,
275277
handleFinishInvite: this.props.handleFinishInvite,
276278
sharedbAceInitValue: this.props.sharedbAceInitValue,
277279
sharedbAceIsInviting: this.props.sharedbAceIsInviting,

src/components/__tests__/Playground.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ const baseProps = {
5454
handleUsingSubst: (usingSubst: boolean) => {},
5555
handleDebuggerPause: () => {},
5656
handleDebuggerResume: () => {},
57-
handleDebuggerReset: () => {}
57+
handleDebuggerReset: () => {},
58+
handlePromptAutocomplete: (row: number, col: number, callback: any) => {}
5859
};
5960

6061
const testValueProps: IPlaygroundProps = {

src/components/academy/grading/GradingWorkspace.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export type DispatchProps = {
8888
handleDebuggerReset: () => void;
8989
handleUpdateCurrentSubmissionId: (submissionId: number, questionId: number) => void;
9090
handleUpdateHasUnsavedChanges: (hasUnsavedChanges: boolean) => void;
91+
handlePromptAutocomplete: (row: number, col: number, callback: any) => void;
9192
};
9293

9394
class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
@@ -179,6 +180,7 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
179180
highlightedLines: this.props.highlightedLines,
180181
newCursorPosition: this.props.newCursorPosition,
181182
handleEditorUpdateBreakpoints: this.props.handleEditorUpdateBreakpoints,
183+
handlePromptAutocomplete: this.props.handlePromptAutocomplete,
182184
isEditorAutorun: false
183185
}
184186
: undefined,

src/components/assessment/AssessmentWorkspace.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export type DispatchProps = {
108108
handleDebuggerPause: () => void;
109109
handleDebuggerResume: () => void;
110110
handleDebuggerReset: () => void;
111+
handlePromptAutocomplete: (row: number, col: number, callback: any) => void;
111112
};
112113

113114
class AssessmentWorkspace extends React.Component<
@@ -248,6 +249,7 @@ class AssessmentWorkspace extends React.Component<
248249
highlightedLines: this.props.highlightedLines,
249250
newCursorPosition: this.props.newCursorPosition,
250251
handleEditorUpdateBreakpoints: this.props.handleEditorUpdateBreakpoints,
252+
handlePromptAutocomplete: this.props.handlePromptAutocomplete,
251253
isEditorAutorun: false
252254
}
253255
: undefined,

src/components/assessment/__tests__/AssessmentWorkspace.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const defaultProps: AssessmentWorkspaceProps = {
4545
handleDebuggerPause: () => {},
4646
handleDebuggerResume: () => {},
4747
handleDebuggerReset: () => {},
48+
handlePromptAutocomplete: (row: number, col: number, callback: any) => {},
4849
isRunning: false,
4950
isDebugging: false,
5051
enableDebugging: false,

src/components/missionControl/EditingWorkspace.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export type DispatchProps = {
102102
handleDebuggerReset: () => void;
103103
handleUpdateCurrentAssessmentId: (assessmentId: number, questionId: number) => void;
104104
handleUpdateHasUnsavedChanges: (hasUnsavedChanges: boolean) => void;
105+
handlePromptAutocomplete: (row: number, col: number, callback: any) => void;
105106
};
106107

107108
interface IState {
@@ -182,6 +183,7 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
182183
newCursorPosition: this.props.newCursorPosition,
183184
handleEditorUpdateBreakpoints: this.props.handleEditorUpdateBreakpoints,
184185
handleUpdateHasUnsavedChanges: this.props.handleUpdateHasUnsavedChanges,
186+
handlePromptAutocomplete: this.props.handlePromptAutocomplete,
185187
isEditorAutorun: false
186188
}
187189
: undefined,

0 commit comments

Comments
 (0)