Language Parser Space Requirements

已回答

Hey Guys,

I want to adjust the space settings of my custom language parser. Therefore I overwrote the spaceExistenceTypeBetweenTokens method of the ParserDefinition Interface and implemented my own logic. Unfortunately I noted that the method is never called. Here a simplified example which is not working for me. Does somebody know, what is going wrong here?

class ItemParserDefinition : ParserDefinition {
companion object {
val WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE)
val COMMENTS = TokenSet.create(ItemTypes.COMMENT)
val FILE = IFileElementType(ItemLanguage)
}

override fun createParser(project: Project?): PsiParser = ItemParser()
override fun createFile(viewProvider: FileViewProvider): PsiFile = ItemFile(viewProvider)
override fun getStringLiteralElements(): TokenSet = TokenSet.EMPTY
override fun getFileNodeType(): IFileElementType = FILE
override fun createLexer(project: Project?): Lexer = ItemLexerAdapter()
override fun createElement(node: ASTNode?): PsiElement = ItemTypes.Factory.createElement(node)
override fun getCommentTokens(): TokenSet = COMMENTS
override fun getWhitespaceTokens(): TokenSet = WHITE_SPACES
override fun spaceExistenceTypeBetweenTokens(left: ASTNode?, right: ASTNode?): ParserDefinition.SpaceRequirements =
ParserDefinition.SpaceRequirements.MUST_NOT
}

 

1

Philipp,

It's hard to guess, what's wrong with it looking just at the ParserDefinition implementation.

I'd suggest you debug your plugin and check the class which is calling spaceExistenceTypeBetweenTokens method: LanguageTokenSeparatorGenerators.

Maybe some conditions are not met. And if such class is not called as well, just go upper to CodeEditUtil.markToReformatBeforeOrInsertWhitespace(ASTNode, ASTNode) or InplaceVariableIntroducer.

0
Avatar
Permanently deleted user

Hi Jakub,

thanks for your feedback. I ran up the dependency tree and put breakpoint on all methods but could not recognized any call of the following functions:

1. ParserDefinition.spaceExistanceTypeBetweenTokens
2. LanguageTokenSeparatorGenerators.generateWhitespaceBetweenTokens
3. CodeEditUtil.markToReformatBeforeOrInsertWhitespace / AbstractInplaceIntroducer.constructor
4. CodeEditUtil.makePlaceHolderBetweenTokens
5. CodeEditUtil.addChildren / CodeEditUtil.replaceChild
6. CodeEditUtil.addChild
7. PsiFieldImpl.normalizeDeclaration / PsiLocalVariableImpl.normalizeDeclaration
8 -> Could not find further references

I also looked at the intellij-rust plugin to see the differences. I have set a breakpoint here, but I notice the same problem. The function is not called (or the debugger doesn't stop), at least in my build environment. Is my assumption correct that spaceExistanceTypeBetweenTokens should be called for every change in the editor?

Thanks!

 

1

I'm running into the same issue here, and also had the assumption that "spaceExistanceTypeBetweenTokens should be called for every change in the editor" - however, looking at the call tree, it seems to be only used when IntelliJ inserts/generates code automatically and want's to know what tokens should be used to separate elements? Could somebody provide some clarification on what the method is supposed to do / what it is intended to be used for?

0

请先登录再写评论。