Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(swift) does not recognize core Apple foundational libraries #2758

Closed
AustinConlon opened this issue Oct 16, 2020 · 16 comments · Fixed by #2920
Closed

(swift) does not recognize core Apple foundational libraries #2758

AustinConlon opened this issue Oct 16, 2020 · 16 comments · Fixed by #2920
Labels
auto-detect Issue with auto detection of language type bug good first issue Should be easier for first time contributors help welcome Could use help from community language

Comments

@AustinConlon
Copy link

I found this while writing this on Stack Overflow. I'm not sure what the root of the problem is, but I'm guessing it starts in the function signature. Here's the code:

func configuredGridCell() -> UICollectionView.CellRegistration<UICollectionViewCell, Emoji> {
    return UICollectionView.CellRegistration<UICollectionViewCell, Emoji> { (cell, indexPath, emoji) in
        var content = UIListContentConfiguration.cell()
        content.text = emoji.text
        content.textProperties.font = .boldSystemFont(ofSize: 38)
        content.textProperties.alignment = .center
        content.directionalLayoutMargins = .zero
        cell.contentConfiguration = content
        var background = UIBackgroundConfiguration.listPlainCell()
        background.cornerRadius = 8
        background.strokeColor = .systemGray3
        background.strokeWidth = 1.0 / cell.traitCollection.displayScale
        cell.backgroundConfiguration = background
    }
}
@AustinConlon AustinConlon added bug help welcome Could use help from community language labels Oct 16, 2020
@joshgoebel
Copy link
Member

Screen Shot 2020-10-15 at 9 10 28 PM

Looks good to me... you need to tell it your code is Swift... otherwise it's auto-detected as ObjectiveC and that's obviously not doing what you wanted.

@joshgoebel
Copy link
Member

joshgoebel commented Oct 16, 2020

Are all the same built-in classes equally valid in Swift as in ObjC?

  var API_CLASS = {
    className: 'built_in',
    begin: '\\b(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)\\w+',
  };

Right now Swift doesn't get any points for them while ObjC does which is why your code is being flagged as ObjC. (so many library mentions)

@AustinConlon
Copy link
Author

you need to tell it your code is Swift

Since I encountered this as a Stack Overflow user, does this mean the question has to have the Swift tag?

@AustinConlon
Copy link
Author

Are all the same built-in classes equally valid in Swift as in ObjC?

  var API_CLASS = {
    className: 'built_in',
    begin: '\\b(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)\\w+',
  };

Right now Swift doesn't get any points for them while ObjC does which is why your code is being flagged as ObjC. (so many library mentions)

There are a few new frameworks like WidgetKit which are Swift-only, but I'm not sure if that's part of the problem.

@joshgoebel
Copy link
Member

joshgoebel commented Oct 16, 2020

Damn, my question was too broad. :-) All all the class prefixes listed there valid for use in Swift code also? I think you're saying the answer is yes?

I'm thinking we should add them to our Swift grammar so they can be highlighted and help out for auto-detecting, yes? Right now swift is highlighting them as "types" but they have no relevance score, so it doesn't make it more likely that your code is Swift like it would if we added those API classes as an explicit list.

@joshgoebel joshgoebel added the good first issue Should be easier for first time contributors label Oct 16, 2020
@joshgoebel joshgoebel changed the title Swift generic structure initialization with handler breaks syntax highlighting (swift) does not recognize core Apple foundational libraries Oct 16, 2020
@joshgoebel joshgoebel added the auto-detect Issue with auto detection of language type label Oct 16, 2020
@joshgoebel
Copy link
Member

@AustinConlon Ping.

@AustinConlon
Copy link
Author

Yup, all of the frameworks for those prefixes are Swift as well, none are exclusive to Objective-C.

@joshgoebel
Copy link
Member

@AustinConlon Want to take a pass at making a PR to pull over that rule from Objective-C, and balance the languages out?

@AustinConlon
Copy link
Author

Will do.

@joshgoebel
Copy link
Member

And if you happened to have the time: #2819 :-)

@joshgoebel
Copy link
Member

joshgoebel commented Dec 10, 2020

@svanimpe Any chance you might be willing to tackle this also? Should be easy.

@svanimpe
Copy link
Contributor

I would prefer not to highlight these classes any differently. They are imported Objective-C types, not "built-in" to Swift in any way, and we don't even highlight the built-in types from the Standard Library.

Is it not enough that they're highlighted as types?

@joshgoebel
Copy link
Member

The Foundational libraries are used often in both ObjC and Swift code so seeing them doesn't imply one language on the
other. They need to be added for their relevance, even if not highlighting.

Honestly I'd consider them in the same category of built-ins... thinking about Swift as a larger platform and what code is COMMON, not just the language itself. But at the very least we need the relevance to fix issues with ObjC claiming Swift code just because a lot of foundational classes are used.

@svanimpe
Copy link
Contributor

So I could for example, highlight them as types, but match them separately for a relevance boost?

Import statements could also be relevance boosters:

import Foundation
import UIKit
import AppKit
import SwiftUI

However, since we're talking about highlighting code snippets here (not full projects), it's unlikely that these are present.

@joshgoebel
Copy link
Member

Import statements could also be relevance boosters:

Many languages have imports though... it's the very unique apple names that matter, not the imports themselves.

However, since we're talking about highlighting code snippets here (not full projects), it's unlikely that these are present.

Exactly.

@joshgoebel
Copy link
Member

So I could for example, highlight them as types, but match them separately for a relevance boost?

Sounds like a start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-detect Issue with auto detection of language type bug good first issue Should be easier for first time contributors help welcome Could use help from community language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants