Skip to content

Commit 38a971f

Browse files
authored
Merge pull request #35 from chenfeng11111/main
支持拼写检查
2 parents d03cfad + 4fa1313 commit 38a971f

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.spellchecker
18+
19+
import com.intellij.spellchecker.BundledDictionaryProvider
20+
21+
class LuaSpellBundledDictionaryProvider : BundledDictionaryProvider {
22+
override fun getBundledDictionaries() = arrayOf("/spellchecker/lua.dic")
23+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.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+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
<!-- LSP 颜色配置页面 -->
7474
<colorSettingsPage implementation="com.tang.intellij.lua.highlighting.LuaLspColorSettingsPage"/>
7575

76+
<spellchecker.support implementationClass="com.tang.intellij.lua.spellchecker.LuaSpellcheckingStrategy" language="Lua"/>
77+
<spellchecker.bundledDictionaryProvider implementation="com.tang.intellij.lua.spellchecker.LuaSpellBundledDictionaryProvider"/>
78+
7679
<!-- <readWriteAccessDetector implementation="com.tang.intellij.lua.codeInsight.LuaReadWriteAccessDetector"/> -->
7780

7881
<!-- debugger-->
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
acos
2+
asin
3+
atan
4+
collectgarbage
5+
coroutine
6+
cpath
7+
difftime
8+
dofile
9+
fmod
10+
frexp
11+
getfenv
12+
gethook
13+
getinfo
14+
getmetatable
15+
getregistry
16+
getupvalue
17+
gmatch
18+
gsub
19+
ipairs
20+
ldexp
21+
loadfile
22+
loadlib
23+
loadstring
24+
maxn
25+
metatable
26+
modf
27+
newindex
28+
pcall
29+
popen
30+
randomseed
31+
rawequal
32+
rawget
33+
rawset
34+
seeall
35+
setfenv
36+
sethook
37+
setlocal
38+
setlocale
39+
setmetatable
40+
setupvalue
41+
setuservalue
42+
setvbuf
43+
sinh
44+
tanh
45+
tmpfile
46+
tmpname
47+
tonumber
48+
tostring
49+
tostring
50+
traceback
51+
upvalueid
52+
upvaluejoin
53+
xpcall

0 commit comments

Comments
 (0)