Skip to content

Commit 7b09419

Browse files
committed
Fix duplicate commands are created
1 parent 214513a commit 7b09419

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

EditorExtension/SourceEditorExtension.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func customCommands() -> [[XCSourceEditorCommandDefinitionKey: Any]] {
7979
[
8080
XCSourceEditorCommandDefinitionKey.classNameKey: CustomCommand.className(),
8181
XCSourceEditorCommandDefinitionKey
82-
.identifierKey: identifierPrefix + "CustomCommand\($0.name.hashValue)",
82+
.identifierKey: identifierPrefix + "CustomCommand\($0.name.sha1HexString)",
8383
.nameKey: $0.name,
8484
]
8585
}
@@ -94,3 +94,21 @@ func customCommands() -> [[XCSourceEditorCommandDefinitionKey: Any]] {
9494

9595
return definitions
9696
}
97+
98+
import CryptoKit
99+
100+
// CryptoKit.Digest utils
101+
extension Digest {
102+
var bytes: [UInt8] { Array(makeIterator()) }
103+
var data: Data { Data(bytes) }
104+
105+
var hexStr: String {
106+
bytes.map { String(format: "%02X", $0) }.joined()
107+
}
108+
}
109+
110+
extension String {
111+
var sha1HexString: String {
112+
Insecure.SHA1.hash(data: data(using: .utf8) ?? Data()).hexStr
113+
}
114+
}

0 commit comments

Comments
 (0)