Skip to content

Commit

Permalink
Add support to ffi_cdata and ffi_scope in phpdoc (#8)
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
Danil42Russia authored May 23, 2022
1 parent 208779e commit e53da15
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ExPhpTypeCompletionProvider : CompletionProvider<CompletionParameters>() {
result.addElement(LookupElementBuilder.create("future"))
result.addElement(LookupElementBuilder.create("future_queue"))
result.addElement(LookupElementBuilder.create("any"))
result.addElement(LookupElementBuilder.create("ffi_cdata"))
result.addElement(LookupElementBuilder.create("ffi_scope"))

// "Cassandra\Tuple" messes with our 'tuple', I don't want it to be seen, filter it out
// same for some others also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ internal object TokensToExPhpTypePsiParsing {
}
}

private fun parseFfiContents(builder: PhpPsiBuilder): Boolean {
if (!builder.compareAndEat(PhpDocTokenTypes.DOC_LAB))
return !builder.expected("<")

while (true) {
if (builder.compareAndEat(PhpDocTokenTypes.DOC_TEXT) ||
builder.compareAndEat(PhpDocTokenTypes.DOC_COMMA) ||
builder.compareAndEat(PhpDocTokenTypes.DOC_IDENTIFIER)
)
continue

if (builder.compareAndEat(PhpDocTokenTypes.DOC_RAB))
return true

return builder.expected(">")
}
}

private fun parseTypedCallableContents(builder: PhpPsiBuilder): Boolean {
if (!builder.compareAndEat(PhpDocTokenTypes.DOC_LPAREN))
return !builder.expected("(")
Expand Down Expand Up @@ -183,6 +201,17 @@ internal object TokensToExPhpTypePsiParsing {
return true
}

if (builder.compare(PhpDocTokenTypes.DOC_IDENTIFIER) && (builder.tokenText == "ffi_cdata" || builder.tokenText == "ffi_scope")) {
val marker = builder.mark()
builder.advanceLexer()
if (!parseFfiContents(builder)) {
marker.drop()
return false
}
marker.done(ExPhpTypeAnyPsiImpl.elementType)
return true
}

if (builder.compare(PhpDocTokenTypes.DOC_IDENTIFIER) && builder.tokenText == "callable" && builder.rawLookup(1) == PhpDocTokenTypes.DOC_LPAREN) {
val marker = builder.mark()
builder.advanceLexer()
Expand Down

0 comments on commit e53da15

Please sign in to comment.