I'm trying to get auto-import to work in the Gosu plugin. I'm pretty close, but I have a problem getting the old error annotations to disappear after the fix is applied.
Here is the bindToElement() code for a TypeLiteral in Gosu:
public PsiElement bindToElement( PsiElement element ) throws IncorrectOperationException
GosuFile initialFile = (GosuFile)getContainingFile();
PsiElement elt = GosuPsiParseUtil.parseExpression( ((PsiQualifiedNamedElement)element).getQualifiedName(), getManager() );
if( elt instanceof GosuTypeLiteralImpl )
GosuTypeLiteralImpl tl = (GosuTypeLiteralImpl)elt;
if( element instanceof PsiQualifiedNamedElement )
PsiElement shortName = GosuPsiParseUtil.parseRelativeTypeLiteral( ((PsiQualifiedNamedElement)element).getQualifiedName(), getManager() );
initialFile.addImport( tl );
replace( shortName );
replace( elt );
We replace the PSI and everything looks pretty good at the text level, but unfortunately the old error annotations stick around (pointing to bad offsets.) The only way I can get the annotations to update is to delete (not add) text from within the function.
I'm still poking around, but I was hoping someone might chime in with a "Oh, you need to mark the file as needing a full reparse" or something...