|
23 | 23 | namespace Microsoft.Python.Analysis.Analyzer { |
24 | 24 | [DebuggerDisplay("{Name} : {FilePath}")] |
25 | 25 | internal readonly struct AnalysisModuleKey : IEquatable<AnalysisModuleKey> { |
26 | | - private enum KeyType { Default, Typeshed, LibraryAsDocument } |
27 | | - |
28 | | - private readonly KeyType _type; |
29 | 26 | public string Name { get; } |
30 | 27 | public string FilePath { get; } |
31 | | - public bool IsTypeshed => _type == KeyType.Typeshed; |
32 | | - public bool IsLibraryAsDocument => _type == KeyType.LibraryAsDocument; |
| 28 | + public bool IsTypeshed { get; } |
| 29 | + public bool IsNonUserAsDocument { get; } |
33 | 30 |
|
34 | 31 | public AnalysisModuleKey(IPythonModule module) { |
35 | 32 | Name = module.Name; |
36 | 33 | FilePath = module.ModuleType == ModuleType.CompiledBuiltin ? null : module.FilePath; |
37 | | - _type = module is StubPythonModule stub && stub.IsTypeshed |
38 | | - ? KeyType.Typeshed |
39 | | - : module.ModuleType == ModuleType.Library && module is IDocument document && document.IsOpen |
40 | | - ? KeyType.LibraryAsDocument |
41 | | - : KeyType.Default; |
| 34 | + IsTypeshed = module is StubPythonModule stub && stub.IsTypeshed; |
| 35 | + IsNonUserAsDocument = (module.IsNonUserFile() || module.IsCompiled()) && module is IDocument document && document.IsOpen; |
42 | 36 | } |
43 | 37 |
|
44 | | - public AnalysisModuleKey(string name, string filePath, bool isTypeshed) { |
45 | | - Name = name; |
46 | | - FilePath = filePath; |
47 | | - _type = isTypeshed ? KeyType.Typeshed : KeyType.Default; |
48 | | - } |
| 38 | + public AnalysisModuleKey(string name, string filePath, bool isTypeshed) |
| 39 | + : this(name, filePath, isTypeshed, false) { } |
49 | 40 |
|
50 | | - private AnalysisModuleKey(string name, string filePath, KeyType type) { |
| 41 | + private AnalysisModuleKey(string name, string filePath, bool isTypeshed, bool isNonUserAsDocument) { |
51 | 42 | Name = name; |
52 | 43 | FilePath = filePath; |
53 | | - _type = type; |
| 44 | + IsTypeshed = isTypeshed; |
| 45 | + IsNonUserAsDocument = isNonUserAsDocument; |
54 | 46 | } |
55 | 47 |
|
56 | | - public AnalysisModuleKey GetLibraryAsDocumentKey() => new AnalysisModuleKey(Name, FilePath, KeyType.LibraryAsDocument); |
| 48 | + public AnalysisModuleKey GetNonUserAsDocumentKey() => new AnalysisModuleKey(Name, FilePath, IsTypeshed, true); |
57 | 49 |
|
58 | 50 | public bool Equals(AnalysisModuleKey other) |
59 | | - => Name.EqualsOrdinal(other.Name) && FilePath.PathEquals(other.FilePath) && _type == other._type; |
| 51 | + => Name.EqualsOrdinal(other.Name) && FilePath.PathEquals(other.FilePath) && IsTypeshed == other.IsTypeshed && IsNonUserAsDocument == other.IsNonUserAsDocument; |
60 | 52 |
|
61 | 53 | public override bool Equals(object obj) => obj is AnalysisModuleKey other && Equals(other); |
62 | 54 |
|
63 | 55 | public override int GetHashCode() { |
64 | 56 | unchecked { |
65 | | - var hashCode = (Name != null ? Name.GetHashCode() : 0); |
| 57 | + var hashCode = Name != null ? Name.GetHashCode() : 0; |
66 | 58 | hashCode = (hashCode * 397) ^ (FilePath != null ? FilePath.GetPathHashCode() : 0); |
67 | | - hashCode = (hashCode * 397) ^ _type.GetHashCode(); |
| 59 | + hashCode = (hashCode * 397) ^ IsTypeshed.GetHashCode(); |
| 60 | + hashCode = (hashCode * 397) ^ IsNonUserAsDocument.GetHashCode(); |
68 | 61 | return hashCode; |
69 | 62 | } |
70 | 63 | } |
|
0 commit comments