Skip to content

Commit

Permalink
Merge branch 'v2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
opensumi[bot] committed Oct 10, 2024
2 parents 302756f + 21e7a88 commit 8532548
Show file tree
Hide file tree
Showing 26 changed files with 183 additions and 64 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "2.0.4"
"version": "2.1.0"
}
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codeblitzjs/ide-cli",
"version": "2.0.4",
"version": "2.1.0",
"description": "@codeblitzjs/ide-cli",
"main": "lib/commander.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/code-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codeblitzjs/ide-code-api",
"version": "2.0.4",
"version": "2.1.0",
"description": "@codeblitzjs/ide-code-api",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/code-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codeblitzjs/ide-code-service",
"version": "2.0.4",
"version": "2.1.0",
"description": "@codeblitzjs/ide-code-service",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codeblitzjs/ide-common",
"version": "2.0.4",
"version": "2.1.0",
"description": "@codeblitzjs/ide-common",
"main": "lib/index.js",
"typing": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codeblitzjs/ide-core",
"version": "2.0.4",
"version": "2.1.0",
"description": "@codeblitzjs/ide-core",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/api/createEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { IAppInstance, IConfig } from './types';

export { BoxPanel, SlotLocation, SlotRenderer, SplitPanel };

const getDefaultAppConfig = (): IAppOpts => ({
const getDefaultEditorAppConfig = (): IAppOpts => ({
modules: getModules(),
useCdnIcon: true,
noExtHost: true,
Expand Down Expand Up @@ -62,7 +62,7 @@ const getDefaultAppConfig = (): IAppOpts => ({
});

export function createEditor({ appConfig, runtimeConfig }: IConfig): IAppInstance {
const opts = interceptAppOpts(mergeConfig(getDefaultAppConfig(), appConfig), runtimeConfig);
const opts = interceptAppOpts(mergeConfig(getDefaultEditorAppConfig(), appConfig), runtimeConfig);

if (!opts.workspaceDir) {
throw new Error(
Expand Down
23 changes: 8 additions & 15 deletions packages/core/src/core/diff-viewer/internal/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fsExtra, isFilesystemReady } from '@codeblitzjs/ide-sumi-core';
import { InlineChatHandler } from '@opensumi/ide-ai-native/lib/browser/widget/inline-chat/inline-chat.handler';
import { AppConfig, ClientAppContribution, EDITOR_COMMANDS, IClientApp } from '@opensumi/ide-core-browser';
import { AppConfig, ClientAppContribution, EDITOR_COMMANDS } from '@opensumi/ide-core-browser';
import {
Disposable,
DisposableStore,
Expand All @@ -10,14 +10,12 @@ import {
IChatProgress,
ILogger,
isArray,
isWindows,
MaybePromise,
Sequencer,
URI,
} from '@opensumi/ide-core-common';
import { IResourceOpenOptions, WorkbenchEditorService } from '@opensumi/ide-editor';
import { Selection, SelectionDirection } from '@opensumi/ide-monaco';
import { toSlashes } from '@opensumi/ide-utils/lib/path';

import { Autowired } from '@opensumi/di';
import { InlineChatController } from '@opensumi/ide-ai-native/lib/browser/widget/inline-chat/inline-chat-controller';
Expand Down Expand Up @@ -87,12 +85,8 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
return URI.file(this.getFullPath(filePath));
}

normalizePath(filePath: string) {
let result = removeStart(filePath, this.appConfig.workspaceDir);
if (isWindows) {
result = toSlashes(result);
}

normalizePath(path: string) {
let result = removeStart(path, this.appConfig.workspaceDir);
if (result.startsWith('/')) {
return result.slice(1);
}
Expand Down Expand Up @@ -245,7 +239,7 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
};

getFilePathForEditor = (editor: IEditor) => {
return this.normalizePath(editor.currentUri!.codeUri.fsPath);
return this.normalizePath(editor.currentUri!.codeUri.path);
};

getAllTabs = (): IDiffViewerTab[] => {
Expand All @@ -254,7 +248,7 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri

return resources.map((editor, idx) => ({
index: idx,
filePath: this.normalizePath(editor.uri.codeUri.fsPath),
filePath: this.normalizePath(editor.uri.codeUri.path),
}));
};

Expand Down Expand Up @@ -362,17 +356,16 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
this._disposables.add(disposable);

disposable.addDispose(this.inlineDiffHandler.onPartialEditEvent((e) => {
const fsPath = e.uri.fsPath;
const path = e.uri.path;

this._onPartialEditEvent.fire({
filePath: this.normalizePath(fsPath),
filePath: this.normalizePath(path),
...e,
});
}));

disposable.addDispose(this.workbenchEditorService.onActiveResourceChange((e) => {
const _newPath = e?.uri.codeUri.fsPath;
let newPath = _newPath;
let newPath = e?.uri.codeUri.path;
let currentIndex = -1;
if (newPath) {
currentIndex = this.getFileIndex(newPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Autowired, Injectable } from '@opensumi/di';
import { AppConfig, Domain, path as paths, URI } from '@opensumi/ide-core-browser';
import {
StaticResourceContribution as CoreStaticResourceContribution,
StaticResourceService,
} from '@opensumi/ide-core-browser/lib/static-resource';
import { IWorkspaceService } from '@opensumi/ide-workspace';
import { IPropsService } from '../../props.service';
import { fromSCMUri } from '../../utils';
import { CodeDocumentModel, EditorProps } from '../types';

const EXPRESS_SERVER_PATH = window.location.href;

// file 文件资源 远程读取
@Domain(CoreStaticResourceContribution)
export class EditorStaticResourceContribution implements CoreStaticResourceContribution {
@Autowired(AppConfig)
private readonly appConfig: AppConfig;

@Autowired(IWorkspaceService)
private readonly workspaceService: IWorkspaceService;

@Autowired(IPropsService)
propsService: IPropsService<EditorProps>;

registerStaticResolver(service: StaticResourceService): void {
// 用来打开 raw 文件,如 jpg
service.registerStaticResourceProvider({
scheme: 'file',
resolveStaticResource: (uri: URI) => {
const documentModel = this.propsService.props.documentModel;

if (
!(this.appConfig.staticServicePath
|| (documentModel && (documentModel as CodeDocumentModel).resolveStaticResourcePath))
) {
return uri;
}

// 将 file 协议转为代码托管平台提供的 raw 服务
const assetsUri = new URI(this.appConfig.staticServicePath!);
const rootUri = new URI(this.workspaceService.workspace?.uri!);
const relativePath = rootUri.relative(uri);
if (!relativePath) {
return uri;
}

// FIXME: 由于 resolveStaticResource 是同步方法,这里 hardcode 了 workspaceManagerService 的实现
let relativePathStr = relativePath.toString();

// trim leading whitespace
if (relativePathStr.startsWith(paths.Path.separator)) {
relativePathStr = relativePathStr.slice(1);
}

if (documentModel && (documentModel as CodeDocumentModel).resolveStaticResourcePath) {
return (documentModel as CodeDocumentModel).resolveStaticResourcePath!(
documentModel as CodeDocumentModel,
);
}
return assetsUri.withPath(assetsUri.path.join(relativePathStr));
},
roots: [this.appConfig.staticServicePath || EXPRESS_SERVER_PATH],
});
}
}
4 changes: 3 additions & 1 deletion packages/core/src/core/editor/editor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ import md5 from 'md5';
import * as path from 'path';
import { CodeBlitzCommandContribution } from '../commands';
import { IPropsService } from '../props.service';
import { DefaultThemeGuardContribution } from '../providers';
import styles from '../style.module.less';
import { EditorStaticResourceContribution } from './contributions/static-resource.contribution';
import { CodeDocumentModel, EditorProps, isCodeDocumentModel } from './types';
import { DefaultThemeGuardContribution } from '../providers';

const ContextTrue = new RawContextKey('alex.context.true', undefined);
const ContextFalse = new RawContextKey('alex.context.false', undefined);
Expand Down Expand Up @@ -740,5 +741,6 @@ export class EditorSpecialModule extends BrowserModule {
DefaultThemeGuardContribution,
EditorSpecialContribution,
CodeBlitzCommandContribution,
EditorStaticResourceContribution,
];
}
4 changes: 2 additions & 2 deletions packages/core/src/core/editor/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { WorkspaceModule } from '@opensumi/ide-workspace/lib/browser';
* alex
*/
import { PluginModule } from '@codeblitzjs/ide-plugin';
import { ClientModule, ServerModuleCollection } from '@codeblitzjs/ide-sumi-core';
import { ClientModule, EditorServerModuleCollection } from '@codeblitzjs/ide-sumi-core';

/**
* editor special
Expand Down Expand Up @@ -66,7 +66,7 @@ export const getModules: () => ModuleConstructor[] = () => [
// CodeBlitz
ClientModule,
PluginModule,
...ServerModuleCollection,
...EditorServerModuleCollection,

// Editor Special
EditorSpecialModule,
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/core/editor/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { URI } from '@opensumi/ide-core-common';

export interface DocumentModel {
/**
* 打开的文件路径
Expand Down Expand Up @@ -48,6 +50,8 @@ export interface CodeDocumentModel extends DocumentModel {
* 仓库名
*/
name: string;

resolveStaticResourcePath?(documentModel: CodeDocumentModel): URI;
}

export interface EditorConfig {
Expand Down
48 changes: 46 additions & 2 deletions packages/core/src/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IExtensionBasicMetadata } from '@codeblitzjs/ide-common';
import { IAppOpts } from '@codeblitzjs/ide-sumi-core';
import { ModuleConstructor } from '@opensumi/ide-core-browser';
import { BuiltinTheme, getThemeId, getThemeType, IThemeContribution } from '@opensumi/ide-theme';
import { URI } from '@opensumi/ide-core-common';

import { IAppConfig } from '../api/types';

Expand Down Expand Up @@ -68,3 +67,48 @@ export function createHook(obj: any, targetFunction: string, options: {
}
};
}

interface SCMUriQueryParams {
ref: string; // commitId
branch?: string; // 分支名
}

interface SCMUriParams extends SCMUriQueryParams {
platform: string; // 例如 gitlab/gitlab 等
repo: string; // groupName/repoName 项目名称
path: string; // 文件路径
}

export function fromSCMUri(uri: URI): SCMUriParams {
const query = uri.getParsedQuery();

const result: SCMUriParams = {
platform: query.scheme,
repo: query.authority,
path: query.path,
ref: query.ref,
};

if (query.branch) {
result.branch = query.branch;
}

return result;
}

export function toSCMUri(uriParams: SCMUriParams) {
const query: SCMUriQueryParams = {
ref: uriParams.ref,
};

if (uriParams.branch) {
query.branch = uriParams.branch;
}

return URI.from({
scheme: uriParams.platform,
authority: uriParams.repo,
path: uriParams.path,
query: JSON.stringify(query),
});
}
2 changes: 1 addition & 1 deletion packages/i18n/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codeblitzjs/ide-i18n",
"version": "2.0.4",
"version": "2.1.0",
"description": "@codeblitzjs/ide-i18n",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codeblitzjs/ide-plugin",
"version": "2.0.4",
"version": "2.1.0",
"description": "@codeblitzjs/ide-plugin",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/registry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codeblitzjs/ide-registry",
"version": "2.0.4",
"version": "2.1.0",
"description": "@codeblitzjs/ide-registry",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/startup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codeblitzjs/ide-startup",
"version": "2.0.4",
"version": "2.1.0",
"description": "@codeblitzjs/ide-startup",
"main": "lib/index.js",
"typing": "types/index.d.ts",
Expand Down
Loading

0 comments on commit 8532548

Please sign in to comment.