diff --git a/docs/extension/opensumi-api/built-in-command.en.md b/docs/extension/opensumi-api/built-in-command.en.md new file mode 100644 index 00000000..2a6af171 --- /dev/null +++ b/docs/extension/opensumi-api/built-in-command.en.md @@ -0,0 +1,79 @@ +--- +id: built-in-command +title: Built-in Command +slug: built-in-command +order: 2 +--- + +OpenSumi provides a set of built-in commands, which partially implement the built-in commands of VS Code. These commands may be used in some plug-ins. If you encounter built-in commands that are not implemented, you can go to [OpenSumi Issues](https://github .com/opensumi/core/issues) for adaptation requirements. + +## Built-in command set + +| command | function | parameter | +| --------------------------------------------------------- | ------------------------------------------------------------- | -------------------------------- | +| revealInExplorer | Locate file in explorer interface | `uri`: URI | +| setContext | Set Context variable value | `key`: key, `value`: value | +| workbench.action.closeActiveEditor | Close the currently active editor | | +| workbench.action.revertAndCloseActiveEditor | Reverts the current file content and closes the active editor | | +| workbench.action.splitEditorRight | Split the current editor to the right | | +| workbench.action.splitEditorDown | Split the current editor down | | +| workbench.action.files.newUntitledFile | Create a new temporary editor file | | +| workbench.action.closeAllEditors | close all editors | | +| workbench.action.closeOtherEditors | close other editors | | +| workbench.action.files.save | Save current file | | +| workbench.action.splitEditor | Open file and split right | `resource`: ResourceArgs | URI, `editorGroup?`: EditorGroup | +| workbench.action.splitEditorOrthogonal | Open file and split down | `resource`: ResourceArgs | URI, `editorGroup?`: EditorGroup | +| workbench.action.navigateLeft | Switch to left editor | | +| workbench.action.navigateUp | switch to top editor | | +| workbench.action.navigateRight | Switch to right editor | | +| workbench.action.navigateDown | switch to bottom editor | | +| workbench.action.navigateEditorGroups | Navigate Editor Groups | | +| workbench.action.nextEditor | Switch to next file | | +| workbench.action.previousEditor | Switch to previous file | | +| workbench.action.openEditorAtIndex | Open editor by subscript position | | +| workbench.action.files.revert | Reverts the currently active file content | | +| workbench.action.terminal.clear | Clear the contents of the currently active terminal window | | +| workbench.action.terminal.toggleTerminal | Toggle Terminal Window | | +| workbench.files.action.focusFilesExplorer | Open the active editor group | | +| vscode.open | Open file (only available under Electron) | `uri`: URI, `newWindow`: boolean | +| vscode.openFolder | open folder (only available under Electron) | `uri`: URI, `newWindow`: boolean | +| workbench.action.reloadWindow (reload_window) | reload window | | +| copyFilePath | Copy file absolute path | `uri`: URI | +| copyRelativeFilePath | Relative file path to copy | `uri`: URI | +| workbench.action.openSettings | Open Settings panel | | +| workbench.action.navigateBack | Go to previous editor | | +| workbench.action.navigateForward | Navigate to the next editor | | +| workbench.action.files.saveAll | save all files | | +| workbench.action.debug.stepInto | Debug StepInto | | +| workbench.action.debug.stepOut | Debug step out | | +| workbench.action.debug.stepOver | Debug stepping | | +| workbench.action.debug.continue | debug continue | | +| workbench.action.debug.run (workbench.action.debug.start) | debug run | | +| workbench.action.debug.pause | debug pause | | +| workbench.action.debug.restart | debug restart | | +| workbench.action.debug.stop | debug stop | | +| workbench.action.showAllSymbols | Show all symbols | | + +## Usage + +> For example, use `vscode.open` to open a file with a protocol + +```typescript +import * as sumi from 'sumi'; + +// Parameter Description +type VSCodeOpen = ( + resource: vscode.Uri, + columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions, + label?: string +) => void; + +sumi.commands.executeCommand( + 'vscode. open', + { + preserveFocus: true, + preview: false + } as vscode.TextDocumentShowOptions, + 'test-title' +); +``` diff --git a/docs/extension/opensumi-api/built-in-command.zh.md b/docs/extension/opensumi-api/built-in-command.zh.md new file mode 100644 index 00000000..d07f561c --- /dev/null +++ b/docs/extension/opensumi-api/built-in-command.zh.md @@ -0,0 +1,79 @@ +--- +id: built-in-command +title: 内置命令 +slug: built-in-command +order: 2 +--- + +OpenSumi 提供了一套内置命令,部分实现了 VS Code 内置实现的命令,这些命令可能会在某些插件被使用,如果遇到了没有实现的内置命令,可以前往 [OpenSumi Issues](https://github.com/opensumi/core/issues) 提适配需求。 + +## 内置命令集 + +| 命令 | 功能 | 参数 | +| --------------------------------------------------------- | ------------------------------------ | -------------------------------- | +| revealInExplorer | 在资源管理器界面定位文件 | `uri`: URI | +| setContext | 设置 Context 变量值 | `key`:键, `value`:值 | +| workbench.action.closeActiveEditor | 关闭当前激活的编辑器 | | +| workbench.action.revertAndCloseActiveEditor | 恢复当前文件内容同时关闭激活的编辑器 | | +| workbench.action.splitEditorRight | 向右拆分当前编辑器 | | +| workbench.action.splitEditorDown | 向下拆分当前编辑器 | | +| workbench.action.files.newUntitledFile | 新建临时的编辑器文件 | | +| workbench.action.closeAllEditors | 关闭所有编辑器 | | +| workbench.action.closeOtherEditors | 关闭其他编辑器 | | +| workbench.action.files.save | 保存当前文件 | | +| workbench.action.splitEditor | 打开文件并向右拆分 | `resource` : ResourceArgs | URI, `editorGroup?`:EditorGroup | +| workbench.action.splitEditorOrthogonal | 打开文件并向下拆分 | `resource` : ResourceArgs | URI, `editorGroup?`: EditorGroup | +| workbench.action.navigateLeft | 切换到左侧编辑器 | | +| workbench.action.navigateUp | 切换到顶部编辑器 | | +| workbench.action.navigateRight | 切换到右侧编辑器 | | +| workbench.action.navigateDown | 切换到底部编辑器 | | +| workbench.action.navigateEditorGroups | 切换编辑器组 | | +| workbench.action.nextEditor | 切换至下个文件 | | +| workbench.action.previousEditor | 切换至上个文件 | | +| workbench.action.openEditorAtIndex | 通过下标位置打开编辑器 | | +| workbench.action.files.revert | 恢复当前激活的文件内容 | | +| workbench.action.terminal.clear | 清理当前激活的终端窗口内容 | | +| workbench.action.terminal.toggleTerminal | 打开/关闭 终端窗口 | | +| workbench.files.action.focusFilesExplorer | 打开激活的编辑器组 | | +| vscode.open | 打开文件(仅在 Electron 下可用) | `uri`: URI, `newWindow`: boolean | +| vscode.openFolder | 打开文件夹(仅在 Electron 下可用) | `uri`: URI, `newWindow`: boolean | +| workbench.action.reloadWindow (reload_window) | 重载窗口 | | +| copyFilePath | 复制文件绝对路径 | `uri`: URI | +| copyRelativeFilePath | 复制文件相对路径 | `uri`: URI | +| workbench.action.openSettings | 打开设置面板 | | +| workbench.action.navigateBack | 前往上一个编辑器 | | +| workbench.action.navigateForward | 前往下一个编辑器 | | +| workbench.action.files.saveAll | 保存全部文件 | | +| workbench.action.debug.stepInto | 调试步入 | | +| workbench.action.debug.stepOut | 调试步出 | | +| workbench.action.debug.stepOver | 调试步进 | | +| workbench.action.debug.continue | 调试继续 | | +| workbench.action.debug.run (workbench.action.debug.start) | 调试运行 | | +| workbench.action.debug.pause | 调试暂停 | | +| workbench.action.debug.restart | 调试重启 | | +| workbench.action.debug.stop | 调试终止 | | +| workbench.action.showAllSymbols | 展示所有符号 | | + +## 用法 + +> 例如使用 `vscode.open` 打开一个带协议的文件 + +```typescript +import * as sumi from 'sumi'; + +// 参数说明 +type VSCodeOpen = ( + resource: vscode.Uri, + columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions, + label?: string +) => void; + +sumi.commands.executeCommand( + 'vscode.open', + { + preserveFocus: true, + preview: false + } as vscode.TextDocumentShowOptions, + 'test-title' +); +``` diff --git a/docs/extension/opensumi-api/built-in-component.en.md b/docs/extension/opensumi-api/built-in-component.en.md new file mode 100644 index 00000000..07b6095d --- /dev/null +++ b/docs/extension/opensumi-api/built-in-component.en.md @@ -0,0 +1,187 @@ +--- +id: built-in-component +title: Built-in Component +slug: built-in-component +order: 3 +--- + +OpenSumi has built-in some basic components, which can be imported and used through the `sumi-browser` module when the browser-side plug-in is running. + +The current built-in components include: + +```bash +├── Badge +├── Button +├── Checkbox +├── Dialog +├── Icon +├── Input +├── Message +├── Notification +├── Overlay +├── Popover +├── RecycleList +├── BasicRecycleTree +├── Scrollbars +├── Select +├── Tabs +├── Tooltip + +``` + +For some usage examples, see: [Use Built-in Components](https://github.com/opensumi/opensumi-module-samples/tree/main/modules/components). + +## Other component libraries + +You can also continue to use the popular `AntD` component library in the community in OpenSumi, and you only need to import the theme package we provide to use it normally. + +- [opensumi/antd-theme](https://github.com/opensumi/antd-theme) - AntD theme package based on OpenSumi + +The usage is as follows: + +```tsx +import '@opensumi/antd-theme/lib/index.css'; +import { ConfigProvider } from 'antd'; + +// ... +return ( + + + +); +``` + +其他主题库适配期待社区的贡献。 + +## 自定义适配主题的组件 + +For developers who do not meet the above schemes, or expect to write their own CSS styles to adapt to the theme, you can refer to the Token table below to use the corresponding CSS Token, such as Token is `kt.disableForeground`, you can pass `var( --kt-disableForeground)` reference. + +| Blocks | Doc | +| ------------ | ------------------------------------------------------------------------------------------------------------------------------------ | +| 主题色板 | [主题色板](https://github.com/opensumi/core/wiki/%E4%B8%BB%E9%A2%98%E8%89%B2%E6%9D%BF) | +| 基础颜色 | [基础颜色](https://github.com/opensumi/core/wiki/%E5%9F%BA%E7%A1%80%E9%A2%9C%E8%89%B2) | +| Button | [Button 按钮](https://github.com/opensumi/core/wiki/Button-%E6%8C%89%E9%92%AE) | +| Checkbox | [Checkbox 多选框](https://github.com/opensumi/core/wiki/Checkbox-%E5%A4%9A%E9%80%89%E6%A1%86) | +| Input | [Input 输入框](https://github.com/opensumi/core/wiki/Input-%E8%BE%93%E5%85%A5%E6%A1%86) | +| Select | [Select 选择器](https://github.com/opensumi/core/wiki/Select-%E9%80%89%E6%8B%A9%E5%99%A8) | +| Editor | [Editor 编辑器](https://github.com/opensumi/core/wiki/Editor-%E7%BC%96%E8%BE%91%E5%99%A8) | +| ActionBar | [ActionBar 操作组](https://github.com/opensumi/core/wiki/ActionBar-%E6%93%8D%E4%BD%9C%E7%BB%84) | +| ActivityBar | [ActivityBar 左右侧活动栏](https://github.com/opensumi/core/wiki/ActivityBar-%E5%B7%A6%E5%8F%B3%E4%BE%A7%E6%B4%BB%E5%8A%A8%E6%A0%8F) | +| Bottom Panel | [Bottom Panel 底部面板](https://github.com/opensumi/core/wiki/Bottom-Panel-%E5%BA%95%E9%83%A8%E9%9D%A2%E6%9D%BF) | +| Explorer | [Explorer 资源管理器](https://github.com/opensumi/core/wiki/Explorer-%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86%E5%99%A8) | +| Keybinding | [Keybinding 快捷键页](https://github.com/opensumi/core/wiki/Keybinding-%E5%BF%AB%E6%8D%B7%E9%94%AE%E9%A1%B5) | +| MenuBar | [MenuBar 菜单栏](https://github.com/opensumi/core/wiki/MenuBar-%E8%8F%9C%E5%8D%95%E6%A0%8F) | +| Message | [Message 全局提示](https://github.com/opensumi/core/wiki/Message-%E5%85%A8%E5%B1%80%E6%8F%90%E7%A4%BA) | +| Modal | [Modal 对话框](https://github.com/opensumi/core/wiki/Modal-%E5%AF%B9%E8%AF%9D%E6%A1%86) | +| Notification | [Notification 通知提醒框](https://github.com/opensumi/core/wiki/Notification-%E9%80%9A%E7%9F%A5%E6%8F%90%E9%86%92%E6%A1%86) | +| Popover | [Popover 气泡卡片](https://github.com/opensumi/core/wiki/Popover-%E6%B0%94%E6%B3%A1%E5%8D%A1%E7%89%87) | +| SCM | [SCM 源代码管理](https://github.com/opensumi/core/wiki/SCM-%E6%BA%90%E4%BB%A3%E7%A0%81%E7%AE%A1%E7%90%86) | +| Search | [Search 搜索](https://github.com/opensumi/core/wiki/Search-%E6%90%9C%E7%B4%A2) | +| Setting | [Setting 设置页](https://github.com/opensumi/core/wiki/Setting-%E8%AE%BE%E7%BD%AE%E9%A1%B5) | +| Sidebar | [Sidebar 侧边栏面板](https://github.com/opensumi/core/wiki/Sidebar-%E4%BE%A7%E8%BE%B9%E6%A0%8F%E9%9D%A2%E6%9D%BF) | +| StatusBar | [StatusBar 底部状态栏](https://github.com/opensumi/core/wiki/StatusBar-%E5%BA%95%E9%83%A8%E7%8A%B6%E6%80%81%E6%A0%8F) | +| Tab | [Tab 标签页](https://github.com/opensumi/core/wiki/Tab-%E6%A0%87%E7%AD%BE%E9%A1%B5) | +| ToolBar | [ToolBar 工具栏](https://github.com/opensumi/core/wiki/ToolBar-%E5%B7%A5%E5%85%B7%E6%A0%8F) | +| Tooltip | [Tooltip 文字提示](https://github.com/opensumi/core/wiki/Tooltip-%E6%96%87%E5%AD%97%E6%8F%90%E7%A4%BA) | + +Most custom tokens are usually backward compatible with [Theme Color](https://code.visualstudio.com/api/references/theme-color) of VS Code, and you can also use these tokens directly. + +If you feel that the definition of this part of the color value table cannot meet your needs, on the one hand, you can consider providing a PR for OpenSumi to expand it, on the other hand, you can also bypass this part of the limitation by processing it on the integration side To solve, two common methods are introduced below: + +### Style customization by ClassName + +Customize through the scope of ClassName, such as: + +```css +.vs-dark { + .a { + color: #fff; // Dark Theme Model, the text will be white + } +} + +.vs { + .a { + color: #000; // Light Theme Model, the text will be black + } +} +``` + +### Use the `registerColor` method to register a custom token + +It should be noted here that it is necessary to ensure that the `registerColor` method is called before the application starts, and it is recommended to introduce it in the `renderApp` phase. + +```ts +// The entry file +import './custom-token'; +// ... + +renderApp({...}); +``` + +```ts +// custom-token.ts +import { + registerColor, + ktPrimaryButtonForeground, + ktPrimaryButtonBackground, + ktPrimaryButtonClickBackground +} from '@opensumi/ide-theme'; +import { localize } from '@opensumi/ide-core-browser'; + +export const ktToolbarButtonSelectionForeground = registerColor( + 'kt.toolbarButton.selectionForeground', + { + dark: ktPrimaryButtonForeground, + light: ktPrimaryButtonForeground, + hcDark: null, + hcLight: null + }, + localize('Active toolbar button foreground.') +); +export const ktToolbarButtonSelectionBackground = registerColor( + 'kt.toolbarButton.selectionBackground', + { + dark: ktPrimaryButtonBackground, + light: ktPrimaryButtonBackground, + hcDark: null, + hcLight: null + }, + localize('Active toolbar button background.') +); +export const ktToolbarButtonForeground = registerColor( + 'kt.toolbarButton.foreground', + { + dark: ktPrimaryButtonForeground, + light: ktPrimaryButtonForeground, + hcDark: null, + hcLight: null + }, + localize('Default toolbar button foreground.') +); +export const ktToolbarButtonBackground = registerColor( + 'kt.toolbarButton.background', + { + dark: ktPrimaryButtonClickBackground, + light: ktPrimaryButtonClickBackground, + hcDark: null, + hcLight: null + }, + localize('Default toolbar button background.') +); +``` + +## Use floating components + +When writing extensions, we will inevitably use floating windows to allow users to perform secondary interactions. When writing such codes on the OpenSumi Browser side, since the overall solution adopts a sandbox isolation mechanism, the Browser layer in the extension cannot get the top `Document`, so when using components with floating properties such as `Modal`, `Dialog`, `Select` in some libraries, you need to re-bind a rendering container for such components. + +Take the `Modal` component in AntD as an example, you need to pass in the rendering container of the current component when using it, otherwise the corresponding component will not work properly. + +```tsx +// ... + +

Some contents...

+

Some contents...

+

Some contents...

+
+``` diff --git a/docs/extension/opensumi-api/built-in-component.zh.md b/docs/extension/opensumi-api/built-in-component.zh.md new file mode 100644 index 00000000..73dcfb5c --- /dev/null +++ b/docs/extension/opensumi-api/built-in-component.zh.md @@ -0,0 +1,187 @@ +--- +id: built-in-component +title: 内置组件 +slug: built-in-component +order: 3 +--- + +OpenSumi 内置了一些基础的组件,在 Browser 端插件运行时可以通过 `sumi-browser` 模块引入这些组件来使用。 + +目前的内置组件包含: + +```bash +├── Badge +├── Button +├── Checkbox +├── Dialog +├── Icon +├── Input +├── Message +├── Notification +├── Overlay +├── Popover +├── RecycleList +├── BasicRecycleTree +├── Scrollbars +├── Select +├── Tabs +├── Tooltip + +``` + +部分使用示例见:[Use Built-in Components](https://github.com/opensumi/opensumi-module-samples/tree/main/modules/components)。 + +## 其他组件库 + +你也可以在 OpenSumi 中继续使用社区中流行的 `AntD` 组件库,使用时只需要引入我们提供的主题包即可正常使用。 + +- [opensumi/antd-theme](https://github.com/opensumi/antd-theme) —— AntD 基于 OpenSumi 的主题包 + +用法如下: + +```tsx +import '@opensumi/antd-theme/lib/index.css'; +import { ConfigProvider } from 'antd'; + +// ... +return ( + + + +); +``` + +其他主题库适配期待社区的贡献。 + +## 自定义适配主题的组件 + +对于不满足以上方案的同学,或者期望自行编写 CSS 样式来适配主题,可以参考下面的 Token 表使用对应的 CSS Token,如 Token 为 `kt.disableForeground`, 在使用时就可以通过 `var(--kt-disableForeground)` 引用。 + +| 区块 | 文档 | +| ------------ | ------------------------------------------------------------------------------------------------------------------------------------ | +| 主题色板 | [主题色板](https://github.com/opensumi/core/wiki/%E4%B8%BB%E9%A2%98%E8%89%B2%E6%9D%BF) | +| 基础颜色 | [基础颜色](https://github.com/opensumi/core/wiki/%E5%9F%BA%E7%A1%80%E9%A2%9C%E8%89%B2) | +| Button | [Button 按钮](https://github.com/opensumi/core/wiki/Button-%E6%8C%89%E9%92%AE) | +| Checkbox | [Checkbox 多选框](https://github.com/opensumi/core/wiki/Checkbox-%E5%A4%9A%E9%80%89%E6%A1%86) | +| Input | [Input 输入框](https://github.com/opensumi/core/wiki/Input-%E8%BE%93%E5%85%A5%E6%A1%86) | +| Select | [Select 选择器](https://github.com/opensumi/core/wiki/Select-%E9%80%89%E6%8B%A9%E5%99%A8) | +| Editor | [Editor 编辑器](https://github.com/opensumi/core/wiki/Editor-%E7%BC%96%E8%BE%91%E5%99%A8) | +| ActionBar | [ActionBar 操作组](https://github.com/opensumi/core/wiki/ActionBar-%E6%93%8D%E4%BD%9C%E7%BB%84) | +| ActivityBar | [ActivityBar 左右侧活动栏](https://github.com/opensumi/core/wiki/ActivityBar-%E5%B7%A6%E5%8F%B3%E4%BE%A7%E6%B4%BB%E5%8A%A8%E6%A0%8F) | +| Bottom Panel | [Bottom Panel 底部面板](https://github.com/opensumi/core/wiki/Bottom-Panel-%E5%BA%95%E9%83%A8%E9%9D%A2%E6%9D%BF) | +| Explorer | [Explorer 资源管理器](https://github.com/opensumi/core/wiki/Explorer-%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86%E5%99%A8) | +| Keybinding | [Keybinding 快捷键页](https://github.com/opensumi/core/wiki/Keybinding-%E5%BF%AB%E6%8D%B7%E9%94%AE%E9%A1%B5) | +| MenuBar | [MenuBar 菜单栏](https://github.com/opensumi/core/wiki/MenuBar-%E8%8F%9C%E5%8D%95%E6%A0%8F) | +| Message | [Message 全局提示](https://github.com/opensumi/core/wiki/Message-%E5%85%A8%E5%B1%80%E6%8F%90%E7%A4%BA) | +| Modal | [Modal 对话框](https://github.com/opensumi/core/wiki/Modal-%E5%AF%B9%E8%AF%9D%E6%A1%86) | +| Notification | [Notification 通知提醒框](https://github.com/opensumi/core/wiki/Notification-%E9%80%9A%E7%9F%A5%E6%8F%90%E9%86%92%E6%A1%86) | +| Popover | [Popover 气泡卡片](https://github.com/opensumi/core/wiki/Popover-%E6%B0%94%E6%B3%A1%E5%8D%A1%E7%89%87) | +| SCM | [SCM 源代码管理](https://github.com/opensumi/core/wiki/SCM-%E6%BA%90%E4%BB%A3%E7%A0%81%E7%AE%A1%E7%90%86) | +| Search | [Search 搜索](https://github.com/opensumi/core/wiki/Search-%E6%90%9C%E7%B4%A2) | +| Setting | [Setting 设置页](https://github.com/opensumi/core/wiki/Setting-%E8%AE%BE%E7%BD%AE%E9%A1%B5) | +| Sidebar | [Sidebar 侧边栏面板](https://github.com/opensumi/core/wiki/Sidebar-%E4%BE%A7%E8%BE%B9%E6%A0%8F%E9%9D%A2%E6%9D%BF) | +| StatusBar | [StatusBar 底部状态栏](https://github.com/opensumi/core/wiki/StatusBar-%E5%BA%95%E9%83%A8%E7%8A%B6%E6%80%81%E6%A0%8F) | +| Tab | [Tab 标签页](https://github.com/opensumi/core/wiki/Tab-%E6%A0%87%E7%AD%BE%E9%A1%B5) | +| ToolBar | [ToolBar 工具栏](https://github.com/opensumi/core/wiki/ToolBar-%E5%B7%A5%E5%85%B7%E6%A0%8F) | +| Tooltip | [Tooltip 文字提示](https://github.com/opensumi/core/wiki/Tooltip-%E6%96%87%E5%AD%97%E6%8F%90%E7%A4%BA) | + +大部分自定义 Token 通常会向下兼容到 VS Code 的 [Theme Color](https://code.visualstudio.com/api/references/theme-color),你也可以直接使用这些 Token。 + +如果你觉得这部分色值表的定义不能满足你的需求,一方面,你可以考虑为 OpenSumi 提供一个 PR 拓展一下,另一方面,你也可以绕开这部分限制,通过在集成侧处理的方式解决,下面介绍两种常用手段: + +### 通过 ClassName 进行样式自定义 + +通过 ClassName 的作用域进行自定义,如: + +```css +.vs-dark { + .a { + color: #fff; // 暗色主题下 `.a` 的字体颜色为白色 + } +} + +.vs { + .a { + color: #000; // 亮色主题下 `.a` 的字体颜色为黑色 + } +} +``` + +### 使用 `registerColor` 方法注册自定义 Token + +这里需要注意的是需要保证 `registerColor` 方法的调用在应用启动前,建议放在 `renderApp` 阶段引入。 + +```ts +// 入口文件 +import './custom-token'; +// ... + +renderApp({...}); +``` + +```ts +// custom-token.ts +import { + registerColor, + ktPrimaryButtonForeground, + ktPrimaryButtonBackground, + ktPrimaryButtonClickBackground +} from '@opensumi/ide-theme'; +import { localize } from '@opensumi/ide-core-browser'; + +export const ktToolbarButtonSelectionForeground = registerColor( + 'kt.toolbarButton.selectionForeground', + { + dark: ktPrimaryButtonForeground, + light: ktPrimaryButtonForeground, + hcDark: null, + hcLight: null + }, + localize('Active toolbar button foreground.') +); +export const ktToolbarButtonSelectionBackground = registerColor( + 'kt.toolbarButton.selectionBackground', + { + dark: ktPrimaryButtonBackground, + light: ktPrimaryButtonBackground, + hcDark: null, + hcLight: null + }, + localize('Active toolbar button background.') +); +export const ktToolbarButtonForeground = registerColor( + 'kt.toolbarButton.foreground', + { + dark: ktPrimaryButtonForeground, + light: ktPrimaryButtonForeground, + hcDark: null, + hcLight: null + }, + localize('Default toolbar button foreground.') +); +export const ktToolbarButtonBackground = registerColor( + 'kt.toolbarButton.background', + { + dark: ktPrimaryButtonClickBackground, + light: ktPrimaryButtonClickBackground, + hcDark: null, + hcLight: null + }, + localize('Default toolbar button background.') +); +``` + +## 使用浮动组件 + +在编写插件中我们难免会使用浮窗让用户进行二次交互,在 OpenSumi Browser 端中编写这类代码,由于整体方案采用了一种沙箱的隔离机制,插件内的 Browser 层是获取不到顶部的 `Document` 的,故在使用一部分库的 `Modal` 、 `Dialog` 、 `Select` 等带浮动属性的组件时,你需要重新为这类组件绑定一个渲染容器。 + +以 AntD 中的 `Modal` 组件为例,你在使用时需要传入一下当前组件的渲染容器,否则对应的组件将不能正常工作。 + +```tsx +// ... + +

Some contents...

+

Some contents...

+

Some contents...

+
+``` diff --git a/docs/extension/opensumi-api/built-in-icon.en.md b/docs/extension/opensumi-api/built-in-icon.en.md new file mode 100644 index 00000000..1deda3a0 --- /dev/null +++ b/docs/extension/opensumi-api/built-in-icon.en.md @@ -0,0 +1,14 @@ +--- +id: built-in-icon +title: Built-in Icons +slug: built-in-icon +order: 1 +--- + +OpenSumi provides a set of built-in icon sets, these icons are maintained based on [iconfont](https://www.iconfont.cn/), you can directly use `iconClass: ` to reference when registering panels such as views these icons. + +## OpenSumi built-in icon list + +![Built-in Icon](https://img.alicdn.com/imgextra/i1/O1CN01zxObcW27Z25ygkmuZ_!!6000000007810-2-tps-2920-1566.png) + +Online address: [OpenSumi built-in icon list](https://opensumi.github.io/core/iconfont.html). diff --git a/docs/extension/opensumi-api/built-in-icon.zh.md b/docs/extension/opensumi-api/built-in-icon.zh.md new file mode 100644 index 00000000..b1be8152 --- /dev/null +++ b/docs/extension/opensumi-api/built-in-icon.zh.md @@ -0,0 +1,14 @@ +--- +id: built-in-icon +title: 内置图标 +slug: built-in-icon +order: 1 +--- + +OpenSumi 提供了一套内置的图标集,这些图标是基于 [iconfont](https://www.iconfont.cn/) 维护的,在注册视图等面板时可以直接使用 `iconClass: ` 来引用这些图标。 + +## 图标集在线预览 + +![Built-in Icon](https://img.alicdn.com/imgextra/i1/O1CN01zxObcW27Z25ygkmuZ_!!6000000007810-2-tps-2920-1566.png) + +在线地址:[OpenSumi built-in icon list](https://opensumi.github.io/core/iconfont.html)。 diff --git a/docs/extension/opensumi-api/connection-mode.en.md b/docs/extension/opensumi-api/connection-mode.en.md new file mode 100644 index 00000000..b4455d85 --- /dev/null +++ b/docs/extension/opensumi-api/connection-mode.en.md @@ -0,0 +1,209 @@ +--- +id: connection-mode +title: Connection Mode +slug: connection-mode +order: 0 +--- + +The OpenSumi extension supports extensions in both Browser and Node environments. Generally, we recommend that you only register views at the Browser entry and write extension business logic in the Node entry. + +## Front-end and Back-end communication + +![Click](https://img.alicdn.com/imgextra/i3/O1CN01jgVXs41u6YSrFgIZY_!!6000000005988-2-tps-362-120.png) + +Considering the above scenario, I want to pop up an error message when the button is clicked. This requires declaring a button in the left area of the extension at the Browser entry and implementing the logic to pop up the error message in the Node entry of the extension. + +### Browser entry + +Implement the component in `extend/browser/Leftview.tsx`: + +```tsx +// extend/browser/Leftview.tsx +import * as React from 'react'; + +import { Button } from '@ali/ide-components'; + +export const Leftview: React.FC> = ({ + sumiExtendSet, + sumiExtendService +}) => { + const defaultTitle = 'Click'; + const [title, setTitle] = useState(defaultTitle); + + function onDidUpdateTitle(val: string) { + setTitle(defaultTitle + ' ' + val); + } + + useEffect(() => { + if (sumiExtendSet) { + sumiExtendSet.set({ + updateTitle: onDidUpdateTitle + }); + } + }, []); + function handleClick() { + // sumiExtendService.node is an API Proxy + sumiExtendService.node.sayHello(); + } + return ( + + ); +}; +``` + +Export components under `extend/browser/index.ts`: + +```typescript +// extend/browser/index.ts +import { Leftview } from './toolbar-button'; + +export { Leftview }; +``` + +Declare where and how components are rendered in `package.json`: + +```json +// package.json +{ + "kaitianContributes": { + "browserMain": "./out/browser/index.js", + "nodeMain": "./out/node/index.js", + "viewsProxies": ["Leftview"], + "browserViews": { + "left": { + "type": "add", + "view": [ + { + "id": "Leftview", + "icon": "extension" + } + ] + } + } + } +} +``` + +In this code, we declare a view whose rendering position is the position of the left sidebar. + +In the component, we bind an event handler to the button, and call the method from `props.sumiExtendService.node` when clicked (please note that this is a proxy of the extension Node entry API, this code will not be directly in the running in a Node environment). + +At the same time, we also bind an `updateTitle` method in the Browser entry, which can also be called in the subsequent Node entry code. + +### Node entry + +```typescript +// extend/node/index.ts +import * as sumi from 'sumi'; // sumi node API (extends vscode) + +export function activate(context: sumi.ExtensionContext) { + const { componentProxy, registerExtendModuleService } = context; + + registerExtendModuleService({ + async sayHello() { + // Call the `updateTitle` method registered in the Leftview component + await componentProxy.Leftview.updateTitle('Hello sumi Extension'); + sumi.window.showInformationMessage('Hello OpenSumi'); + return 'Hello sumi Extension'; + } + }); +} +``` + +In this code, we call `registerExtendModuleService` in the `activate` function to register a method named `sayHello`. + +In this way, the method of the Node entry can be called through the front end in the OpenSumi extension, and you can also encapsulate complex logic in the extension of the Node environment to avoid running too many tasks in the UI extension and causing the interface to freeze. + +At the same time, we need to obtain the front-end methods bound through `sumiExtendSet` in the front-end components through `componentProxy` at the Node entry. + +The final running effect is as follows: + +![Preview](https://img.alicdn.com/imgextra/i3/O1CN01rQT5p11bgl4Y5Jiau_!!6000000003495-1-tps-960-518.gif) + +## Use Command to communication + +In addition to the above methods, you can also use the more familiar `command` mechanism to achieve front-end and back-end communication. Command is a very important and common mechanism in OpenSumi and VS Code. Use `registerCommand` and `executeCommand` two methods To register and execute commands, OpenSumi also provides the `executeCommand` method in the front-end API (in order to reduce the complexity, the `registerCommand` method is not provided for now). In this way, you can call the commands registered in the Node entry through `executeCommand` on the front end. + +```typescript +// Node environment +import { commands } from 'sumi'; + +export function activate() { + commands.regiterCommand('getProjectType', () => { + //... + }); +} + +// front-end environment + +import { commands } from 'sumi-browser'; + +export const MyProjectView = () => { + const handleGetProjectType = useCallback(() => { + commands.executeCommand('getProjectType').then(res => { + //... + }); + }, []); + return ( +
+ +
+ ); +}; +``` + +## Communication between extensions + +In the VS Code extension, the API can be exposed externally by returning a set of objects through the `activate` function. For other extensions, the extension instance can be obtained through `vscode.extensions.getExtension`, and these APIs can be called. + +For example, extension A exposes `sayHello` interface in `activate` function + +```ts +function activate(context) { + return { + sayHello() { + // return sayHello + //... + } + }; +} +``` + +In extension B it can be used like this: + +```ts +async function activate(context) { + const exta = vscode.extensions.getExtension('{ID of extension A}'); // such as `opensumi.a` + + await exta.activate(); + exta.exports.sayHello(); // call sayHello +} +``` + +In the Node entry of the OpenSumi extension, this method can also be used to call each other, and the attribute for accessing the Node entry of the OpenSumi extension is named `exetndsExports`, which is different from VS Code. + +Similarly, the `activate` method in `extend/node/index.ts` returns the object: + +```typescript +function activate(context) { + return { + sayHello() { + // return sayHello + //... + } + }; +} +``` + +In another extension it can be used like this: + +```ts +async function activate(context) { + const exta = sumi.extensions.getExtension('{ID of extension A}'); // such as `opensumi.a` + + await exta.activate(); + exta.extendExports.sayHello(); // call sayHello +} +``` diff --git a/docs/extension/opensumi-api/connection-mode.zh.md b/docs/extension/opensumi-api/connection-mode.zh.md new file mode 100644 index 00000000..9e3d4515 --- /dev/null +++ b/docs/extension/opensumi-api/connection-mode.zh.md @@ -0,0 +1,209 @@ +--- +id: connection-mode +title: 通信模型 +slug: connection-mode +order: 0 +--- + +OpenSumi 插件支持 Browser 及 Node 环境下的扩展,一般的我们建议在 Browser 层仅注册视图,在 Node 层编写插件业务逻辑。 + +## 前后端通信 + +![Click](https://img.alicdn.com/imgextra/i3/O1CN01jgVXs41u6YSrFgIZY_!!6000000005988-2-tps-362-120.png) + +考虑以上场景,我希望在点击按钮时弹出一个错误弹窗,这需要在插件 Browser 层声明一个位于左侧区域的按钮,同时在插件 Node 层实现弹出错误的逻辑。 + +### Borwser 层实现 + +在 `extend/browser/Leftview.tsx` 下实现组件: + +```tsx +// extend/browser/Leftview.tsx +import * as React from 'react'; + +import { Button } from '@ali/ide-components'; + +export const Leftview: React.FC> = ({ + sumiExtendSet, + sumiExtendService +}) => { + const defaultTitle = 'Click'; + const [title, setTitle] = useState(defaultTitle); + + function onDidUpdateTitle(val: string) { + setTitle(defaultTitle + ' ' + val); + } + + useEffect(() => { + if (sumiExtendSet) { + sumiExtendSet.set({ + updateTitle: onDidUpdateTitle + }); + } + }, []); + function handleClick() { + // sumiExtendService.node 包含一份该插件注册的 API Proxy + sumiExtendService.node.sayHello(); + } + return ( + + ); +}; +``` + +在 `extend/browser/index.ts` 下导出组件 + +```typescript +// extend/browser/index.ts +import { Leftview } from './toolbar-button'; + +export { Leftview }; +``` + +在 `package.json` 中声明组件渲染位置及方式: + +```json +// package.json +{ + "kaitianContributes": { + "browserMain": "./out/browser/index.js", + "nodeMain": "./out/node/index.js", + "viewsProxies": ["Leftview"], + "browserViews": { + "left": { + "type": "add", + "view": [ + { + "id": "Leftview", + "icon": "extension" + } + ] + } + } + } +} +``` + +这段代码中,我们声明了一个视图,其渲染位置为左侧边栏位置。 + +在组件中我们为按钮绑定了一个事件处理函数,点击时调用来自 `props.sumiExtendService.node` 上的方法 (请注意,这是一个插件 Node 层 API 的代理,这段代码并不会直接在 Node 环境中运行)。 + +同时,我们也在 Browser 层绑定了一个 `updateTitle` 方法,该方法也可以在后续的 Node 层代码中被调用。 + +### Node 层实现 + +```typescript +// extend/node/index.ts +import * as sumi from 'sumi'; // sumi node API (extends vscode) + +export function activate(context: sumi.ExtensionContext) { + const { componentProxy, registerExtendModuleService } = context; + + registerExtendModuleService({ + async sayHello() { + // 调用 Leftview 组件中注册的 `updateTitle` 方法 + await componentProxy.Leftview.updateTitle('Hello sumi Extension'); + sumi.window.showInformationMessage('Hello OpenSumi'); + return 'Hello sumi Extension'; + } + }); +} +``` + +这段代码中,我们在 `activate` 函数里调用 `registerExtendModuleService` 注册了一个名为 `sayHello` 的方法。 + +这样既可在 OpenSumi 插件中通过前端调用 Node 层的方法,你也可以将复杂的逻辑封装在 Node 环境的插件里,避免在 UI 插件中运行过多的任务导致界面卡顿。 + +同时,我们需要在 Node 层也可以通过 `componentProxy` 获取到在前端组件中通过 `sumiExtendSet` 绑定的前端方法。 + +最终的运行效果如下: + +![Preview](https://img.alicdn.com/imgextra/i3/O1CN01rQT5p11bgl4Y5Jiau_!!6000000003495-1-tps-960-518.gif) + +## 使用 Command 实现前后端通信 + +除了上述方式外,也可以使用我们更为熟悉的 `command` 机制来实现前后端通信,command 是 OpenSumi 和 VS Code 中非常重要且常见的一种机制,使用 `registerCommand` 与 `executeCommand` 两个方法来注册与执行命令,OpenSumi 在前端 API 中也提供了 `executeCommand` 方法(为降低复杂度,暂不提供 `registerCommand` 方法)。这样一来,你可以在前端通过 `executeCommand` 来调用 Node 层注册的命令。 + +```typescript +// Node 环境 +import { commands } from 'sumi'; + +export function activate() { + commands.regiterCommand('getProjectType', () => { + //... + }); +} + +// 前端环境 + +import { commands } from 'sumi-browser'; + +export const MyProjectView = () => { + const handleGetProjectType = useCallback(() => { + commands.executeCommand('getProjectType').then(res => { + //... + }); + }, []); + return ( +
+ +
+ ); +}; +``` + +## 插件间通信 + +在 VS Code 插件中,通过 `activate` 函数返回一组对象的方式,可以对外暴露 API,对于其他插件,可以通过 `vscode.extensions.getExtension` 来获取到插件实例,并且可以调用这些 API。 + +如插件 A 在 `activate` 函数中暴露了 `sayHello` 接口 + +```ts +function activate(context) { + return { + sayHello() { + // 返回 sayHello + //... + } + }; +} +``` + +在插件 B 中就可以这样使用: + +```ts +async function activate(context) { + const exta = vscode.extensions.getExtension('{插件 A 的 ID}'); // 如 `opensumi.a` + + await exta.activate(); + exta.exports.sayHello(); // 调用 sayHello +} +``` + +在 OpenSumi 插件的 Node 层,同样可以使用这种方式来进行相互调用,而访问 OpenSumi 插件 Node 层的属性名为 `exetndsExports` ,与 VS Code 有所区分。 + +同样的,在 `extend/node/index.ts` 中的 `activate` 方法返回对象: + +```typescript +function activate(context) { + return { + sayHello() { + // 返回 sayHello + //... + } + }; +} +``` + +在另外一个插件就可以这样使用: + +```ts +async function activate(context) { + const exta = sumi.extensions.getExtension('{插件 A 的 ID}'); // 如 `opensumi.a` + + await exta.activate(); + exta.extendExports.sayHello(); // 调用 sayHello +} +``` diff --git a/docs/extension/overview.en.md b/docs/extension/overview.en.md new file mode 100644 index 00000000..53705acf --- /dev/null +++ b/docs/extension/overview.en.md @@ -0,0 +1,100 @@ +--- +id: overview +title: Extension API Overview +slug: overview +order: 0 +--- + +OpenSumi provides a powerful extension ecosystem that is compatible with the VS Code extension API while also having its own OpenSumi API for further expanding the IDE interface and abilities. + +The structure diagram of the extension capabilities is as follows: + +![Extension Features](https://img.alicdn.com/imgextra/i2/O1CN01xpzgfe24PvNA26s4q_!!6000000007384-2-tps-1371-940.png) + +## Developing VS Code Extensions + +In extension development, you can follow the development model of VS Code, complete your extension development in VS Code, and then import the implemented extension products into IDE based on OpenSumi for use. + +For more details, refer to the [Extension Guides](https://code.visualstudio.com/api/extension-guides/overview) of the VS Code extension document. + +Here are some commonly used examples and documents: + +- [eclipse-theia/vscode-builtin-extensions](https://github.com/eclipse-theia/vscode-builtin-extensions) —— 基于 VS Code 版本打包其内置插件的工程项目 +- [microsoft/vscode-extension-samples](https://github.com/microsoft/vscode-extension-samples) —— VS Code 官方的插件 API 示例仓库 +- [Extension Guides](https://code.visualstudio.com/api/extension-guides/overview) —— VS Code 插件开发向导文档 +- [Your First Extension](https://code.visualstudio.com/api/get-started/your-first-extension) —— 快速开始插件开发 +- [Web Extensions](https://code.visualstudio.com/api/extension-guides/web-extensions) —— 在 OpenSumi 中也支持了这类插件,在纯前端环境有着十分重要的作用 + +## Developing OpenSumi Extensions + +There is a part of OpenSumi that can only run in IDEs built on OpenSumi and provides capabilities including but not limited to: + +- Extending and customizing views through React technology stack +- Toolbar customization +- Electron Webview management +- Layout capability +- Full view custom rendering + +The directory structure of a complete OpenSumi extension is as follows: + +```bash +. +├── .gitignore # git ignore directory +├── README.md # extension description +├── src + ├── extend + ├── browser # extension Browser entry, providing UI customization capability + ├── node # extension Node entry, providing local environment operation capability + ├── worker # extension Worker entry, providing WebWorker environment operation capability +│ └── extension.ts # extension source code (VS Code extension entry) +├── package.json # Extension manifest +├── tsconfig.json +``` + +### Directory Explanation + +The `src/extensions.ts` file is the entry point for the VS Code extension. Refer to the Extension Guides for VS Code extension development. + +The `src/extend` directory contains OpenSumi's own extension system, including Browser/Node/Worker entry points. + +### Entry Point Explanation + +> VS Code extensions will behave consistently with a specific version of VS Code when running in OpenSumi, for example, the current `2.23.0` version is compatible with the VS Code extension API version `1.68.0`. + +The Browser supports UI customization through `React` components in exposed slots. If your extension needs to register UI components in the interface, you can write them in the Browser. + +The Node supports pure Node environment operations. The Node extension has the same API as the VS Code extension and can also call OpenSumi's own extension API. If your extension needs to call native Node.js APIs or run some local tasks, you can write them in the Node. + +The Worker has the ability to run in a WebWorker environment. If your extension contains tasks with large amounts of calculations that do not require local capabilities, you can write them in the Worker. + +**Whether it's a VS Code extension or `Browser/Node/Worker`, all three are optional. In other words, if you only need native VS Code extension capabilities, you can ignore the extend directory. Similarly, if you only need the capabilities of one of OpenSumi's extensions, you can ignore the other and only need to modify a small amount of configuration.** + +## Getting Started + +Refer to the [Quick Start](<(./quick-start)>) document to quickly set up a extension development environment using OpenSumi CLI locally. + +## Extension Examples + +In addition to the [VS Code Extension Samples](https://github.com/microsoft/vscode-extension-samples) mentioned above, OpenSumi also has its [OpenSumi Extension Samples](https://github.com/opensumi/opensumi-extension-samples), which includes some common extension sample code. + +- Toolbar Sample +- i18n Sample +- Gulp compile Sample +- Gulp +- Custom webpack compile Sample +- Configuration Sample +- Upload OSS Sample +- Plain Webview Sample +- Git Operation Sample +- Command Sample? + +## Extension Marketplace + +Currently, OpenSumi supports two types of plugin marketplaces as shown below: + +![Extension Marketplace](https://img.alicdn.com/imgextra/i2/O1CN01Kq3jZf25zTjbBJWzR_!!6000000007597-2-tps-1906-732.png) + +- [OpenTRS](https://marketplace.opentrs.cn/square) —— A public extension marketplace service provided by Ant Group. +- [OpenVSX](https://open-vsx.org/) —— A public extension marketplace service provided by the Eclipse Foundation (with open source code). + +You can freely switch between sources according to your usage scenario, see the documentation for [Custom Extension Marketplace](../integrate/universal-integrate-case/custom-marketplace-entrypoint). diff --git a/docs/extension/overview.zh.md b/docs/extension/overview.zh.md new file mode 100644 index 00000000..fff48cc5 --- /dev/null +++ b/docs/extension/overview.zh.md @@ -0,0 +1,98 @@ +--- +id: overview +title: 概览 +slug: overview +order: 0 +--- + +在 OpenSumi 中,我们提供了一个强大的插件生态系统,在兼容 [VS Code 插件 API](https://code.visualstudio.com/api) 的同时,我们也有着自己的 OpenSumi API 用于进一步拓展 IDE 界面及能力。 + +插件能力实现结构图如下: + +![Extension Features](https://img.alicdn.com/imgextra/i2/O1CN01xpzgfe24PvNA26s4q_!!6000000007384-2-tps-1371-940.png) + +## 开发 VS Code 插件 + +在插件开发中,你可以遵循 VS Code 的开发模式,在 VS Code 内完成你的插件开发后,将实现的插件产物引入到基于 OpenSumi 搭建的 IDE 中使用,详细可参考 VS Code 插件文档 [Extension Guides](https://code.visualstudio.com/api/extension-guides/overview)。 + +下面是一些常用的示例及文档: + +- [eclipse-theia/vscode-builtin-extensions](https://github.com/eclipse-theia/vscode-builtin-extensions) —— 基于 VS Code 版本打包其内置插件的工程项目 +- [microsoft/vscode-extension-samples](https://github.com/microsoft/vscode-extension-samples) —— VS Code 官方的插件 API 示例仓库 +- [Extension Guides](https://code.visualstudio.com/api/extension-guides/overview) —— VS Code 插件开发向导文档 +- [Your First Extension](https://code.visualstudio.com/api/get-started/your-first-extension) —— 快速开始插件开发 +- [Web Extensions](https://code.visualstudio.com/api/extension-guides/web-extensions) —— 在 OpenSumi 中也支持了这类插件,在纯前端环境有着十分重要的作用 + +## 开发 OpenSumi 插件 + +OpenSumi 中存在着一部分仅能运行在基于 OpenSumi 开发的 IDE 之中,提供的能力包括但不限于: + +- 通过 React 技术栈进行视图的拓展定制 +- Toolbar 定制 +- Electron Webview 管理 +- 布局能力 +- 全视图的自定义渲染 + +一个完整的 OpenSumi 插件目录结构如下: + +```bash +. +├── .gitignore # git 忽略目录 +├── README.md # 插件说明 +├── src + ├── extend + ├── browser # 插件 Browser 端入口, 提供 UI 定制能力 + ├── node # 插件 Node 端入口,提供本地环境运行能力 + ├── worker # 插件 Worker 端入口,提供 WebWorker 环境运行能力 +│ └── extension.ts # 插件源码 (VS Code 插件入口) +├── package.json # Extension manifest +├── tsconfig.json +``` + +### 目录说明 + +`src/extensions.ts` 为 VS Code 插件入口,关于 VS Code 插件开发请参阅 [Extension Guides](https://code.visualstudio.com/api/extension-guides/overview)。 + +`src/extend` 目录下为 OpenSumi 自有插件体系,包含 `Browser/Node/Worker` 端入口。 + +### 入口说明 + +> VS Code 插件在 OpenSumi 运行时会保持与 VS Code 特定版本一致的行为,例如当前 `2.23.0` 版本兼容 VS Code 的插件 API 版本为 `1.68.0`。 + +Browser 端支持通过 `React` 组件的方式在界面暴露的插槽中定制 UI ,如果你的插件需要在界面注册 UI 组件,可以将其编写在 Browser 端。 + +Node 端支持纯 Node 环境运行时,在 Node 端插件拥有与 VS Code 插件一致的 API,同时还可以调用 OpenSumi 自有的插件 API,如果你的插件需要调用原生 Node.js 的 API 或运行一些本地任务,可以将其编写在 Node 端。 + +Worker 端拥有 WebWorker 环境运行时,如果你的插件包含一些计算量较大的任务,同时不需要本地能力,可以将其编写在 Worker 端。 + +**不论是 VS Code 插件还是 `Browser/Node/Worker` 三端都是可选的,也就是说如果你只需要原生 VS Code 插件能力,则可以忽略 extend 目录。同样如果你只需要 OpenSumi 插件三端之一的能力,也可以忽略其他,仅需要修改少量的配置。** + +## 开始开发 + +参考 [快速开始](./quick-start) 文档,使用 OpenSumi CLI 快速在本地搭建插件开发环境。 + +## 插件示例 + +除了上面提到的 [VS Code Extension Samples](https://github.com/microsoft/vscode-extension-samples),OpenSumi 也有自己的插件示例仓库 [OpenSumi Extension Samples](https://github.com/opensumi/opensumi-extension-samples),包含了一些常见的插件示例代码。 + +- Toolbar Sample +- i18n Sample +- Gulp compile Sample +- Gulp +- Custom webpack compile Sample +- Configuration Sample +- Upload OSS Sample +- Plain Webview Sample +- Git Operation Sample +- Command Sample + +## 插件市场 + +当前 OpenSumi 支持两种插件市场,如下面所示: + +![Extension Marketplace](https://img.alicdn.com/imgextra/i2/O1CN01Kq3jZf25zTjbBJWzR_!!6000000007597-2-tps-1906-732.png) + +- [OpenTRS](https://marketplace.opentrs.cn/square) —— 蚂蚁集团开放的公共插件市场服务 +- [OpenVSX](https://open-vsx.org/) —— Eclipse 基金会开放的公共插件市场服务(源码开源) + +可以根据使用场景自由进行源的切换,见文档 [自定义插件市场源](../integrate/universal-integrate-case/custom-marketplace-entrypoint)。 diff --git a/docs/extension/quick-start.en.md b/docs/extension/quick-start.en.md new file mode 100644 index 00000000..9b621cf6 --- /dev/null +++ b/docs/extension/quick-start.en.md @@ -0,0 +1,214 @@ +--- +id: quick-start +title: Quick Start +slug: quick-start +order: 1 +--- + +OpenSumi allows integration in two ways: Web and Electron. The extension system and its capabilities have a consistent performance on both platforms. + +When developing a extension, you can quickly start the extension development environment locally using [@opensumi/cli](https://www.npmjs.com/package/@opensumi/cli). Install it by running: + +```bash +$ npm install @opensumi/cli -g +``` + +## Initialize the extension template + +run `sumi init` and enter the extension `name`, `publisher`, `displayName`, and `description` as prompted. + +![sumi-init](https://img.alicdn.com/imgextra/i3/O1CN01A9Ic8J1nGRi2E8aOr_!!6000000005062-2-tps-838-438.png) + +## Running extension + +Install the dependencies using: + +```bash +$ npm install +``` + +Extensions initialized based on `@opensumi/cli` include basic running and building scripts in `package.json`. It is recommended to run `npm run watch` in the background during the development stage to compile the extension code in real time. + +Run `npm run dev` in the extension directory to start a web version of OpenSumi IDE and load the current extension into it. + +```json +{ + "scripts": { + "compile": "sumi compile", + "watch": "sumi watch", + "dev": "sumi dev -e=$(pwd)" + } +} +``` + +Or run the development command of `@opensumi/cli` directly in the extension directory, `sumi dev` + +```bash +$ sumi watch # Monitor and compile code automatically +$ sumi dev # Start the OpenSumi Web version development environment +``` + +![sumi-dev](https://img.alicdn.com/imgextra/i2/O1CN01M4UZxy1q1jpwR9PtM_!!6000000005436-2-tps-986-334.png) + +Open [http://127.0.0.1:50999](http://127.0.0.1:50999) in the browser to open a web version of OpenSumi IDE. + +## Command usage### Engine Version Control + +In OpenSumi, there are many release versions. Before developing a extension, you need to make sure that the extension API you are using is supported by the corresponding `OpenSumi Engine` version. You can check the current version information through the following command: + +```bash +$ sumi engine ls +``` + +![sumi-engine-ls](https://img.alicdn.com/imgextra/i4/O1CN01egTvGF1nQWQB3JQtO_!!6000000005084-2-tps-532-196.png) + +You can see all `OpenSumi Engine` version information by the following command: + +```bash +$ sumi engine ls-remote +``` + +When switching versions, you only need to switch with the following command: + +```bash +$ sumi engine use {version} +``` + +When encountering abnormal performance of extension functions, updating `OpenSumi Engine` to the latest version for testing is a more effective means of verification. + +### Set compilation success callback + +When running the `sumi watch` command, OpenSumi CLI supports executing a callback after each successful compilation, for example: + +```bash +$ sumi watch --onSuccess 'echo hello world' +``` + +### specify the working directory + +Support specifying working directory when running `sumi dev` command + +```bash +$ sumi dev -w=/path/to/vscode +``` + +This will start OpenSumi IDE with the path passed in as the `workspaceDir` parameter and the current directory as the extension, as shown in the image below: + +![set-workspace](https://img.alicdn.com/imgextra/i4/O1CN010Yu9Be1jgm0jSYwUt_!!6000000004578-2-tps-1200-802.png) + +### Specify the base plugin + +OpenSumi CLI does not have any built-in plug-ins. When your plug-ins rely on some capabilities of other plug-ins, you can soft-link or directly copy these plug-ins to the plug-in directory of OpenSumi CLI. The default plug-in directory is `.sumi-dev in the user's Home directory /extensions`. + +### Specify IDE Server port + +OpenSumi CLI supports specifying the listening port of IDE Server via `-p`, the default is `50999`. + +```bash +$ sumi dev -p=8989 # ... +``` + +## debug + +```bash +# Run in the extension directory +$ sumi dev --debug # Start OpenSumi IDE debug mode + +# or specify the extension directory +$ sumi dev --debug -e=/path/to/ext1,/path/to/ext2 +``` + +### Use VS Code / OpenSumi IDE for breakpoint debugging + +The Extension Host Process is a Node.js process, and the extension code can be debugged by configuring `launch.json` in VS Code. + +```json +// A launch configuration that compiles the extension and then opens it inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "attach", // Attach mode + "name": "Attach to Extension Host", + "port": 9889, // extension process port, not modifiable + "skipFiles": ["/**"], + "sourceMaps": true, // Turn on SourceMap for easy source mapping + "outFiles": ["${workspaceFolder}/out/*/.js"] // Specify the extension code output directory + } +} + +``` + +Select Attach to Extension Host in the VS Code debug panel to use VS Code for breakpoint debugging + +![debug](https://img.alicdn.com/imgextra/i3/O1CN0118sSJb1KYCCXcZrIS_!!6000000001175-2-tps-1200-683.png) + +The principle of debugging on the local client developed based on OpenSumi is also the same, just place the configuration file under `.sumi/launch.json`. + +**If you need to perform breakpoint debugging in typescript source code, you need to enable Sourcemap when compiling** + +### Specify the operating environment + +Currently, the desktop (Electron) version of the IDE based on the OpenSumi framework is supported as the extension runtime environment. + +run in terminal + +```bash +$ sumi dev -e=/path/to/ext1,/path/to/ext2 --execute=/path/to/IDE +``` + +The `--execute` parameter indicates the path of the desktop IDE executable file, for example: + +```bash +#Windows +$ sumi dev -e=/path/to/ext --execute=/C:\Program Files\OpenSumi\OpenSumi.exe --debug + +# MacOS +$ sumi dev -e=/path/to/ext --execute=/Applications/OpenSumi.app/Contents/MacOS/OpenSumi --debug +``` + +> When using the desktop version of the IDE, since the desktop version of the IDE may include pre-processes such as creating and selecting projects, it is not possible to specify `workspaceDir` through parameters. + +## Package Extension + +Use the `sumi package` command to package your extension. + +![sumi-package](https://img.alicdn.com/imgextra/i1/O1CN012hnLYD1p6wiwKXrHk_!!6000000005312-2-tps-886-618.png) + +```bash +$ sumi package +``` + +Please make sure that the extension `package.json` contains a `scripts` script named `prepublish`. + +```json +{ + "scripts": { + "prepublishOnly": "/* your compile script */" + } +} +``` + +This will first run `npm list` to analyze dependencies. If you need to package the node_modules of the extension project, it is recommended to use `npm install --production` to install dependencies, which will only install the modules necessary for runtime. + +### Exclude directories + +When running the `sumi package` command, it supports specifying excluded files or directories. Create a new file named `.vscodeignore` under the extension project. The format is similar to `.gitignore`. It supports glob pattern matching directories and will be excluded when packaging. these files: + +```bash +#.vscodeignore +node_modules/ +src/ +yarn-error.log +#... +``` + +Or pass `--ignoreFile` parameter to specify ignore file + +```bash +$ sumi package --ignoreFile=/path/to/.ignore +``` diff --git a/docs/extension/quick-start.zh.md b/docs/extension/quick-start.zh.md new file mode 100644 index 00000000..10fda5ee --- /dev/null +++ b/docs/extension/quick-start.zh.md @@ -0,0 +1,216 @@ +--- +id: quick-start +title: 快速开始 +slug: quick-start +order: 1 +--- + +OpenSumi 支持 `Web/Electron` 两种方式集成,插件系统及其能力在两个平台下具有一致的表现。 + +开发插件时,你可以使用 [@opensumi/cli](https://www.npmjs.com/package/@opensumi/cli) 快速在本地启动插件开发环境。 + +```bash +$ npm install @opensumi/cli -g +``` + +## 初始化插件模板 + +运行 `sumi init` 根据提示输入插件 `name` 、 `publisher` ,以及 `displayName` 和 `description`。 + +![sumi-init](https://img.alicdn.com/imgextra/i3/O1CN01A9Ic8J1nGRi2E8aOr_!!6000000005062-2-tps-838-438.png) + +## 运行插件 + +首先需要安装依赖。 + +```bash +$ npm install +``` + +基于 `@opensumi/cli` 初始化的插件,在 `package.json` 中包含了基础的运行及构建脚本,建议开发阶段后台运行 `npm run watch` 实时编译插件代码。 + +在插件目录下运行 `npm run dev` 即可启动一个 Web 版本的 OpenSumi IDE,并将当前插件加载进来。 + +```json +{ + "scripts": { + "compile": "sumi compile", + "watch": "sumi watch", + "dev": "sumi dev -e=$(pwd)" + } +} +``` + +或者直接在插件目录下运行 `@opensumi/cli` 的开发命令, `sumi dev` + +```bash +$ sumi watch # 监听并自动编译代码 +$ sumi dev # 启动 OpenSumi Web 版本开发环境 +``` + +![sumi-dev](https://img.alicdn.com/imgextra/i2/O1CN01M4UZxy1q1jpwR9PtM_!!6000000005436-2-tps-986-334.png) + +浏览器打开 [http://127.0.0.1:50999](http://127.0.0.1:50999) 即可打开一个 Web 版的 OpenSumi IDE。 + +## 命令使用 + +### Engine 版本控制 + +在 OpenSumi 中,存在许多的发行版本,在开发插件前,你需要确保你所使用的的插件 API 在对应的 `OpenSumi Engine` 版本中支持,可以通过下面的命令查看当前使用的版本信息: + +```bash +$ sumi engine ls +``` + +![sumi-engine-ls](https://img.alicdn.com/imgextra/i4/O1CN01egTvGF1nQWQB3JQtO_!!6000000005084-2-tps-532-196.png) + +通过下面的命令你可以看到所有的 `OpenSumi Engine` 版本信息: + +```bash +$ sumi engine ls-remote +``` + +在切换版本时,只需要通过下面的命令进行切换: + +```bash +$ sumi engine use {版本} +``` + +在遇到插件功能表现异常时,及时更新 `OpenSumi Engine` 到最新版本进行测试是比较有效的验证手段。 + +### 设置编译成功回调 + +在运行 `sumi watch` 命令时,OpenSumi CLI 支持在每一次编译成功后执行回调,例如: + +```bash +$ sumi watch --onSuccess 'echo hello world' +``` + +### 指定工作目录 + +在运行 `sumi dev` 命令时,支持指定工作目录 + +```bash +$ sumi dev -w=/path/to/vscode +``` + +这会将传入的路径作为 `workspaceDir` 参数,并将当前目录作为插件启动 OpenSumi IDE,如下图所示: + +![set-workspace](https://img.alicdn.com/imgextra/i4/O1CN010Yu9Be1jgm0jSYwUt_!!6000000004578-2-tps-1200-802.png) + +### 指定基础插件 + +OpenSumi CLI 不会内置任何插件,当你的插件依赖其他插件的一些能力时,可以将这些插件软链接或者直接复制到 OpenSumi CLI 的插件目录,默认插件目录为用户 Home 目录下的 `.sumi-dev/extensions`。 + +### 指定 IDE Server 端口 + +OpenSumi CLI 支持通过 `-p` 指定 IDE Server 监听的端口,默认为 `50999`。 + +```bash +$ sumi dev -p=8989 # ... +``` + +## 调试 + +```bash +# 在插件目录下运行 +$ sumi dev --debug # 启动 OpenSumi IDE 调试模式 + +# 或指定插件目录 +$ sumi dev --debug -e=/path/to/ext1,/path/to/ext2 +``` + +### 使用 VS Code / OpenSumi IDE 进行断点调试 + +插件进程本质为一个 Node.js 进程,在 VS Code 中配置 `launch.json` 即可调试插件代码。 + +```json +// A launch configuration that compiles the extension and then opens it inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "attach", // Attach 模式 + "name": "Attach to Extension Host", + "port": 9889, // 插件进程端口,不可修改 + "skipFiles": ["/**"], + "sourceMaps": true, // 开启 SourceMap,便于源码映射 + "outFiles": ["${workspaceFolder}/out/*/.js"] // 指定插件代码输出目录 + } +} + +``` + +在 VS Code 调试面板中选择 Attach to Extension Host,即可使用 VS Code 进行断点调试 + +![debug](https://img.alicdn.com/imgextra/i3/O1CN0118sSJb1KYCCXcZrIS_!!6000000001175-2-tps-1200-683.png) + +在基于 OpenSumi 开发的本地客户端上调试原理也是一致的,将配置文件放置在 `.sumi/launch.json` 下即可。 + +**如需在 typescript 源码中进行断点调试,需要编译时开启 Sourcemap** + +### 指定运行环境 + +目前支持基于 OpenSumi 框架的桌面(Electron) 版 IDE 作为插件运行环境。 + +在终端运行 + +```bash +$ sumi dev -e=/path/to/ext1,/path/to/ext2 --execute=/path/to/IDE +``` + +`--execute` 参数表示桌面 IDE 可执行文件路径,例如: + +```bash +# Windows +$ sumi dev -e=/path/to/ext --execute=/C:\Program Files\OpenSumi\OpenSumi.exe --debug + +# MacOS +$ sumi dev -e=/path/to/ext --execute=/Applications/OpenSumi.app/Contents/MacOS/OpenSumi --debug +``` + +> 使用桌面版 IDE 时,由于桌面版 IDE 可能包含创建、选择项目等前置流程,故无法通过参数指定 `workspaceDir`。 + +## 打包插件 + +使用 `sumi package` 命令将你的插件打包。 + +![sumi-package](https://img.alicdn.com/imgextra/i1/O1CN012hnLYD1p6wiwKXrHk_!!6000000005312-2-tps-886-618.png) + +```bash +$ sumi package +``` + +请确保插件 `package.json` 中包含名为 `prepublish` 的 `scripts` 脚本。 + +```json +{ + "scripts": { + "prepublishOnly": "/* your compile script */" + } +} +``` + +这会先运行 `npm list` 分析依赖,如果你需要将插件项目的 node_modules 一并打包进去,建议使用 `npm install --production` 安装依赖,这样会仅安装运行时必要的模块。 + +### 排除目录 + +运行 `sumi package` 命令时,支持指定排除的文件或目录,在插件项目下新建名为 `.vscodeignore` 的文件,格式类似 `.gitignore` ,支持 glob 模式匹配目录,在打包时将会排除掉这些文件: + +```bash +# .vscodeignore +node_modules/ +src/ +yarn-error.log +# ... +``` + +或传入 `--ignoreFile` 参数指定 ignore 文件 + +```bash +$ sumi package --ignoreFile=/path/to/.ignore +``` diff --git a/docs/integrate/overview.en.md b/docs/integrate/overview.en.md index 10ce2f55..81788838 100644 --- a/docs/integrate/overview.en.md +++ b/docs/integrate/overview.en.md @@ -1,6 +1,6 @@ --- id: overview -title: OverView +title: Introduction slug: overview order: 0 --- @@ -24,7 +24,7 @@ There are three core processes within OpenSumi: - Extension process(Extension Process) - Backend process (Node Process) - Frontend process(Browser Process) - + To ensure that extension problems do not affect IDE performance, OpenSumi uses a similar solution in terms of extension capabilities: similar to `VS Code`, the extension is enabled by a separate extension process, and the extension process communicates with the frontend process by the backend process. ![OpenSumi Overall Structure](https://img.alicdn.com/imgextra/i2/O1CN01qNPXUm1wbMFgrPieN_!!6000000006326-2-tps-1332-1180.png) @@ -104,10 +104,10 @@ export class ModuleDemoModule extends NodeModule { Extension, is a type of program files supported by OpenSumi framework. By installing extension files on a specific location, the interface and functions of IDE can be re-developed. It is designed to be compatible with the [VSCode Extension API](https://code.visualstudio.com/api), that is, IDE products developed by OpenSumi are naturally compatible with `VSCode` plug-in system. -> We will roll out support for OpenSumi extension development-related R&D process links in the future, so stay tuned. - ![Extension](https://img.alicdn.com/imgextra/i3/O1CN01gHphRQ26x18NyYeTz_!!6000000007727-2-tps-1156-800.png) +See [Extension API Overview](../extension/overview); + ### How to Release Due to protocol issues, OpenSumi cannot directly use the VS Code extension market source. By default OpenSumi currently integrates with [Eclipse Open VSX](https://www.eclipse.org/community/eclipse_newsletter/2020/march/1.php) service developed by Eclipse company. Developers can use directly the service or build their own extension Marketplace based on [Eclipse Open VSX](https://www.eclipse.org/community/eclipse_newsletter/2020/march/1.php). Later on, we will also build our own extension marketplace to develop free extension hosting services for more developers. diff --git a/docs/integrate/overview.zh.md b/docs/integrate/overview.zh.md index d667d8e1..93a9291f 100644 --- a/docs/integrate/overview.zh.md +++ b/docs/integrate/overview.zh.md @@ -1,6 +1,6 @@ --- id: overview -title: 概览 +title: 框架介绍 slug: overview order: 0 --- @@ -102,10 +102,10 @@ export class ModuleDemoModule extends NodeModule { 插件, 也可称为 Extension,是指当前 OpenSumi 框架下支持的,通过在特定位置安装插件文件,从而对 IDE 的界面、功能进行二次插件的一类程序文件,设计上兼容 `VSCode` 中的 [VSCode Extension API](https://code.visualstudio.com/api),即对于使用 OpenSumi 进行开发的 IDE 产品天然兼容 `VSCode` 的插件体系。 -> 针对 OpenSumi 插件开发相关的研发流程链路支持将会在后续逐步推出,敬请期待。 - ![插件](https://img.alicdn.com/imgextra/i3/O1CN01gHphRQ26x18NyYeTz_!!6000000007727-2-tps-1156-800.png) +插件开发文档见:[Extension API 概览](../extension/overview); + ### 如何发布 由于协议问题,OpenSumi 无法直接使用 VS Code 插件市场源,当前 OpenSumi 默认集成了 Eclipse 公司研发的 [Eclipse Open VSX](https://www.eclipse.org/community/eclipse_newsletter/2020/march/1.php) 服务,开发者可以直接使用,也可以基于 [Eclipse Open VSX](https://www.eclipse.org/community/eclipse_newsletter/2020/march/1.php) 建设自己的插件市场, 后续,我们也将建设自己的插件市场开发免费的插件托管服务给更多开发者使用。 diff --git a/gatsby-config.js b/gatsby-config.js index a40bd02a..9edd72ae 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -43,6 +43,13 @@ module.exports = { zh: '开发文档' } }, + { + slug: 'docs/extension/overview', + title: { + en: 'Extension API', + zh: '插件研发' + } + }, { slug: 'https://marketplace.opentrs.cn/square', title: { @@ -107,6 +114,14 @@ module.exports = { en: 'Sample' }, order: 6 + }, + { + slug: 'extension/opensumi-api', + title: { + zh: 'OpenSumi 插件开发', + en: 'OpenSumi Extension API' + }, + order: 2 } ], showDingTalkQRCode: true, diff --git a/site/pages/index.zh.tsx b/site/pages/index.zh.tsx index 14e9a39e..a922a089 100644 --- a/site/pages/index.zh.tsx +++ b/site/pages/index.zh.tsx @@ -116,7 +116,7 @@ const IndexPage = () => { ), link: 'https://opendocs.alipay.com/mini/ide/overview', image: - 'https://img.alicdn.com/imgextra/i1/O1CN01BYqn4B219wcGGXHBS_!!6000000006943-2-tps-775-667.png' + 'https://img.alicdn.com/imgextra/i4/O1CN012vU3ct201s6upzFwb_!!6000000006790-2-tps-775-667.png' }, { logo: