NSHipster / SwiftSyntaxHighlighter

A syntax highlighter for Swift code that uses SwiftSyntax to generate Pygments-compatible HTML.
https://nshipster.com/swiftsyntax/
MIT License
275 stars 12 forks source link

Type detection has false positives and false negatives #5

Closed belkadan closed 3 years ago

belkadan commented 4 years ago

https://github.com/NSHipster/SwiftSyntaxHighlighter/blob/dca53e3e9063cef8f4e591ee9d8ee0cb32a3b925/Sources/TokenizationSchemes/Xcode/Xcode.swift#L15-L33

In this code, the where clause only applies to the .leftSquareBracket case, but not all (say) members are types. Beyond that, though, the capitalized property lowercases all further letters, meaning something like "UnsafePointer" wouldn't pass the test.

mattt commented 4 years ago

Taking another look at this, I think the trailing where in the final case was intentional, but should also apply to .period as well (to cover nested type names). You're absolutely right about the incorrect capitalization check, though. Should be an easy fix. I'll get a PR started for this.

Edit: See #6

belkadan commented 4 years ago

Colon seems like it needs the same check, because of dictionary literals. (Really, I would hope that anywhere : indicates a type, it's already a typeIdentifier node kind, but I'm not sure if libSyntax actually does this.)