mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Test getInstanceFromResource
Part of #126387 Co-Authored-By: Megan Rogge <merogge@microsoft.com>
This commit is contained in:
parent
954686aae5
commit
9fee021ba4
|
@ -16,7 +16,7 @@ import { IRemoteTerminalService, ITerminalEditorService, ITerminalInstance, ITer
|
|||
import { TerminalEditor } from 'vs/workbench/contrib/terminal/browser/terminalEditor';
|
||||
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
|
||||
import { DeserializedTerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorSerializer';
|
||||
import { parseTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
import { getInstanceFromResource, parseTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
import { ILocalTerminalService, IOffProcessTerminalService } from 'vs/workbench/contrib/terminal/common/terminal';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
|
@ -219,16 +219,7 @@ export class TerminalEditorService extends Disposable implements ITerminalEditor
|
|||
}
|
||||
|
||||
getInstanceFromResource(resource: URI | undefined): ITerminalInstance | undefined {
|
||||
if (URI.isUri(resource)) {
|
||||
// note that the uri and and instance id might
|
||||
// not match this window
|
||||
for (const instance of this.instances) {
|
||||
if (instance.resource.path === resource.path) {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
return getInstanceFromResource(this.instances, resource);
|
||||
}
|
||||
|
||||
splitInstance(instanceToSplit: ITerminalInstance, shellLaunchConfig: IShellLaunchConfig = {}): ITerminalInstance {
|
||||
|
|
|
@ -16,6 +16,7 @@ import { IShellLaunchConfig, TerminalSettingId } from 'vs/platform/terminal/comm
|
|||
import { IViewDescriptorService, IViewsService, ViewContainerLocation } from 'vs/workbench/common/views';
|
||||
import { ITerminalFindHost, ITerminalGroup, ITerminalGroupService, ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
import { TerminalGroup } from 'vs/workbench/contrib/terminal/browser/terminalGroup';
|
||||
import { getInstanceFromResource } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
import { TerminalViewPane } from 'vs/workbench/contrib/terminal/browser/terminalView';
|
||||
import { TERMINAL_VIEW_ID } from 'vs/workbench/contrib/terminal/common/terminal';
|
||||
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
|
||||
|
@ -177,16 +178,7 @@ export class TerminalGroupService extends Disposable implements ITerminalGroupSe
|
|||
}
|
||||
|
||||
getInstanceFromResource(resource: URI | undefined): ITerminalInstance | undefined {
|
||||
if (URI.isUri(resource)) {
|
||||
// note that the uri and and instance id might
|
||||
// not match this window
|
||||
for (const instance of this.instances) {
|
||||
if (instance.resource.path === resource.path) {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
return getInstanceFromResource(this.instances, resource);
|
||||
}
|
||||
|
||||
findNext(): void {
|
||||
|
|
|
@ -36,7 +36,7 @@ import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/term
|
|||
import { TerminalEditor } from 'vs/workbench/contrib/terminal/browser/terminalEditor';
|
||||
import { getColorClass, getUriClasses } from 'vs/workbench/contrib/terminal/browser/terminalIcon';
|
||||
import { configureTerminalProfileIcon } from 'vs/workbench/contrib/terminal/browser/terminalIcons';
|
||||
import { getTerminalUri, parseTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
import { getInstanceFromResource, getTerminalUri, parseTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
import { TerminalViewPane } from 'vs/workbench/contrib/terminal/browser/terminalView';
|
||||
import { ILocalTerminalService, IOffProcessTerminalService, IRemoteTerminalAttachTarget, IStartExtensionTerminalRequest, ITerminalConfigHelper, ITerminalProcessExtHostProxy, ITerminalProfileContribution, TERMINAL_VIEW_ID } from 'vs/workbench/contrib/terminal/common/terminal';
|
||||
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
|
||||
|
@ -606,16 +606,7 @@ export class TerminalService implements ITerminalService {
|
|||
}
|
||||
|
||||
getInstanceFromResource(resource: URI | undefined): ITerminalInstance | undefined {
|
||||
if (URI.isUri(resource)) {
|
||||
// note that the uri and and instance id might
|
||||
// not match this window
|
||||
for (const instance of this.instances) {
|
||||
if (instance.resource.path === resource.path) {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
return getInstanceFromResource(this.instances, resource);
|
||||
}
|
||||
|
||||
isAttachedToTerminal(remoteTerm: IRemoteTerminalAttachTarget): boolean {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import { DataTransfers } from 'vs/base/browser/dnd';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
|
||||
export function parseTerminalUri(resource: URI): ITerminalIdentifier {
|
||||
const [, workspaceId, instanceId] = resource.path.split('/');
|
||||
|
@ -44,3 +45,16 @@ export function getTerminalResourcesFromDragEvent(event: IPartialDragEvent): URI
|
|||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getInstanceFromResource<T extends Pick<ITerminalInstance, 'resource'>>(instances: T[], resource: URI | undefined): T | undefined {
|
||||
if (resource) {
|
||||
for (const instance of instances) {
|
||||
// Note that the URI's workspace and instance id might not originally be from this window
|
||||
// Don't bother checking the scheme and assume instances only contains terminals
|
||||
if (instance.resource.path === resource.path) {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { deepStrictEqual } from 'assert';
|
||||
import { getTerminalResourcesFromDragEvent, IPartialDragEvent } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
import { deepStrictEqual, strictEqual } from 'assert';
|
||||
import { getInstanceFromResource, getTerminalResourcesFromDragEvent, getTerminalUri, IPartialDragEvent } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
|
||||
function fakeDragEvent(data: string): IPartialDragEvent {
|
||||
return {
|
||||
|
@ -16,29 +16,63 @@ function fakeDragEvent(data: string): IPartialDragEvent {
|
|||
};
|
||||
}
|
||||
|
||||
suite('getTerminalResourcesFromDragEvent', () => {
|
||||
test('should give undefined when no terminal resources is in event', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent(''))?.map(e => e.toString()),
|
||||
undefined
|
||||
);
|
||||
suite('terminalUri', () => {
|
||||
suite('getTerminalResourcesFromDragEvent', () => {
|
||||
test('should give undefined when no terminal resources is in event', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent(''))?.map(e => e.toString()),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
test('should give undefined when an empty terminal resources array is in event', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent('[]'))?.map(e => e.toString()),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
test('should return terminal resource when event contains one', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent('["vscode-terminal:/1626874386474/3"]'))?.map(e => e.toString()),
|
||||
['vscode-terminal:/1626874386474/3']
|
||||
);
|
||||
});
|
||||
test('should return multiple terminal resources when event contains multiple', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent('["vscode-terminal:/foo/1","vscode-terminal:/bar/2"]'))?.map(e => e.toString()),
|
||||
['vscode-terminal:/foo/1', 'vscode-terminal:/bar/2']
|
||||
);
|
||||
});
|
||||
});
|
||||
test('should give undefined when an empty terminal resources array is in event', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent('[]'))?.map(e => e.toString()),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
test('should return terminal resource when event contains one', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent('["vscode-terminal:/1626874386474/3"]'))?.map(e => e.toString()),
|
||||
['vscode-terminal:/1626874386474/3']
|
||||
);
|
||||
});
|
||||
test('should return multiple terminal resources when event contains multiple', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent('["vscode-terminal:/foo/1","vscode-terminal:/bar/2"]'))?.map(e => e.toString()),
|
||||
['vscode-terminal:/foo/1', 'vscode-terminal:/bar/2']
|
||||
);
|
||||
suite('getInstanceFromResource', () => {
|
||||
test('should return undefined if there is no match', () => {
|
||||
strictEqual(
|
||||
getInstanceFromResource([
|
||||
{ resource: getTerminalUri('workspace', 2, 'title') }
|
||||
], getTerminalUri('workspace', 1)),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
test('should return a result if there is a match', () => {
|
||||
const instance = { resource: getTerminalUri('workspace', 2, 'title') };
|
||||
strictEqual(
|
||||
getInstanceFromResource([
|
||||
{ resource: getTerminalUri('workspace', 1, 'title') },
|
||||
instance,
|
||||
{ resource: getTerminalUri('workspace', 3, 'title') }
|
||||
], getTerminalUri('workspace', 2)),
|
||||
instance
|
||||
);
|
||||
});
|
||||
test('should ignore the fragment', () => {
|
||||
const instance = { resource: getTerminalUri('workspace', 2, 'title') };
|
||||
strictEqual(
|
||||
getInstanceFromResource([
|
||||
{ resource: getTerminalUri('workspace', 1, 'title') },
|
||||
instance,
|
||||
{ resource: getTerminalUri('workspace', 3, 'title') }
|
||||
], getTerminalUri('workspace', 2, 'does not match!')),
|
||||
instance
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue