Files
helder/Sources/HelderCore/Symbols/SymbolModels.swift
T

67 lines
2.2 KiB
Swift

import Foundation
/// One class, interface, trait or enum declaration.
public struct SymbolDef: Sendable, Equatable, Codable {
public var name: String
public var path: String
public var line: Int
/// `class`, `interface`, `trait` or `enum`.
public var kind: String
/// The file's namespace, for the fully qualified name; "" when none.
public var namespace: String
/// `extends` on the declaration line, short names.
public var parents: [String]
/// `implements` on the declaration line, short names.
public var interfaces: [String]
/// Traits mixed in by an indented `use` in the body.
public var traits: [String]
public init(name: String, path: String, line: Int, kind: String, namespace: String = "",
parents: [String] = [], interfaces: [String] = [], traits: [String] = []) {
self.name = name
self.path = path
self.line = line
self.kind = kind
self.namespace = namespace
self.parents = parents
self.interfaces = interfaces
self.traits = traits
}
public var qualifiedName: String { namespace.isEmpty ? name : namespace + "\\" + name }
}
/// References to one name within one file.
public struct RefGroup: Sendable, Equatable {
public var path: String
public var hits: [ContentHit]
public init(path: String, hits: [ContentHit]) {
self.path = path
self.hits = hits
}
}
/// What a ⌘-click on a class name returns: where it is declared and where it is used.
public struct SymbolLookup: Sendable, Equatable {
public var name: String
public var definitions: [SymbolDef]
public var references: [RefGroup]
public var referenceCount: Int
public init(name: String, definitions: [SymbolDef] = [], references: [RefGroup] = [], referenceCount: Int = 0) {
self.name = name
self.definitions = definitions
self.references = references
self.referenceCount = referenceCount
}
public static func empty(_ name: String) -> SymbolLookup { SymbolLookup(name: name) }
}
public enum SymbolLimits {
public static let maxDefinitions = 25
public static let maxReferenceFiles = 300
public static let maxLineLength = 1000
}