tabWorkspaceIdentity.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. interface WorkspaceTabIdentityLike {
  2. workspacePath: string;
  3. remoteSessionId?: string;
  4. workspaceIdentity?: string;
  5. }
  6. interface WorkspaceTabMatchOptions {
  7. remoteSessionId?: string;
  8. workspaceIdentity?: string;
  9. previousWorkspaceIdentity?: string;
  10. }
  11. function hasRemoteTabIdentity(tab: WorkspaceTabIdentityLike): boolean {
  12. return Boolean(tab.workspaceIdentity || tab.remoteSessionId);
  13. }
  14. function isLocalWorkspaceTab(tab: WorkspaceTabIdentityLike): boolean {
  15. return !hasRemoteTabIdentity(tab);
  16. }
  17. export function isSameWorkspaceTab(
  18. tab: WorkspaceTabIdentityLike,
  19. workspacePath: string,
  20. options?: WorkspaceTabMatchOptions,
  21. ): boolean {
  22. if (tab.workspacePath !== workspacePath) {
  23. return false;
  24. }
  25. if (options?.workspaceIdentity) {
  26. return (
  27. tab.workspaceIdentity === options.workspaceIdentity ||
  28. (Boolean(options.previousWorkspaceIdentity) &&
  29. tab.workspaceIdentity === options.previousWorkspaceIdentity)
  30. );
  31. }
  32. if (options?.remoteSessionId) {
  33. return tab.remoteSessionId === options.remoteSessionId;
  34. }
  35. return isLocalWorkspaceTab(tab);
  36. }