Merge pull request #12 from JohnSundell/self-as-static-property

Highlight ‘self’ as keyword when used to refer to a type
This commit is contained in:
John Sundell 2018-08-27 19:02:08 +02:00 committed by GitHub
commit b8584cd396
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View File

@ -276,6 +276,10 @@ private extension SwiftGrammar {
return false
}
guard segment.tokens.current != "self" else {
return false
}
return segment.tokens.onSameLine.first != "import"
}
}
@ -292,15 +296,13 @@ private extension SwiftGrammar {
return false
}
guard !segment.prefixedByDotAccess else {
guard segment.tokens.current != "self" else {
return false
}
if let previousToken = segment.tokens.previous {
guard !keywords.contains(previousToken) else {
guard !segment.prefixedByDotAccess else {
return false
}
}
return segment.tokens.onSameLine.first != "import"
}

View File

@ -88,6 +88,19 @@ final class FunctionCallTests: SyntaxHighlighterTestCase {
])
}
func testPassingTypeToFunction() {
let components = highlighter.highlight("call(String.self)")
XCTAssertEqual(components, [
.token("call", .call),
.plainText("("),
.token("String", .type),
.plainText("."),
.token("self", .keyword),
.plainText(")")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
@ -101,7 +114,8 @@ extension FunctionCallTests {
("testExplicitInitializerCall", testExplicitInitializerCall),
("testAccessingPropertyAfterFunctionCallWithoutArguments", testAccessingPropertyAfterFunctionCallWithoutArguments),
("testAccessingPropertyAfterFunctionCallWithArguments", testAccessingPropertyAfterFunctionCallWithArguments),
("testCallingStaticMethodOnGenericType", testCallingStaticMethodOnGenericType)
("testCallingStaticMethodOnGenericType", testCallingStaticMethodOnGenericType),
("testPassingTypeToFunction", testPassingTypeToFunction)
]
}
}