# @opensumi/ide-connection

> 基于 sumi rpc 完成多端远程调用场景，兼容 lsp 等通信方式

Latest version **3.9.0** (published 2025-05-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @opensumi/ide-connection
pnpm add @opensumi/ide-connection
yarn add @opensumi/ide-connection
bun add @opensumi/ide-connection
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.9.0 |
| Published | 2025-05-20 |
| First published | 2021-12-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 499.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3654 |
| Maintainers | ensorrow, jinboker, ricbet, hacke2, lengthmin, erha19, sakuraash, yantze |

## Links

- npm: https://www.npmjs.com/package/@opensumi/ide-connection
- Repository: https://github.com/opensumi/core
- Homepage: https://github.com/opensumi/core#readme
- Issues: https://github.com/opensumi/core/issues
- npm.io page: https://npm.io/package/@opensumi/ide-connection

## Dependencies (8)

- [ws](https://npm.io/package/ws.md) ^8.16.0
- [@furyjs/fury](https://npm.io/package/@furyjs/fury.md) 0.5.9-beta
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^6.2.1
- [@opensumi/events](https://npm.io/package/@opensumi/events.md) ^1.0.0
- [@opensumi/ide-utils](https://npm.io/package/@opensumi/ide-utils.md) 3.9.0
- [@opensumi/vscode-jsonrpc](https://npm.io/package/@opensumi/vscode-jsonrpc.md) ^8.0.0-next.2
- [@opensumi/ide-core-common](https://npm.io/package/@opensumi/ide-core-common.md) 3.9.0
- [@opensumi/reconnecting-websocket](https://npm.io/package/@opensumi/reconnecting-websocket.md) ^4.4.0

## Recent versions

- 3.9.0 (latest) — 2025-05-20
- 3.9.1-next-1790001292.0 (next) — 2026-09-21
- 2.27.3-rc-1715227667.0 (rc) — 2024-05-09
- 3.9.1-next-1789996105.0 — 2026-09-21
- 3.9.1-next-1788263965.0 — 2026-09-01
- 3.9.1-next-1788253557.0 — 2026-09-01
- 3.9.1-next-1788150617.0 — 2026-08-31
- 3.9.1-next-1787646115.0 — 2026-08-25
- 3.9.1-next-1787303337.0 — 2026-08-21
- 3.9.1-next-1787197346.0 — 2026-08-20
- 3.9.1-next-1786069412.0 — 2026-08-07
- 3.9.1-next-1784688644.0 — 2026-07-22
- 3.9.1-next-1784643835.0 — 2026-07-21
- 3.9.1-next-1784623944.0 — 2026-07-21
- 3.9.1-next-1784553929.0 — 2026-07-20
- … 1908 more at https://npm.io/package/@opensumi/ide-connection/versions

## README

# 通信模块

基于 sumi rpc 完成多端远程调用场景，兼容 lsp 等通信方式

### 后端服务: backService

backService 即在 Web Server 暴露的能力，类似 web 应用框架中 controller 提供的请求响应逻辑

1. 注册服务

`packages/file-service/src/node/index.ts`

```ts
import { FileSystemNodeOptions, FileService } from './file-service';
import { servicePath } from '../common/index';

export class FileServiceModule extends NodeModule {
  providers = [{ token: 'FileServiceOptions', useValue: FileSystemNodeOptions.DEFAULT }];

  backServices = [
    {
      servicePath,
      token: FileService,
    },
  ];
}
```

例如在 file-service 模块中，通过定义 `backServices` 数组，传递模块提供的后端服务，`servicePath` 为前端模块引用的服务地址，以及对应服务的注入 `token`

2. 服务调用

`packages/file-tree/src/browser/index.ts`

```ts
import { servicePath as FileServicePath } from '@opensumi/ide-file-service';

@Injectable()
export class FileTreeModule extends BrowserModule {
  providers: Provider[] = [createFileTreeAPIProvider(FileTreeAPIImpl)];
  backServices = [
    {
      servicePath: FileServicePath,
    },
  ];
}
```

例如在 file-tree 模块中，首先在模块入口位置声明需要用到的 `backServices`，传入引用的服务 `servicePath`，与服务注册时的 `servicePath` 一致

`packages/file-tree/src/browser/file-tree.service.ts`

```ts
import { servicePath as FileServicePath } from '@opensumi/ide-file-service';

@Injectable()
export default class FileTreeService extends Disposable {
  @observable.shallow
  files: CloudFile[] = [];

  @Autowired()
  private fileAPI: FileTreeAPI;

  @Autowired(CommandService)
  private commandService: CommandService;

  constructor(@Inject(FileServicePath) protected readonly fileService) {
    super();

    this.getFiles();
  }
  createFile = async () => {
    const { content } = await this.fileService.resolveContent('{file_path}');
    const file = await this.fileAPI.createFile({
      name: 'name' + Date.now() + '\n' + content,
      path: 'path' + Date.now(),
    });

    // 只会执行注册在 Module 里声明的 Contribution
    this.commandService.executeCommand('file.tree.console');

    if (this.files) {
      this.files.push(file);
    } else {
      this.files = [file];
    }
  };
}
```

在 file-tree.service.ts 中通过 `servicePath` 进行注入，并直接调用在服务类上的方法

```ts
constructor(@Inject(FileServicePath) protected readonly fileService) {
    super();

    this.getFiles();
  }
```

方法调用会转换成一个远程调用进行响应，返回结果

```ts
const { content } = await this.fileService.resolveContent('{file_path}');
```

### 后端服务: remoteService

remoteService 提供了一种更简单，显式的 API 声明，我们将上面的 fileService 使用 remoteService 重写一遍：

1. 注册服务

`packages/file-service/src/node/index.ts`

```ts
import { FileSystemNodeOptions, FileService } from './file-service';

export class FileServiceModule extends NodeModule {
  providers = [{ token: 'FileServiceOptions', useValue: FileSystemNodeOptions.DEFAULT }];
  remoteServices = [FileService];
}
```

`packages/file-service/src/node/file-service.ts`

```ts
import { servicePath } from '../common/index';

export class FileService extends RemoteService {
  servicePath = servicePath;
  // write your own logic here
}
```

---
_Source: https://npm.io/package/@opensumi/ide-connection · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
