1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Diagnostics ;
3
4
using Minimatch ;
4
5
using Newtonsoft . Json ;
5
6
using OmniSharp . Extensions . LanguageServer . Protocol . Document ;
6
7
using OmniSharp . Extensions . LanguageServer . Protocol . Serialization ;
7
8
8
9
namespace OmniSharp . Extensions . LanguageServer . Protocol . Models
9
10
{
11
+ [ DebuggerDisplay ( "{" + nameof ( DebuggerDisplay ) + ",nq}" ) ]
10
12
public class DocumentFilter : IEquatable < DocumentFilter >
11
13
{
12
14
public static DocumentFilter ForPattern ( string wildcard )
@@ -55,8 +57,7 @@ public static DocumentFilter ForScheme(string scheme)
55
57
public string Pattern
56
58
{
57
59
get => _pattern ;
58
- set
59
- {
60
+ set {
60
61
_pattern = value ;
61
62
_minimatcher = new Minimatcher ( value , new Options ( ) { MatchBase = true } ) ;
62
63
}
@@ -78,14 +79,17 @@ public static explicit operator string(DocumentFilter documentFilter)
78
79
{
79
80
items . Add ( documentFilter . Language ) ;
80
81
}
82
+
81
83
if ( documentFilter . HasScheme )
82
84
{
83
85
items . Add ( documentFilter . Scheme ) ;
84
86
}
87
+
85
88
if ( documentFilter . HasPattern )
86
89
{
87
90
items . Add ( documentFilter . Pattern ) ;
88
91
}
92
+
89
93
return $ "[{ string . Join ( ", " , items ) } ]";
90
94
}
91
95
@@ -95,33 +99,40 @@ public bool IsMatch(TextDocumentAttributes attributes)
95
99
{
96
100
return Language == attributes . LanguageId && Scheme == attributes . Scheme && _minimatcher . IsMatch ( attributes . Uri . ToString ( ) ) ;
97
101
}
102
+
98
103
if ( HasLanguage && HasPattern )
99
104
{
100
105
return Language == attributes . LanguageId && _minimatcher . IsMatch ( attributes . Uri . ToString ( ) ) ;
101
106
}
107
+
102
108
if ( HasLanguage && HasScheme )
103
109
{
104
110
return Language == attributes . LanguageId && Scheme == attributes . Scheme ;
105
111
}
112
+
106
113
if ( HasPattern && HasScheme )
107
114
{
108
115
return Scheme == attributes . Scheme && _minimatcher . IsMatch ( attributes . Uri . ToString ( ) ) ;
109
116
}
117
+
110
118
if ( HasLanguage )
111
119
{
112
120
return Language == attributes . LanguageId ;
113
121
}
122
+
114
123
if ( HasScheme )
115
124
{
116
125
return Scheme == attributes . Scheme ;
117
126
}
127
+
118
128
if ( HasPattern )
119
129
{
120
130
return _minimatcher . IsMatch ( attributes . Uri . ToString ( ) ) ;
121
131
}
122
132
123
133
return false ;
124
134
}
135
+
125
136
public bool Equals ( DocumentFilter other )
126
137
{
127
138
if ( ReferenceEquals ( null , other ) ) return false ;
@@ -134,7 +145,7 @@ public override bool Equals(object obj)
134
145
if ( ReferenceEquals ( null , obj ) ) return false ;
135
146
if ( ReferenceEquals ( this , obj ) ) return true ;
136
147
if ( obj . GetType ( ) != this . GetType ( ) ) return false ;
137
- return Equals ( ( DocumentFilter ) obj ) ;
148
+ return Equals ( ( DocumentFilter ) obj ) ;
138
149
}
139
150
140
151
public override int GetHashCode ( )
@@ -151,5 +162,9 @@ public override int GetHashCode()
151
162
public static bool operator == ( DocumentFilter left , DocumentFilter right ) => Equals ( left , right ) ;
152
163
153
164
public static bool operator != ( DocumentFilter left , DocumentFilter right ) => ! Equals ( left , right ) ;
165
+
166
+ private string DebuggerDisplay => ( string ) this ;
167
+ /// <inheritdoc />
168
+ public override string ToString ( ) => DebuggerDisplay ;
154
169
}
155
170
}
0 commit comments