Skip to content

Commit bb3a863

Browse files
author
winjo
committed
feat: 增加 ts 跨库索引
1 parent 7eb42a3 commit bb3a863

5 files changed

Lines changed: 130 additions & 137 deletions

File tree

packages/alex/src/integration/editor/index.tsx

Lines changed: 83 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,86 +4,112 @@ import { IAppInstance, EditorRenderer } from '../../editor';
44
import * as Alex from '../../editor';
55
import '../startup/languages';
66

7-
import Button from 'antd/lib/button';
8-
import 'antd/lib/button/style/index.css';
7+
import 'antd/dist/antd.css';
98
import Select from 'antd/lib/select';
10-
import 'antd/lib/select/style/index.css';
11-
import Spin from 'antd/lib/spin';
12-
import 'antd/lib/spin/style/index.css';
9+
import Cascader from 'antd/lib/cascader';
1310
import './style.less';
1411

1512
(window as any).alex = Alex;
1613

17-
const owner = 'kaitian';
18-
const name = 'ide-framework';
19-
const project = encodeURIComponent(`${owner}/${name}`);
14+
const fileOptions = [
15+
{
16+
value: 'chaxuan.wh/qiankun-mirror',
17+
label: 'chaxuan.wh/qiankun-mirror',
18+
children: [
19+
{
20+
value: 'master',
21+
label: 'master',
22+
children: [
23+
{
24+
value: 'src/globalState.ts',
25+
label: 'src/globalState.ts',
26+
},
27+
],
28+
},
29+
],
30+
},
31+
{
32+
value: 'wealth_release/finstrategy',
33+
label: 'wealth_release/finstrategy',
34+
children: [
35+
{
36+
value: 'f577528518c7c0279f8cdf3de59ae24a80a16607',
37+
label: 'f577528518c7c0279f8cdf3de59ae24a80a16607',
38+
children: [
39+
{
40+
value:
41+
'app/biz/service-impl/src/main/java/com/alipay/finstrategy/biz/service/impl/portfolio/msg/TradeMessageListener.java',
42+
label:
43+
'app/biz/service-impl/src/main/java/com/alipay/finstrategy/biz/service/impl/portfolio/msg/TradeMessageListener.java',
44+
},
45+
],
46+
},
47+
],
48+
},
49+
{
50+
value: 'kaitian/ide-framework',
51+
label: 'kaitian/ide-framework',
52+
children: [
53+
{
54+
value: 'develop',
55+
label: 'develop',
56+
children: [
57+
{
58+
value: 'packages/addons/src/browser/file-drop.service.ts',
59+
label: 'packages/addons/src/browser/file-drop.service.ts',
60+
},
61+
{
62+
value: 'packages/addons/src/common/index.ts',
63+
label: 'packages/addons/src/common/index.ts',
64+
},
65+
{
66+
value: 'OWNERS',
67+
label: 'OWNERS',
68+
},
69+
],
70+
},
71+
],
72+
},
73+
];
2074

2175
const App = () => {
22-
const [key, setKey] = useState(0);
76+
const [project, setProject] = useState('');
2377
const [ref, setRef] = useState('');
2478
const [filepath, setFilePath] = useState('');
2579
const [encoding, setEncoding] = useState<'utf8' | 'gbk' | undefined>('utf8');
2680
const [lineNumber, setLineNumber] = useState<number | [number, number] | undefined>();
2781

28-
const setContent = () => {
29-
setRef('develop');
30-
setFilePath('packages/addons/src/browser/file-drop.service.ts');
31-
setLineNumber([30, 32]);
32-
};
33-
3482
const readFile = async (filepath: string) => {
3583
const res = await fetch(
36-
`/code-service/api/v3/projects/${project}/repository/blobs/${encodeURIComponent(
37-
ref
38-
)}?filepath=${filepath}`
84+
`/code-service/api/v3/projects/${encodeURIComponent(
85+
project
86+
)}/repository/blobs/${encodeURIComponent(ref)}?filepath=${filepath}`
3987
);
4088
if (res.status >= 200 && res.status < 300) {
4189
return res.arrayBuffer();
4290
}
4391
throw new Error(`${res.status} - ${res.statusText}`);
4492
};
4593

94+
const onFileChange = ([project, ref, filepath]) => {
95+
setProject(project);
96+
setRef(ref);
97+
setFilePath(filepath);
98+
};
99+
console.log(123);
100+
46101
return (
47102
<div style={{ padding: 8 }}>
48103
<div style={{ display: 'flex', marginBottom: 8 }}>
49-
<Select
50-
value={ref || undefined}
51-
onChange={setRef}
104+
<Cascader
105+
style={{ width: '100%' }}
52106
size="small"
53-
style={{ width: 400, marginRight: 8 }}
54-
placeholder="选择分支"
55-
>
56-
{['develop'].map((path) => (
57-
<Select.Option key={path} value={path}>
58-
{path}
59-
</Select.Option>
60-
))}
61-
</Select>
62-
<Select
63-
value={filepath || undefined}
64-
onChange={setFilePath}
65-
size="small"
66-
style={{ width: 600, marginRight: 8 }}
67-
placeholder="选择文件"
68-
>
69-
{[
70-
'packages/addons/src/browser/file-drop.service.ts',
71-
'packages/addons/src/common/index.ts',
72-
'OWNERS',
73-
].map((path) => (
74-
<Select.Option key={path} value={path}>
75-
{path}
76-
</Select.Option>
77-
))}
78-
</Select>
107+
options={fileOptions}
108+
onChange={onFileChange}
109+
placeholder="Please select"
110+
/>
79111
</div>
80112
<div style={{ display: 'flex', marginBottom: 8 }}>
81-
<Button size="small" onClick={() => setKey((k) => k + 1)} style={{ marginRight: 8 }}>
82-
重置
83-
</Button>
84-
<Button size="small" onClick={() => setContent()} style={{ marginRight: 8 }}>
85-
一键设置文件
86-
</Button>
87113
<Select
88114
value={encoding}
89115
onChange={setEncoding}
@@ -114,7 +140,7 @@ const App = () => {
114140
<div style={{ display: 'flex' }}>
115141
<div style={{ width: '50%', minHeight: 300 }}>
116142
<EditorRenderer
117-
key={key}
143+
key={project}
118144
onLoad={(app) => {
119145
window.app = app;
120146
}}
@@ -138,13 +164,13 @@ const App = () => {
138164
}}
139165
editorConfig={{
140166
disableEditorSearch: true,
141-
stretchHeight: true,
167+
// stretchHeight: true,
142168
}}
143169
documentModel={{
144170
type: 'code',
145171
ref,
146-
owner,
147-
name,
172+
owner: project.split('/')[0],
173+
name: project.split('/')[1],
148174
filepath,
149175
onFilepathChange(newFilepath) {
150176
setFilePath(newFilepath);

packages/lsif-service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"dependencies": {
2222
"@alipay/alex-core": "0.11.1",
2323
"@alipay/alex-shared": "0.11.1",
24-
"@alipay/lsif-client": "^1.2.0"
24+
"@alipay/lsif-client": "^1.4.0"
2525
},
2626
"peerDependencies": {
2727
"@ali/ide-core-common": "1.35.2",

packages/lsif-service/src/language-service.contribution.ts

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
URI,
77
Uri,
88
IReporterService,
9+
Emitter,
910
} from '@ali/ide-core-common';
1011
import {
1112
ClientAppContribution,
@@ -21,7 +22,12 @@ import { UriComponents } from 'vscode-uri';
2122
import { EditorComponentRegistry, ResourceService, IResource } from '@ali/ide-editor/lib/browser';
2223

2324
import * as vscode from 'vscode';
24-
import { LSIF_PROD_API_HOST, LSIF_TEST_API_HOST, LsifClient } from '@alipay/lsif-client';
25+
import {
26+
LSIF_PROD_API_HOST,
27+
LSIF_TEST_API_HOST,
28+
LsifClient,
29+
OriginScheme,
30+
} from '@alipay/lsif-client';
2531
import { RuntimeConfig, REPORT_NAME } from '@alipay/alex-core';
2632
import {
2733
BrowserEditorContribution,
@@ -30,15 +36,18 @@ import {
3036

3137
import { SimpleLanguageService } from './language-client';
3238
import { LsifPreferences, lsifPreferenceSchema } from './lsif-preferences';
33-
import { OriginScheme, ModelScheme } from './constant';
34-
import { LibEditorDocumentModelProvider } from './lib-scheme.provider';
3539

3640
const IS_TEST_ENV =
3741
process.env.NODE_ENV === 'development' ||
3842
window.location.pathname.indexOf('test') > -1 ||
3943
window.location.hostname === 'localhost' ||
4044
window.location.hostname === '127.0.0.1';
4145

46+
const handleLsifScheme = (scheme: string) => {
47+
const supportScheme: string[] = [OriginScheme.Jar, OriginScheme.Tnpm];
48+
return supportScheme.includes(scheme) ? 10 : -1;
49+
};
50+
4251
@Domain(ClientAppContribution, PreferenceContribution, BrowserEditorContribution)
4352
export class LsifContribution
4453
extends Disposable
@@ -102,7 +111,7 @@ export class LsifContribution
102111
} else {
103112
apiHost = IS_TEST_ENV ? LSIF_TEST_API_HOST : LSIF_PROD_API_HOST;
104113
}
105-
this.lsifClient = new LsifClient(apiHost);
114+
this.lsifClient = new LsifClient(apiHost, this.runtimeConfig.biz || window.location.hostname);
106115
// 集成侧如果需要不一样的 preference name 则需要进行代理
107116
this.lsIfEnabled = this.preferences['lsif.enable'];
108117
this.lsifDocumentScheme = this.preferences['lsif.documentScheme'];
@@ -213,18 +222,22 @@ export class LsifContribution
213222

214223
let locationUri: Uri;
215224

216-
// TODO 处理下 unpkg 协议
217225
switch (scheme) {
226+
// 仓库内
227+
case '':
228+
case 'file':
229+
locationUri = Uri.file(paths.posix.join(_rootUri.path.toString(), path));
230+
break;
231+
232+
// 跨库
218233
case OriginScheme.Jar:
234+
case OriginScheme.Tnpm:
219235
locationUri = Uri.from({
220-
scheme: ModelScheme.Jar,
236+
scheme,
221237
path,
222238
});
223239
break;
224-
case '':
225-
case OriginScheme.File:
226-
locationUri = Uri.file(paths.posix.join(_rootUri.path.toString(), path));
227-
break;
240+
228241
// 无法处理的协议不处理
229242
default:
230243
return null;
@@ -293,18 +306,22 @@ export class LsifContribution
293306

294307
let locationUri: Uri;
295308

296-
// TODO 处理下 unpkg 协议
297309
switch (scheme) {
310+
// 仓库内
311+
case '':
312+
case 'file':
313+
locationUri = Uri.file(paths.posix.join(_rootUri.path.toString(), path));
314+
break;
315+
316+
// 跨库
298317
case OriginScheme.Jar:
318+
case OriginScheme.Tnpm:
299319
locationUri = Uri.from({
300-
scheme: ModelScheme.Jar,
320+
scheme,
301321
path,
302322
});
303323
break;
304-
case '':
305-
case OriginScheme.File:
306-
locationUri = Uri.file(paths.posix.join(_rootUri.path.toString(), path));
307-
break;
324+
308325
// 无法处理的协议不处理
309326
default:
310327
return null;
@@ -331,7 +348,7 @@ export class LsifContribution
331348

332349
registerResource(service: ResourceService) {
333350
service.registerResourceProvider({
334-
scheme: ModelScheme.Jar,
351+
handlesUri: (uri) => handleLsifScheme(uri.scheme),
335352
provideResource: async (uri: URI): Promise<IResource> => {
336353
return Promise.all([this.labelService.getName(uri), this.labelService.getIcon(uri)]).then(
337354
([name, icon]) => {
@@ -348,7 +365,7 @@ export class LsifContribution
348365
}
349366

350367
registerEditorComponent(registry: EditorComponentRegistry) {
351-
registry.registerEditorComponentResolver(ModelScheme.Jar, (_resource, results) => {
368+
registry.registerEditorComponentResolver(handleLsifScheme, (_resource, results) => {
352369
results.push({
353370
type: 'code',
354371
readonly: true,
@@ -357,8 +374,12 @@ export class LsifContribution
357374
}
358375

359376
registerEditorDocumentModelContentProvider(registry: IEditorDocumentModelContentRegistry) {
360-
registry.registerEditorDocumentModelContentProvider(
361-
new LibEditorDocumentModelProvider(this.lsifClient)
362-
);
377+
registry.registerEditorDocumentModelContentProvider({
378+
onDidChangeContent: new Emitter<URI>().event,
379+
handlesScheme: (scheme) => handleLsifScheme(scheme) > 0,
380+
isReadonly: () => true,
381+
provideEditorDocumentModelContent: (uri: URI) =>
382+
this.lsifClient.getFileContentFromUriString(uri.toString()),
383+
});
363384
}
364385
}

packages/lsif-service/src/lib-scheme.provider.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)