Skip to content

Commit 947ccb0

Browse files
feat: associate .psql and .pgsql files with the SQL editor (#1641)
* feat: associate .psql and .pgsql files with the SQL editor * feat(editor): route .psql and .pgsql files through SQL open paths --------- Co-authored-by: Ngô Quốc Đạt <datlechin@gmail.com>
1 parent 7a10b8e commit 947ccb0

6 files changed

Lines changed: 19 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- BigQuery datasets can be switched from the toolbar, the Cmd+K switcher, and the File menu, including creating and dropping datasets. (#509)
13+
- `.psql` and `.pgsql` files now open in the SQL editor like `.sql`: Finder double-click, the open and save panels, and linked SQL folders all accept them. (#1641)
1314

1415
### Changed
1516

TablePro/Core/Services/Infrastructure/SQLFileService.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import UniformTypeIdentifiers
1313
enum SQLFileService {
1414
private static let logger = Logger(subsystem: "com.TablePro", category: "SQLFileService")
1515

16+
static let supportedExtensions: Set<String> = ["sql", "psql", "pgsql"]
17+
18+
private static var allowedContentTypes: [UTType] {
19+
let types = Set(supportedExtensions.compactMap { UTType(filenameExtension: $0) })
20+
return types.isEmpty ? [.plainText] : Array(types)
21+
}
22+
1623
/// Reads a SQL file from disk.
1724
static func readFile(url: URL) async throws -> String {
1825
try await Task.detached {
@@ -34,7 +41,7 @@ enum SQLFileService {
3441
@MainActor
3542
static func showOpenPanel() async -> [URL]? {
3643
let panel = NSOpenPanel()
37-
panel.allowedContentTypes = [UTType(filenameExtension: "sql") ?? .plainText]
44+
panel.allowedContentTypes = allowedContentTypes
3845
panel.allowsMultipleSelection = true
3946
panel.message = String(localized: "Select SQL files to open")
4047
let response = await panel.begin()
@@ -46,7 +53,7 @@ enum SQLFileService {
4653
@MainActor
4754
static func showSavePanel(suggestedName: String = "query.sql") async -> URL? {
4855
let panel = NSSavePanel()
49-
panel.allowedContentTypes = [UTType(filenameExtension: "sql") ?? .plainText]
56+
panel.allowedContentTypes = allowedContentTypes
5057
panel.canCreateDirectories = true
5158
panel.nameFieldStringValue = suggestedName
5259
panel.message = String(localized: "Save SQL file")

TablePro/Core/Services/Infrastructure/URLClassifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal enum URLClassifier {
2828
if ext == "tablepro" {
2929
return .success(.openConnectionShare(url))
3030
}
31-
if ext == "sql" {
31+
if SQLFileService.supportedExtensions.contains(ext) {
3232
return .success(.openSQLFile(url))
3333
}
3434
if PluginManager.shared.allInspectorFileExtensions.contains(ext) {

TablePro/Core/Services/SQL/SQLFolderWatcher.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ internal final class SQLFolderWatcher {
152152
var indexed: [LinkedSQLIndex.IndexedFile] = []
153153

154154
for case let url as URL in enumerator {
155-
guard url.pathExtension.lowercased() == "sql" else { continue }
155+
guard SQLFileService.supportedExtensions.contains(url.pathExtension.lowercased()) else { continue }
156156

157157
let resourceValues = try? url.resourceValues(forKeys: [
158158
.isRegularFileKey, .contentModificationDateKey, .fileSizeKey

TablePro/Info.plist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<key>CFBundleTypeExtensions</key>
1515
<array>
1616
<string>sql</string>
17+
<string>psql</string>
18+
<string>pgsql</string>
1719
</array>
1820
<key>CFBundleTypeIconSystemGenerated</key>
1921
<true/>
@@ -154,6 +156,8 @@
154156
<key>public.filename-extension</key>
155157
<array>
156158
<string>sql</string>
159+
<string>psql</string>
160+
<string>pgsql</string>
157161
</array>
158162
</dict>
159163
</dict>

TableProTests/Core/Services/Infrastructure/URLClassifierTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ struct URLClassifierTests {
5050
#expect(intent == nil)
5151
}
5252

53-
@Test("SQL file routes to openSQLFile")
54-
func routesSQLFile() {
55-
let sqlURL = URL(fileURLWithPath: "/tmp/query.sql")
53+
@Test("SQL file routes to openSQLFile", arguments: ["sql", "psql", "pgsql", "PSQL"])
54+
func routesSQLFile(ext: String) {
55+
let sqlURL = URL(fileURLWithPath: "/tmp/query.\(ext)")
5656
let intent = URLClassifier.classify(sqlURL)
5757
guard case .some(.success(.openSQLFile(let routed))) = intent else {
5858
Issue.record("Expected .openSQLFile, got \(String(describing: intent))")

0 commit comments

Comments
 (0)