feat: support copy relative path from link files (#4367)

* feat: support copy relative path from link files

* chore: add @opensumi/ide-utils dependency

* chore: reorder @opensumi/ide-utils dependency

* chore: update test coverage exclusions for notebook module

* fix: handle leading separators in TreeNode paths and use fsPath for URIs
This commit is contained in:
Dan 2025-02-17 14:08:54 +08:00 committed by GitHub
parent 7d522955ff
commit 2aba876807
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 21 additions and 9 deletions

View File

@ -17,8 +17,9 @@ const baseConfig = {
// 部分contribution文件为-contribution结尾 // 部分contribution文件为-contribution结尾
'!packages/**/*-contribution.ts', '!packages/**/*-contribution.ts',
'!packages/startup/**/*.ts', '!packages/startup/**/*.ts',
// Test 功能暂未完成 // Test, Notebook 模块暂不覆盖
'!packages/testing/**/*.ts', '!packages/testing/**/*.ts',
'!packages/notebook/**/*.ts',
// CLI 不需要测试 // CLI 不需要测试
'!packages/remote-cli/**/*.ts', '!packages/remote-cli/**/*.ts',
'!packages/core-electron-main/**/*.ts', '!packages/core-electron-main/**/*.ts',

View File

@ -236,9 +236,11 @@ export class TreeNode implements ITreeNode {
get path(): string { get path(): string {
if (!this._path) { if (!this._path) {
if (!this.parent) { if (!this.parent) {
this._path = new Path(`${Path.separator}${this.name}`).toString(); this._path = this.name.startsWith(Path.separator) ? this.name : `${Path.separator}${this.name}`;
} else { } else {
this._path = new Path(this.parent.path).join(this.name).toString(); this._path = this.name.startsWith(Path.separator)
? `${this.parent.path}${this.name}`
: `${this.parent.path}${Path.separator}${this.name}`;
} }
} }
return this._path; return this._path;

View File

@ -32,6 +32,7 @@
"@opensumi/ide-overlay": "workspace:*", "@opensumi/ide-overlay": "workspace:*",
"@opensumi/ide-terminal-next": "workspace:*", "@opensumi/ide-terminal-next": "workspace:*",
"@opensumi/ide-theme": "workspace:*", "@opensumi/ide-theme": "workspace:*",
"@opensumi/ide-utils": "workspace:*",
"@opensumi/ide-workspace": "workspace:*", "@opensumi/ide-workspace": "workspace:*",
"@opensumi/ide-workspace-edit": "workspace:*" "@opensumi/ide-workspace-edit": "workspace:*"
} }

View File

@ -50,6 +50,7 @@ import { EXPLORER_CONTAINER_ID } from '@opensumi/ide-explorer/lib/browser/explor
import { IMainLayoutService, IViewsRegistry, MainLayoutContribution } from '@opensumi/ide-main-layout'; import { IMainLayoutService, IViewsRegistry, MainLayoutContribution } from '@opensumi/ide-main-layout';
import { ViewContentGroups } from '@opensumi/ide-main-layout/lib/browser/views-registry'; import { ViewContentGroups } from '@opensumi/ide-main-layout/lib/browser/views-registry';
import { IOpenDialogOptions, ISaveDialogOptions, IWindowDialogService } from '@opensumi/ide-overlay'; import { IOpenDialogOptions, ISaveDialogOptions, IWindowDialogService } from '@opensumi/ide-overlay';
import { Path } from '@opensumi/ide-utils/lib/path';
import { IWorkspaceService, UNTITLED_WORKSPACE } from '@opensumi/ide-workspace'; import { IWorkspaceService, UNTITLED_WORKSPACE } from '@opensumi/ide-workspace';
import { IFileTreeService, PasteTypes, RESOURCE_VIEW_ID } from '../common'; import { IFileTreeService, PasteTypes, RESOURCE_VIEW_ID } from '../common';
@ -778,9 +779,15 @@ export class FileTreeContribution
} }
if (uri.scheme === DIFF_SCHEME) { if (uri.scheme === DIFF_SCHEME) {
const query = uri.getParsedQuery(); const query = uri.getParsedQuery();
// 需要file scheme才能与工作区计算相对路径
uri = new URI(query.modified).withScheme('file'); uri = new URI(query.modified).withScheme('file');
} }
const node = this.fileTreeService.getNodeByPathOrUri(uri);
if (node) {
if (node.filestat.isInSymbolicDirectory) {
// 软链接文件需要通过直接通过文件树 Path 获取
return await this.clipboardService.writeText(node.path.split(Path.separator).slice(2).join(Path.separator));
}
}
let rootUri: URI; let rootUri: URI;
if (this.fileTreeService.isMultipleWorkspace) { if (this.fileTreeService.isMultipleWorkspace) {
// 多工作区额外处理 // 多工作区额外处理

View File

@ -70,7 +70,7 @@ export class EditorFile extends TreeNode {
public dirty: boolean = false, public dirty: boolean = false,
parent: EditorFileGroup | undefined, parent: EditorFileGroup | undefined,
) { ) {
super(tree as ITree, parent, undefined, { name: `${resource.uri.toString()}` }); super(tree as ITree, parent, undefined, { name: `${resource.uri.codeUri.fsPath.toString()}` });
} }
get displayName() { get displayName() {

View File

@ -127,16 +127,16 @@ export class OpenedEditorService extends Tree {
.join(groupName) .join(groupName)
.join( .join(
resource && (resource as IResource).uri resource && (resource as IResource).uri
? (resource as IResource).uri.toString() ? (resource as IResource).uri.codeUri.fsPath
: (resource as URI).toString(), : (resource as URI).codeUri.fsPath,
) )
.toString(); .toString();
} else { } else {
path = new Path(path) path = new Path(path)
.join( .join(
resource && (resource as IResource).uri resource && (resource as IResource).uri
? (resource as IResource).uri.toString() ? (resource as IResource).uri.codeUri.fsPath
: (resource as URI).toString(), : (resource as URI).codeUri.fsPath,
) )
.toString(); .toString();
} }

View File

@ -3731,6 +3731,7 @@ __metadata:
"@opensumi/ide-overlay": "workspace:*" "@opensumi/ide-overlay": "workspace:*"
"@opensumi/ide-terminal-next": "workspace:*" "@opensumi/ide-terminal-next": "workspace:*"
"@opensumi/ide-theme": "workspace:*" "@opensumi/ide-theme": "workspace:*"
"@opensumi/ide-utils": "workspace:*"
"@opensumi/ide-workspace": "workspace:*" "@opensumi/ide-workspace": "workspace:*"
"@opensumi/ide-workspace-edit": "workspace:*" "@opensumi/ide-workspace-edit": "workspace:*"
languageName: unknown languageName: unknown