1+ /*
2+ * Copyright (c) 2017. tangzx([email protected] ) 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.editor
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.lang.LuaLanguage
26+ import com.tang.intellij.lua.psi.LuaLiteralExpr
27+ import com.tang.intellij.lua.psi.LuaLiteralKind
28+ import com.tang.intellij.lua.psi.LuaTypes
29+ import com.tang.intellij.lua.psi.kind
30+
31+ class LuaSpellcheckingStrategy : SpellcheckingStrategy () {
32+ override fun isMyContext (element : PsiElement ): Boolean {
33+ return element.language is LuaLanguage
34+ }
35+
36+ override fun getTokenizer (element : PsiElement ? ): Tokenizer <* > {
37+ if (element?.node?.elementType == LuaTypes .LITERAL_EXPR )
38+ return StringLiteralTokenizer
39+ return super .getTokenizer(element)
40+ }
41+ }
42+
43+ object StringLiteralTokenizer : EscapeSequenceTokenizer<LuaLiteralExpr>() {
44+
45+ override fun tokenize (element : LuaLiteralExpr , consumer : TokenConsumer ) {
46+ if (element.kind == LuaLiteralKind .String ) {
47+ consumer.consumeToken(element, PlainTextSplitter .getInstance())
48+ }
49+ }
50+ }
0 commit comments