You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

  1. import type { TextEditor, Uri } from 'vscode';
  2. abstract class Comparer<T> {
  3. abstract equals(lhs: T, rhs: T): boolean;
  4. }
  5. class UriComparer extends Comparer<Uri> {
  6. equals(lhs: Uri | undefined, rhs: Uri | undefined, options: { exact?: boolean } = { exact: false }) {
  7. if (lhs === rhs) return true;
  8. if (lhs == null || rhs == null) return false;
  9. if (options.exact) {
  10. return lhs.toString() === rhs.toString();
  11. }
  12. return lhs.scheme === rhs.scheme && lhs.fsPath === rhs.fsPath;
  13. }
  14. }
  15. class TextEditorComparer extends Comparer<TextEditor> {
  16. equals(
  17. lhs: TextEditor | undefined,
  18. rhs: TextEditor | undefined,
  19. options: { usePosition: boolean } = { usePosition: false },
  20. ) {
  21. if (lhs === rhs) return true;
  22. if (lhs == null || rhs == null) return false;
  23. if (options.usePosition && lhs.viewColumn !== rhs.viewColumn) return false;
  24. return lhs.document === rhs.document;
  25. }
  26. }
  27. const textEditorComparer = new TextEditorComparer();
  28. const uriComparer = new UriComparer();
  29. export { textEditorComparer as TextEditorComparer, uriComparer as UriComparer };