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

IDE 刷新 / AST 同步时机优化(待定) #183

Closed
wants to merge 2 commits into from

Conversation

BoBoooooo
Copy link
Contributor

@BoBoooooo BoBoooooo commented Jul 8, 2024

问题背景 (临时错误代码不同步引擎,IDE 代码同步 AST 过于高频,且没有必要)

  • IDE 中编写(临时)错误代码,代码易被回滚,原因:IDE 组件内监听 activeFile 或 files 更新,此时 IDE 会被自动 refresh 导致代码丢失
  • IDE 模式下,引擎 AST 的解析是多余环节,此时用户不会使用设计视图
  • IDE 模式下,由于每次 IDE 失焦均会触发 updateFile AST 同步,在 JS 大文件时,有丢帧卡顿现象,造成性能浪费
  • IDE 编写的代码是否是最高优先级(目前 IDE 内的代码有错误时不会同步至 workspace)
  • IDE 是否可以编写语法错误的代码(如果支持 IDE 编写错误代码,在 code2ast 时会失败,在 prettier 格式化时会失败(已加 try catch))

目前 IDE 合法的代码同步至 Workspace 时机:

  • IDE 失焦 (该时机也不能直接去掉,也容易造成代码丢失)
  • IDE 保存快捷键

如果视为纯在线编码的沙箱,应该允许用户任意输入

可能的解决方案(重构 IDE 刷新时机 / AST 解析时机)

Workspace.File 新增 tempCode 字段

  • code
  • cleanCode
  • ast
  • tempCode: 最高优先级,临时代码直传沙箱(支持错误代码),不走 AST 解析,缺点:增加引擎理解/实现成本

AST 同步时机调整

进入 WEBIDE (预览模式)

进入 IDE 时,ast2code 同步一次代码至 IDE
此时保持预览模式,纯 IDE + 沙箱场景,没有引擎 AST 解析干预

退出 IDE (切回设计模式)

离开 IDE 时,code2ast(updateFile) 同步一次 IDE 代码至 Workspace

问题

IDE 模式下,会造成可视化面板跟 IDE 内代码不同步的问题

可能的解决方式:

  • 直接屏蔽所有可视化功能,状态/接口/新建页面等所有可视化面板均屏蔽,用户手写代码
  • 较为刚需的可视化能力,单独走事件通知 IDE 局部刷新某个文件

结论待定

对整体 Tango 设计有较大影响面,如约束用户禁止写错误代码,允许错误代码被回滚的问题,上述均可暂不处理

@BoBoooooo BoBoooooo marked this pull request as draft July 8, 2024 02:27
@BoBoooooo BoBoooooo changed the title AST 同步时机优化 IDE 刷新 / AST 同步时机优化(待定) Jul 8, 2024
@wwsun
Copy link
Contributor

wwsun commented Jul 8, 2024

比较好的方法是为源码模式提供专门的文件系统能力,这样可以独立出 IDE 部分的状态控制。只在切换模式的时候同步一次 AST。

@BoBoooooo
Copy link
Contributor Author

#188

@BoBoooooo
Copy link
Contributor Author

#190 已合并

@BoBoooooo BoBoooooo closed this Jul 31, 2024
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.

2 participants