MCPcopy Create free account
hub / github.com/Wscats/vscode-explore / ContextKeyRegexExpr

Class ContextKeyRegexExpr

contextKeyExpr/src/contextkey.ts:841–906  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

839}
840
841export class ContextKeyRegexExpr implements IContextKeyExpression {
842
843 public static create(key: string, regexp: RegExp | null): ContextKeyRegexExpr {
844 return new ContextKeyRegexExpr(key, regexp);
845 }
846
847 public readonly type = ContextKeyExprType.Regex;
848
849 private constructor(private readonly key: string, private readonly regexp: RegExp | null) {
850 //
851 }
852
853 public cmp(other: ContextKeyExpression): number {
854 if (other.type !== this.type) {
855 return this.type - other.type;
856 }
857 if (this.key < other.key) {
858 return -1;
859 }
860 if (this.key > other.key) {
861 return 1;
862 }
863 const thisSource = this.regexp ? this.regexp.source : '';
864 const otherSource = other.regexp ? other.regexp.source : '';
865 if (thisSource < otherSource) {
866 return -1;
867 }
868 if (thisSource > otherSource) {
869 return 1;
870 }
871 return 0;
872 }
873
874 public equals(other: ContextKeyExpression): boolean {
875 if (other.type === this.type) {
876 const thisSource = this.regexp ? this.regexp.source : '';
877 const otherSource = other.regexp ? other.regexp.source : '';
878 return (this.key === other.key && thisSource === otherSource);
879 }
880 return false;
881 }
882
883 public evaluate(context: IContext): boolean {
884 let value = context.getValue<any>(this.key);
885 return this.regexp ? this.regexp.test(value) : false;
886 }
887
888 public serialize(): string {
889 const value = this.regexp
890 ? `/${this.regexp.source}/${this.regexp.ignoreCase ? 'i' : ''}`
891 : '/invalid/';
892 return `${this.key} =~ ${value}`;
893 }
894
895 public keys(): string[] {
896 return [this.key];
897 }
898

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected