Skip to content

feat: add vscode slice for message passing with extension #3080

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

Merged
merged 15 commits into from
Mar 3, 2025

Conversation

heyzec
Copy link
Contributor

@heyzec heyzec commented Jan 14, 2025

Description

FYP: Source Academy as Visual Studio Code Extension

This PR makes the frontend's behavior change conditionally when it detects itself to be running as an iframe in the VS Code extension. This is required so that it can send and receive the editor text contents, encapsulated as messages, to the VS Code extension.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Code quality improvements

How to test

Checklist

  • I have tested this code

@heyzec heyzec requested a review from RichDom2185 January 14, 2025 08:56
Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for working on this! Could you update the test snapshots?

@coveralls
Copy link

coveralls commented Jan 24, 2025

Pull Request Test Coverage Report for Build 13630765162

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 34 of 58 (58.62%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 31.136%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/commons/application/reducers/VscodeReducer.ts 5 6 83.33%
src/features/vscode/messages.ts 13 20 65.0%
src/commons/application/Application.tsx 8 24 33.33%
Totals Coverage Status
Change from base Build 13616162565: 0.03%
Covered Lines: 4888
Relevant Lines: 14809

💛 - Coveralls

Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor nits :)

Comment on lines 188 to 192
// useEffect(() => {
// // TODO: Hardcoded to make use of the first editor tab. Refactoring is needed for this workspace to enable Folder mode.
// handleEditorValueChange(0, '');
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this break anything with assessments? Have you tested locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my local testing, there's no unintended behavior. Assessments still loading as per normal.

handleEditorValueChange is ultimately called with the editor contents due to the useEffect here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just delete and clean up all this unused code then

@@ -222,7 +223,11 @@ const Workspace: React.FC<WorkspaceProps> = props => {
</Resizable>
<div className="row content-parent" ref={contentContainerDiv}>
<div className="editor-divider" ref={editorDividerDiv} />
<Resizable {...editorResizableProps()}>{createWorkspaceInput(props)}</Resizable>
{isVscode ? (
<div style={{ width: '0px' }}>{createWorkspaceInput(props)}</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must still be visible is it? We can't use visibility: hidden? If we can't, then in addition to width: 0, should we also use overflow: hidden?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While visibility: hidden wouldn't work, I think we can completely remove it now that messages are passed directly to the redux store rather than to the editor.

@RichDom2185 RichDom2185 enabled auto-merge (squash) February 15, 2025 07:12
Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor nits :)

Comment on lines 80 to 83
window.confirm = () => {
console.log('You gotta confirm!');
return true;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use if (window.confirm) ... instead?

Comment on lines 188 to 192
// useEffect(() => {
// // TODO: Hardcoded to make use of the first editor tab. Refactoring is needed for this workspace to enable Folder mode.
// handleEditorValueChange(0, '');
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just delete and clean up all this unused code then

const message: MessageType = event.data;
// Only accept messages from the vscode webview
if (!event.origin.startsWith('vscode-webview://')) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is a guard, but shall we log such an event?

Technically we might be able to configure our deployment with X-Frame-Options: DENY to prevent embedding but let's look into it another time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: also add Content-Security-Policy frame-ancestors 'none';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding header X-Frame-Options: DENY does not compromise the usability of the VSC extension, but Content-Security-Policy: frame-ancestors 'none'; will cause the request to be blocked within VSC.

@RichDom2185 RichDom2185 disabled auto-merge March 3, 2025 12:27
@RichDom2185 RichDom2185 enabled auto-merge (squash) March 3, 2025 12:27
Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@RichDom2185 RichDom2185 merged commit 5eae080 into master Mar 3, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants