jansorg / swift-plugin

Space of the Swift language support plugin for JetBrains IDEs
35 stars 0 forks source link

Strange Error Message w/ Swift Data Model #32

Closed rsarv3006 closed 2 months ago

rsarv3006 commented 2 months ago

This error only occurs using the Swift plugin. XCode and neovim don't show the same message. The app also builds just fine too.

image
@Model
public class Bedtime {
    public let id: UUID
    public let name: String
    public let bedtimeDay: BedtimeDay
    public let isActive: Bool
    public let notificationIdentifiers: [TimeInterval] = []
    public let bedtime: Time

    @Relationship(deleteRule: .cascade) var notificationSchedule: NotificationSchedule?

    @Relationship(deleteRule: .cascade, inverse: \NotificationItem.bedtime)
    var notificationItems = [NotificationItem]()

    public init(name: String, bedtimeDay: BedtimeDay, isActive: Bool, bedtime: Time) {
        self.id = UUID()
        self.name = name
        self.bedtimeDay = bedtimeDay
        self.isActive = isActive
        self.bedtime = bedtime
    }

    func addNotificationSchedule(notificationSchedule: NotificationSchedule) {
        self.notificationSchedule = notificationSchedule
    }

}

Let me know if I can provide more information!

EDIT: After further testing it's the inverse: \NotificationItem.Bedtime that is causing the issue.

jansorg commented 2 months ago

@rsarv3006 Thanks! I'm not a Swift expert (yet ;) , can you tell what the function of the backslash in \NotificationItem.Bedtime is? I couldn't find this in the official grammar. (Update: Probably a key path expression, right? I'll take a look at a fix)

jansorg commented 2 months ago

I've fixed the parsing of key path expressions for the next update.

rsarv3006 commented 2 months ago

@jansorg Thank you for taking a look at this! I'm not surprised documentation was hard to find since it's part of SwiftData. I'll see if I can find the original doc where I found the code example I used to build this.

Thanks again. I love this plugin it's awesome!