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

editor/code: Allow to apply static analysis for codes opened in webview #15256

Closed

Conversation

tetsuharuohzeki
Copy link
Contributor

This pull request introduces build phase to bundle a code opened in a webview by esbuild.

By this change, we are able to apply a static analysis for codes that are opened in webview.

As a caveat, we might confuse the execution context between vscode extension and webview after this change. For example, you may be able to touch DOM that is not actually in the vscode extension context but TypeScript does not warn it. I think this would not be a problem in a almost case by pushing codes into src/webview/ directly.

To prevents this problem, we need introduce a separated npm workspace to use an another tsconfig.json. But I think we don't have to do it in this moment. We should postpone it to the future.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 10, 2023
@tetsuharuohzeki tetsuharuohzeki force-pushed the bundle-webview-code branch 3 times, most recently from 4ef41cb to da1755e Compare July 11, 2023 12:29
@tetsuharuohzeki tetsuharuohzeki changed the title editor/code: Allow to Type Checking codes opened in webview editor/code: Allow to apply static analysis for codes opened in webview Jul 11, 2023
@tetsuharuohzeki
Copy link
Contributor Author

I rebased on the latest master branch

@bors
Copy link
Collaborator

bors commented Jul 13, 2023

☔ The latest upstream changes (presumably #15265) made this pull request unmergeable. Please resolve the merge conflicts.

entryPoints,
format: "esm",
platform: "browser",
// VSCode v1.78 (Electron 22) uses Chromium 108.
Copy link
Member

Choose a reason for hiding this comment

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

We're back on 1.75 since #15333.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update to:

- // VSCode v1.78 (Electron 22) uses Chromium 108.
+ // VSCode v1.75 (Electron 19) uses Chromium 102.

@lnicola
Copy link
Member

lnicola commented Aug 1, 2023

For example, you may be able to touch DOM that is not actually in the vscode extension context but TypeScript does not warn it.

That's pretty bad, but I don't know if it will become a problem in practice. On the other hand, being able to move out all that code is nice.

@Veykril
Copy link
Member

Veykril commented Aug 1, 2023

That's pretty bad, but I don't know if it will become a problem in practice. On the other hand, being able to move out all that code is nice.

I think this is fine for now, we don't use a lot of webviews, nor do we much with them.

@lnicola
Copy link
Member

lnicola commented Aug 1, 2023

I think this is fine for now, we don't use a lot of webviews, nor do we much with them.

I read that a bit differently -- being able to touch (at compile-, not run-time) the browser DOM from the main extension code. But I might be wrong.

@tetsuharuohzeki
Copy link
Contributor Author

I think this is fine for now, we don't use a lot of webviews, nor do we much with them.

I read that a bit differently -- being able to touch (at compile-, not run-time) the browser DOM from the main extension code. But I might be wrong.

@lnicola @Veykril

Yes. By the current design, we can touch DOM objects that does not exist in the vscode extension scope at the compile-time (at type level). For example, the current design does not prevent that VSCode's intellisense suggests window.navigator on inputting w when we edits editors/code/src/config.ts

To prevent fragile, I think we may take an approach to use npm workspace and typescript's project reference to tell a workspace dependency to typescript compiler.

npm script cannot run it's with workspace dependency topological order npm/rfcs#548. Thus I choose typescript's project reference because I don't think it's a bit complex to introduce a monorepo tools nx or turborepo to this repository that already contains 2 programming language in heterogeneously.

But this requires the change directory hierarchy and it would be major surgery.
I'm hesitate to do it in this pull request.

@lnicola
Copy link
Member

lnicola commented Aug 2, 2023

npm script cannot run it's with workspace dependency topological order npm/rfcs#548.

Can we run tsc and whatever twice instead of relying on npm script or an external tool?

@tetsuharuohzeki
Copy link
Contributor Author

Can we run tsc and whatever twice instead of relying on npm script or an external tool?

TypeScript's project reference automatically runs tsc for all participated workspace by invoking tsc once.

@Veykril
Copy link
Member

Veykril commented Aug 15, 2023

I'm indifferent to this, I have no typescript tooling knowledge so I can't really judgbe, but I'm fine with merging this since it looks beneficial.

@bors
Copy link
Collaborator

bors commented Oct 10, 2023

☔ The latest upstream changes (presumably #15728) made this pull request unmergeable. Please resolve the merge conflicts.

@HKalbasi HKalbasi added S-waiting-on-decision and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 20, 2023
@Veykril
Copy link
Member

Veykril commented Jan 2, 2024

Having given this another look,

Yes. By the current design, we can touch DOM objects that does not exist in the vscode extension scope at the compile-time (at type level). For example, the current design does not prevent that VSCode's intellisense suggests window.navigator on inputting w when we edits editors/code/src/config.ts

does seem rather bad. So I'm more inclined to not merge this now after all

@tetsuharuohzeki
Copy link
Contributor Author

Okay, I withdraw this pr once. Thank you for discussions

@tetsuharuohzeki tetsuharuohzeki deleted the bundle-webview-code branch January 2, 2024 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants