|
| 1 | +/* |
| 2 | + * Copyright (c) 2017. tangzx(love.tangzx@qq.com) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.tang.intellij.lua.spellchecker |
| 18 | + |
| 19 | +import com.intellij.psi.PsiElement |
| 20 | +import com.intellij.spellchecker.inspections.PlainTextSplitter |
| 21 | +import com.intellij.spellchecker.tokenizer.EscapeSequenceTokenizer |
| 22 | +import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy |
| 23 | +import com.intellij.spellchecker.tokenizer.TokenConsumer |
| 24 | +import com.intellij.spellchecker.tokenizer.Tokenizer |
| 25 | +import com.tang.intellij.lua.comment.psi.LuaDocTypes |
| 26 | +import com.tang.intellij.lua.lang.LuaLanguage |
| 27 | +import com.tang.intellij.lua.psi.LuaTypes |
| 28 | + |
| 29 | +class LuaSpellcheckingStrategy : SpellcheckingStrategy() { |
| 30 | + override fun isMyContext(element: PsiElement): Boolean { |
| 31 | + return element.language is LuaLanguage |
| 32 | + } |
| 33 | + |
| 34 | + override fun getTokenizer(element: PsiElement): Tokenizer<*> { |
| 35 | + return when(element.node.elementType){ |
| 36 | + LuaDocTypes.STRING -> StringLiteralTokenizer |
| 37 | + LuaDocTypes.WORD -> TEXT_TOKENIZER |
| 38 | + LuaTypes.ID -> TEXT_TOKENIZER |
| 39 | + LuaTypes.STRING -> StringLiteralTokenizer |
| 40 | + else -> super.getTokenizer(element) |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +private object StringLiteralTokenizer : EscapeSequenceTokenizer<PsiElement>() { |
| 47 | + |
| 48 | + override fun tokenize(element: PsiElement, consumer: TokenConsumer) { |
| 49 | + consumer.consumeToken(element, PlainTextSplitter.getInstance()) |
| 50 | + } |
| 51 | +} |
0 commit comments