Skip to content

Commit c2af137

Browse files
committed
spell checker support
1 parent 36b96a5 commit c2af137

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@
136136
<psi.referenceContributor language="Lua" implementation="com.tang.intellij.lua.reference.LuaReferenceContributor"/>
137137
<languageInjector implementation="com.tang.intellij.lua.lang.LuaLanguageInjector"/>
138138

139+
<spellchecker.support implementationClass="com.tang.intellij.lua.editor.LuaSpellcheckingStrategy" language="Lua"/>
140+
139141
<!--usage-->
140142
<lang.findUsagesProvider language="Lua" implementationClass="com.tang.intellij.lua.usages.LuaFindUsagesProvider"/>
141143
<findUsagesHandlerFactory implementation="com.tang.intellij.lua.usages.LuaFindUsagesHandlerFactory"/>

0 commit comments

Comments
 (0)