Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 0 additions & 13 deletions packages/sumi-core/src/server/file-service/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,6 @@ export function detectEncodingByBuffer(buffer: Buffer): string | null {
return mapped || normalizedEncodingName;
}

// export function detectEncodingByURI(uri: URI): string | null {
// const filePath = FileUri.fsPath(uri);
// const fd = fs.openSync(filePath, 'r');
// const maxLength = 100;
// let buffer = Buffer.allocUnsafe(maxLength);
// const readLength = fs.readSync(fd, buffer, 0, maxLength, null);

// // Reset real length
// buffer = buffer.slice(0, readLength);
// fs.closeSync(fd);
// return detectEncodingByBuffer(buffer);
// }

export function getEncodingInfo(encoding: string | null): null | EncodingInfo {
if (!encoding) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ export class FWFileSystemWatcherServer implements IFileSystemWatcherServer {
protected async lookup(path: string, count: number = 3) {
let uri = new URI(path);
let times = 0;
while (!(await fse.pathExists(uri.codeUri.fsPath)) && times <= count) {
while (!(await fse.pathExists(uri.codeUri.path)) && times <= count) {
uri = uri.parent;
times++;
}
if (await fse.pathExists(uri.codeUri.fsPath)) {
return uri.codeUri.fsPath;
if (await fse.pathExists(uri.codeUri.path)) {
return uri.codeUri.path;
} else {
return '';
}
Expand Down