glato / emerge

Emerge is a browser-based interactive codebase and dependency visualization tool for many different programming languages. It supports some basic code quality and graph metrics and provides a simple and intuitive way to explore and analyze a codebase by using graph structures.
MIT License
783 stars 46 forks source link

Improve support for Swift language #12

Closed Andrea-Scuderi closed 2 years ago

Andrea-Scuderi commented 2 years ago
  1. Some Swift language entities and properties are missing
  1. Swift Entities dependencies are not evaluated when used as static

example:

class A {
 static let shared = A()

 func doSomething() {
  print("A")
 }
}

class B {
 func doSomethingWithA() {
  A.shared.doSomething()
 }
}

The class B depends from A, but the relation is not implemented in the output.

Proposed output

Consider the following valid swift example:

protocol Naming {
    var name: String { get set }
}

protocol Describing {
    var describing: String { get }
}

class ClassA: Naming & Describing {

    static let shared = ClassA()

    var name: String = "A"
    let id: UUID = UUID()
    var describing: String = "Class A"
}

class ClassB: ClassA {
    func show() {
        print(name)
    }
}

enum EnumA {
    case one
    case two(EnumB)
}

enum EnumB: String, Describing {
    case one
    case two

    var describing: String {
        self.rawValue
    }
}

struct StructC<T: Naming>: Describing {
    var name: String = "C"
    let state: EnumA = .one
    var generic: T

    var describing: String = "Class C"

    init(generic: T) {
        self.generic = generic
    }
}

public struct EmergeSwiftTest {
    public private(set) var text = "Hello, World!"

    var b = ClassB()
    let eB: EnumB = .one
    let eA = EnumA.two(.one)

    func show() {
        b.show()
        print(ClassA.shared.name)
    }
}

actual output:

Screenshot 2022-01-15 at 19 53 15

desired output:

note:

I've prepared a version solving the point 1. Happy to do a PR if you are interested. Not sure how to sort out point 2 though.

glato commented 2 years ago

Hi @Andrea-Scuderi 👋, thank you for the interesting ideas and enhancements, I'd appreciate any contribution and help. If you've already prepared a PR to solve point 1, I'd be happy to review/test/merge your solution. I'll try to come up with an approach for point 2 in the following days.

glato commented 2 years ago

@Andrea-Scuderi I've merged your PR #13, will try to follow up on an approach for point 2 in a couple of days.

Andrea-Scuderi commented 2 years ago

Thanks! Actually there is also another nasty case, nested entities: https://docs.swift.org/swift-book/LanguageGuide/NestedTypes.html

glato commented 2 years ago

@Andrea-Scuderi I've been doing some updates on the swift-parser and the modularity metric in general. The next release (together with your last contribution) will have some more Swift enhancements and bugfixes, stay tuned. A small teaser: 1 Swift project, 5 different graph types with different modularity.

CleanShot 2022-02-01 at 21 33 02@2x CleanShot 2022-02-01 at 21 33 13@2x CleanShot 2022-02-01 at 21 33 32@2x CleanShot 2022-02-01 at 21 33 48@2x CleanShot 2022-02-01 at 21 34 04@2x
glato commented 2 years ago

@Andrea-Scuderi The last release 1.1.0 includes your swift enhancements with further, smaller bugfixes related to parsing and graph types. Hence I'm closing this issue. Nevertheless we still have no support for nested entities. Either we probably would have to define the pyparsing syntax in another way to match such recursive structures or find another way to extract them. This could be a more complex issue, but I'll try to think about some approach to deal with this.

glato commented 2 years ago

@Andrea-Scuderi we could of course also work together in a follow up issue to solve this 💪?