Skip to content

Commit

Permalink
feat: approve debug memory provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricbet committed May 16, 2022
1 parent 080a944 commit 091015c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 23 deletions.
90 changes: 71 additions & 19 deletions packages/debug/src/browser/debug-memory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@opensumi/di';
import { Injectable, Autowired } from '@opensumi/di';
import {
Event,
FileSystemProvider,
Expand All @@ -9,24 +9,27 @@ import {
Uri,
BinaryBuffer,
Emitter,
FileChange,
} from '@opensumi/ide-core-common';

import { DEBUG_MEMORY_SCHEME, IDebugSessionManager } from '../common';

import { DebugSessionManager } from '.';

@Injectable()
export class DebugMemoryFileSystemProvider implements FileSystemProvider {
@Autowired(IDebugSessionManager)
protected readonly debugSessionManager: DebugSessionManager;

private readonly changeEmitter = new Emitter<FileChangeEvent>();

public readonly capabilities: FileSystemProviderCapabilities =
0 | FileSystemProviderCapabilities.PathCaseSensitive | FileSystemProviderCapabilities.FileOpenReadWriteClose;

public readonly onDidChangeCapabilities = Event.None;

onDidChangeFile: Event<FileChangeEvent> = this.changeEmitter.event;
public onDidChangeFile: Event<FileChangeEvent> = this.changeEmitter.event;

watch(uri: Uri, options: { recursive: boolean; excludes: string[] }): number | Promise<number> {
throw new Error('Not allowed');
}
stat(uri: Uri): Promise<void | FileStat> {
public stat(uri: Uri): Promise<void | FileStat> {
return Promise.resolve({
type: FileType.File,
uri: uri.toString(),
Expand All @@ -37,26 +40,75 @@ export class DebugMemoryFileSystemProvider implements FileSystemProvider {
isDirectory: false,
});
}
readDirectory(uri: Uri): [string, FileType][] | Promise<[string, FileType][]> {
throw new Error('Not allowed');

public readFile(uri: Uri): void | Uint8Array | Promise<void | Uint8Array> {
const parse = this.parseUri(uri);
if (parse && !parse.offset) {
return;
}

return this.toBuffer('');
}

private toBuffer(s: string): Uint8Array {
return BinaryBuffer.fromString(s).buffer;
}

private parseUri(uri: Uri) {
if (uri.scheme !== DEBUG_MEMORY_SCHEME) {
return;
}

const session = this.debugSessionManager.sessions.find((s) => s.id.toLowerCase() === uri.authority.toLowerCase());
if (!session) {
return;
}

let offset: { fromOffset: number; toOffset: number } | undefined;
/**
* query 参数是 hex-editor 插件通过覆盖了 debug file accessor 处理过后添加上的,形如
* ?range=0:131072
*/
const rangeMatch = /range=([0-9]+):([0-9]+)/.exec(uri.query);
if (rangeMatch) {
offset = { fromOffset: Number(rangeMatch[1]), toOffset: Number(rangeMatch[2]) };
}

const [, memoryReference] = uri.path.split('/');

return {
session,
offset,
readOnly: !session.capabilities.supportsWriteMemoryRequest,
sessionId: uri.authority,
memoryReference: decodeURIComponent(memoryReference),
};
}
createDirectory(uri: Uri): void | Promise<void | FileStat> {

public readDirectory(): never {
throw new Error('Not allowed');
}
readFile(uri: Uri, encoding?: string): void | Uint8Array | Promise<void | Uint8Array> {
return BinaryBuffer.fromString('DebugMemoryFileSystemProvider').buffer;

public createDirectory(): never {
throw new Error('Not allowed');
}
writeFile(
uri: Uri,
content: Uint8Array,
options: { create: boolean; overwrite: boolean; encoding?: string | undefined },
): void | Thenable<void | FileStat> {

public rename(): never {
throw new Error('Not allowed');
}
delete(uri: Uri, options: { recursive: boolean; moveToTrash?: boolean | undefined }): void | Promise<void> {

public delete(): never {
throw new Error('Not allowed');
}
rename(oldstring: Uri, newstring: Uri, options: { overwrite: boolean }): void | Promise<void | FileStat> {

public watch(): never {
throw new Error('Not allowed');
}

/**
* 目前仅支持读,不支持写
*/
public writeFile(): never {
throw new Error('Method not implemented.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import { MenuContribution, IMenuRegistry, MenuId } from '@opensumi/ide-core-brow
import { CommandService, CUSTOM_EDITOR_SCHEME, IExtensionProps, URI } from '@opensumi/ide-core-common';
import {
BrowserEditorContribution,
EditorComponentRegistry,
EditorComponentRenderMode,
EditorGroupSplitAction,
IEditorDocumentModelContentRegistry,
IResource,
ResourceService,
WorkbenchEditorService,
Expand Down Expand Up @@ -159,7 +156,6 @@ export class VariablesPanelContribution implements BrowserEditorContribution, Me
{
split: EditorGroupSplitAction.Right,
disableNavigate: true,
backend: true,
preview: true,
forceOpenType: {
type: 'component',
Expand Down

0 comments on commit 091015c

Please sign in to comment.