@opensumi/ide-connection 3.3.4-next-1727344885.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
# 通信模块
|
|
1
|
+
# 通信模块
|
|
2
2
|
|
|
3
3
|
基于 sumi rpc 完成多端远程调用场景,兼容 lsp 等通信方式
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### 后端服务: backService
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
1. 框架中服务分为运行在浏览器环境的 前端服务(frontService) 与运行在 node 环境的 后端服务(backService),服务在两端的实现方式是一致的
|
|
10
|
-
2. 目前在 `tools/dev-tool` 中的启动逻辑中完成了服务的注册和获取逻辑,在具体功能模块中无需关心具体的通信注册获取逻辑
|
|
11
|
-
|
|
12
|
-
**后端服务(backService)** 后端服务(backService) 即在 Web Server 暴露的能力,类似 web 应用框架中 controller 提供的请求响应逻辑
|
|
7
|
+
backService 即在 Web Server 暴露的能力,类似 web 应用框架中 controller 提供的请求响应逻辑
|
|
13
8
|
|
|
14
9
|
1. 注册服务
|
|
15
10
|
|
|
16
11
|
`packages/file-service/src/node/index.ts`
|
|
17
12
|
|
|
18
|
-
```
|
|
13
|
+
```ts
|
|
19
14
|
import { FileSystemNodeOptions, FileService } from './file-service';
|
|
20
15
|
import { servicePath } from '../common/index';
|
|
21
16
|
|
|
@@ -37,7 +32,7 @@ export class FileServiceModule extends NodeModule {
|
|
|
37
32
|
|
|
38
33
|
`packages/file-tree/src/browser/index.ts`
|
|
39
34
|
|
|
40
|
-
```
|
|
35
|
+
```ts
|
|
41
36
|
import { servicePath as FileServicePath } from '@opensumi/ide-file-service';
|
|
42
37
|
|
|
43
38
|
@Injectable()
|
|
@@ -55,12 +50,11 @@ export class FileTreeModule extends BrowserModule {
|
|
|
55
50
|
|
|
56
51
|
`packages/file-tree/src/browser/file-tree.service.ts`
|
|
57
52
|
|
|
58
|
-
```
|
|
59
|
-
import {servicePath as FileServicePath} from '@opensumi/ide-file-service';
|
|
53
|
+
```ts
|
|
54
|
+
import { servicePath as FileServicePath } from '@opensumi/ide-file-service';
|
|
60
55
|
|
|
61
56
|
@Injectable()
|
|
62
57
|
export default class FileTreeService extends Disposable {
|
|
63
|
-
|
|
64
58
|
@observable.shallow
|
|
65
59
|
files: CloudFile[] = [];
|
|
66
60
|
|
|
@@ -75,8 +69,8 @@ export default class FileTreeService extends Disposable {
|
|
|
75
69
|
|
|
76
70
|
this.getFiles();
|
|
77
71
|
}
|
|
78
|
-
|
|
79
|
-
const {content} = await this.fileService.resolveContent('{file_path}');
|
|
72
|
+
createFile = async () => {
|
|
73
|
+
const { content } = await this.fileService.resolveContent('{file_path}');
|
|
80
74
|
const file = await this.fileAPI.createFile({
|
|
81
75
|
name: 'name' + Date.now() + '\n' + content,
|
|
82
76
|
path: 'path' + Date.now(),
|
|
@@ -90,13 +84,13 @@ export default class FileTreeService extends Disposable {
|
|
|
90
84
|
} else {
|
|
91
85
|
this.files = [file];
|
|
92
86
|
}
|
|
93
|
-
}
|
|
87
|
+
};
|
|
94
88
|
}
|
|
95
89
|
```
|
|
96
90
|
|
|
97
91
|
在 file-tree.service.ts 中通过 `servicePath` 进行注入,并直接调用在服务类上的方法
|
|
98
92
|
|
|
99
|
-
```
|
|
93
|
+
```ts
|
|
100
94
|
constructor(@Inject(FileServicePath) protected readonly fileService) {
|
|
101
95
|
super();
|
|
102
96
|
|
|
@@ -106,97 +100,34 @@ constructor(@Inject(FileServicePath) protected readonly fileService) {
|
|
|
106
100
|
|
|
107
101
|
方法调用会转换成一个远程调用进行响应,返回结果
|
|
108
102
|
|
|
109
|
-
```
|
|
103
|
+
```ts
|
|
110
104
|
const { content } = await this.fileService.resolveContent('{file_path}');
|
|
111
105
|
```
|
|
112
106
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
1. 注册服务
|
|
107
|
+
### 后端服务: remoteService
|
|
116
108
|
|
|
117
|
-
|
|
109
|
+
remoteService 提供了一种更简单,显式的 API 声明,我们将上面的 fileService 使用 remoteService 重写一遍:
|
|
118
110
|
|
|
119
|
-
|
|
120
|
-
@Injectable()
|
|
121
|
-
export class FileTreeModule extends BrowserModule {
|
|
122
|
-
providers: Provider[] = [createFileTreeAPIProvider(FileTreeAPIImpl)];
|
|
123
|
-
backServices = [
|
|
124
|
-
{
|
|
125
|
-
servicePath: FileServicePath,
|
|
126
|
-
},
|
|
127
|
-
];
|
|
128
|
-
frontServices = [
|
|
129
|
-
{
|
|
130
|
-
servicePath: FileTreeServicePath,
|
|
131
|
-
token: FileTreeService,
|
|
132
|
-
},
|
|
133
|
-
];
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
与后端服务注册类似,例如在 file-tree 模块中声明 `frontServices` 字段,传入对应的服务地址 `servicePath` 和对应服务的注入 `token`
|
|
138
|
-
|
|
139
|
-
2. 服务使用
|
|
111
|
+
1. 注册服务
|
|
140
112
|
|
|
141
113
|
`packages/file-service/src/node/index.ts`
|
|
142
114
|
|
|
143
|
-
```
|
|
144
|
-
import {
|
|
115
|
+
```ts
|
|
116
|
+
import { FileSystemNodeOptions, FileService } from './file-service';
|
|
145
117
|
|
|
146
|
-
@Injectable()
|
|
147
118
|
export class FileServiceModule extends NodeModule {
|
|
148
119
|
providers = [{ token: 'FileServiceOptions', useValue: FileSystemNodeOptions.DEFAULT }];
|
|
149
|
-
|
|
150
|
-
backServices = [
|
|
151
|
-
{
|
|
152
|
-
servicePath,
|
|
153
|
-
token: FileService,
|
|
154
|
-
},
|
|
155
|
-
];
|
|
156
|
-
frontServices = [
|
|
157
|
-
{
|
|
158
|
-
servicePath: FileTreeServicePath,
|
|
159
|
-
},
|
|
160
|
-
];
|
|
120
|
+
remoteServices = [FileService];
|
|
161
121
|
}
|
|
162
122
|
```
|
|
163
123
|
|
|
164
|
-
与使用后端服务一致,在模块定义中声明需要使用的前端服务 `frontServices`,传入前端服务注册时用的 `servicePath` 一致
|
|
165
|
-
|
|
166
124
|
`packages/file-service/src/node/file-service.ts`
|
|
167
125
|
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
export class FileService implements IFileService {
|
|
171
|
-
|
|
172
|
-
constructor(
|
|
173
|
-
@Inject('FileServiceOptions') protected readonly options: FileSystemNodeOptions,
|
|
174
|
-
@Inject(FileTreeServicePath) protected readonly fileTreeService
|
|
175
|
-
) { }
|
|
176
|
-
|
|
177
|
-
async resolveContent(uri: string, options?: { encoding?: string }): Promise<{ stat: FileStat, content: string }> {
|
|
178
|
-
const fileTree = await this.fileTreeService
|
|
179
|
-
fileTree.fileName(uri.substr(-5))
|
|
180
|
-
|
|
181
|
-
...
|
|
182
|
-
return { stat, content };
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
与使用后端服务使用方式一致,在 file-service.ts 中通过 `servicePath` 进行注入,通过调用注入服务的对应方法
|
|
187
|
-
|
|
188
|
-
```javascript
|
|
189
|
-
constructor(
|
|
190
|
-
@Inject('FileServiceOptions') protected readonly options: FileSystemNodeOptions,
|
|
191
|
-
@Inject(FileTreeServicePath) protected readonly fileTreeService
|
|
192
|
-
) { }
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
方法调用会转换成一个远程调用进行响应,返回结果
|
|
126
|
+
```ts
|
|
127
|
+
import { servicePath } from '../common/index';
|
|
196
128
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
129
|
+
export class FileService extends RemoteService {
|
|
130
|
+
servicePath = servicePath;
|
|
131
|
+
// write your own logic here
|
|
132
|
+
}
|
|
200
133
|
```
|
|
201
|
-
|
|
202
|
-
与后端服务调用区别的是,目前因前端代码后置执行,所以首先需要获取服务 `await this.fileTreeService` 后进行调用
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/rpc-service/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAE3B,8BAAsB,UAAU,CAAC,CAAC,GAAG,GAAG;IACtC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;IAChB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/rpc-service/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAE3B,8BAAsB,UAAU,CAAC,CAAC,GAAG,GAAG;IACtC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;IAChB,IAAI,MAAM,IAAI,CAAC,GAAG,SAAS,CAE1B;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/rpc-service/index.ts"],"names":[],"mappings":";;;;AAAA,iDAAuB;AACvB,mDAAyB;AACzB,qDAA2B;AAE3B,MAAsB,UAAU;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/rpc-service/index.ts"],"names":[],"mappings":";;;;AAAA,iDAAuB;AACvB,mDAAyB;AACzB,qDAA2B;AAE3B,MAAsB,UAAU;IAE9B,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACxD,CAAC;CACF;AALD,gCAKC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-connection",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"src"
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@furyjs/fury": "0.5.9-beta",
|
|
21
21
|
"@opensumi/events": "^1.0.0",
|
|
22
|
-
"@opensumi/ide-core-common": "3.
|
|
23
|
-
"@opensumi/ide-utils": "3.
|
|
22
|
+
"@opensumi/ide-core-common": "3.4.0",
|
|
23
|
+
"@opensumi/ide-utils": "3.4.0",
|
|
24
24
|
"@opensumi/reconnecting-websocket": "^4.4.0",
|
|
25
25
|
"@opensumi/vscode-jsonrpc": "^8.0.0-next.2",
|
|
26
26
|
"path-to-regexp": "^6.2.1",
|
|
27
27
|
"ws": "^8.16.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@opensumi/ide-components": "3.
|
|
31
|
-
"@opensumi/ide-dev-tool": "3.
|
|
30
|
+
"@opensumi/ide-components": "3.4.0",
|
|
31
|
+
"@opensumi/ide-dev-tool": "3.4.0",
|
|
32
32
|
"@opensumi/mock-socket": "^9.3.1"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "1596a2b1b547d2b99c880afe14f91f16f76bb9d5"
|
|
35
35
|
}
|