Clickable area range for reference

Answered

Hello, I have two variants for keys in language that I'm implementing. It can be in quotes as string or without quotes:

withoutQuotes: value
"withQuotes": value

Psi structure without quotes is:

KeyImpl([Lang] KEY)
ScalarImpl([Lang] SCALAR)
PsiElement([Lang] T_IDENTIFIER)('withoutQuotes')
PsiElement([Lang] T_COLON)(':')

And with quotes is:

KeyImpl([Lang] KEY)
StringImpl([Lang] STRING)
PsiElement([Lang] T_DOUBLE_QUOTE_LEFT)('"')
PsiElement([Lang] T_STRING)('withQuotes')
PsiElement([Lang] T_DOUBLE_QUOTE_RIGHT)('"')
PsiElement([Lang] T_COLON)(':')

`KeyImpl` implements `PsiNameIdentifierOwner` and in method `getNameIdentifier` returns: `T_IDENTIFIER` or `T_STRING` for quoted variant. This language can use references to this keys like: %withoutQuotes% or %withQuotes%. For this parameters exists reference registered in ReferenceContributor. And for keys exists FindUsagesProvider.

If I move caret to some parameter, then key is highlighted correctly (in quoted variant is too highlighted T_STRING). And if I move caret to some key, parameter is highlighted correctly.

But if I move caret inside string, for example: "withQ|uotes", nothing is highlighted and `withQuotes` is not clickable for find usages. Only if I move caret before/after first " (T_DOUBLE_QUOTE_LEFT) it is working correctly. And first " is also clickable and working as expected for `withQuotes` identifier.

How to expand clickable and highlight area for key in quotes if caret is inside like: "withQ|uotes"?

 

2 comments
Comment actions Permalink

Hi Matouš,

Did you override PsiElement.getTextOffset() as PsiNamedIdentifierOwner's JavaDoc states?

0
Comment actions Permalink

Karol Lewandowski Hi, nice thank you. It works :)

0

Please sign in to leave a comment.