Highlight.js: (swift) does not recognize core Apple foundational libraries

Created on 16 Oct 2020  路  10Comments  路  Source: highlightjs/highlight.js

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
    }
}
auto-detect bug good first issue help welcome language

All 10 comments

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.

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)

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?

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.

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.

@AustinConlon Ping.

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

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

Will do.

And if you happened to have the time: https://github.com/highlightjs/highlight.js/issues/2819 :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhouxy666 picture zhouxy666  路  3Comments

sustained picture sustained  路  4Comments

Suyash2810 picture Suyash2810  路  8Comments

gka picture gka  路  7Comments

alainbryden picture alainbryden  路  4Comments