Skip to content

Commit 845bac6

Browse files
author
winjo
committed
fix: 修复初始文件打开 url hash 问题
1 parent 1ec5da0 commit 845bac6

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

packages/code-api/src/common/constant.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export const GITHUB_CONTAINER_ID = 'github';
22

33
export const GITLAB_CONTAINER_ID = 'gitlab';
44

5-
export const GITHUB_OAUTH_TOKEN = 'github-oauth-token';
5+
export const GITHUB_OAUTH_TOKEN = 'alex.github-oauth-token';
66

7-
export const GITLAB_PRIVATE_TOKEN = 'gitlab-private-token';
7+
export const GITLAB_PRIVATE_TOKEN = 'alex.gitlab-private-token';

packages/code-service/src/code-service.contribution.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
formatLocalize,
1212
FileChangeType,
1313
WithEventBus,
14-
OnEvent,
14+
IDisposable,
15+
IEventBus,
1516
} from '@ali/ide-core-common';
1617
import {
1718
LaunchContribution,
@@ -42,7 +43,6 @@ import { RefType } from './types';
4243

4344
@Domain(LaunchContribution, BrowserEditorContribution, CommandContribution)
4445
export class CodeContribution
45-
extends WithEventBus
4646
implements LaunchContribution, BrowserEditorContribution, CommandContribution {
4747
@Autowired()
4848
codeModel: CodeModelService;
@@ -77,18 +77,19 @@ export class CodeContribution
7777
@Autowired(IDiskFileProvider)
7878
diskFile: DiskFsProviderClient;
7979

80+
@Autowired(IEventBus)
81+
protected eventBus: IEventBus;
82+
8083
private _unmount: () => void | undefined;
8184

8285
private _mounting = false;
8386

87+
private _disposables: IDisposable[] = [];
88+
8489
async launch({ rootFS }: IServerApp) {
8590
const codeConfig = this.runtimeConfig?.codeService;
8691
if (!codeConfig) return;
8792

88-
this.codeModel.onDidChangeRefPath((path) => {
89-
console.log('>>>>>>>path', path);
90-
});
91-
9293
let initDeferred: Deferred<void> | null = new Deferred();
9394
this.codeModel.onDidChangeHEAD(() => {
9495
this.mountFilesystem(rootFS).then(() => {
@@ -160,14 +161,22 @@ export class CodeContribution
160161
const { revealEntry } = this.codeModel;
161162
if (!revealEntry?.filepath) return;
162163
const uri = URI.file(path.join(this.appConfig.workspaceDir, revealEntry.filepath));
164+
let wait: Promise<any> = Promise.resolve();
163165
if (revealEntry.type === 'blob') {
164-
this.editorService.open(uri, {
166+
wait = this.editorService.open(uri, {
165167
preview: false,
166168
deletedPolicy: 'fail',
167169
});
168170
} else if (revealEntry.type === 'tree') {
169171
this.commandService.tryExecuteCommand(FILE_COMMANDS.LOCATION.id, uri);
170172
}
173+
wait.finally(() => {
174+
this._disposables.push(
175+
this.eventBus.on(EditorGroupChangeEvent, (event) => {
176+
this.onEditorGroupChangeEvent(event);
177+
})
178+
);
179+
});
171180
}
172181

173182
registerCommands(commandRegistry: CommandRegistry) {
@@ -209,7 +218,6 @@ export class CodeContribution
209218
);
210219
}
211220

212-
@OnEvent(EditorGroupChangeEvent)
213221
onEditorGroupChangeEvent({ payload: { newOpenType, newResource } }: EditorGroupChangeEvent) {
214222
if (newOpenType?.type === 'code' && newResource && !newResource.deleted) {
215223
const fsPath = newResource.uri.codeUri.path;
@@ -226,5 +234,6 @@ export class CodeContribution
226234

227235
dispose() {
228236
this._unmount?.();
237+
this._disposables.forEach((disposer) => disposer.dispose());
229238
}
230239
}

0 commit comments

Comments
 (0)