Skip to content

Commit ae246ef

Browse files
committed
clean code
1 parent db7a862 commit ae246ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+573
-485
lines changed

src/main/java/com/tang/intellij/lua/actions/CreateLuaFileAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package com.tang.intellij.lua.actions
22

33
import com.intellij.ide.actions.CreateFileFromTemplateAction
44
import com.intellij.ide.actions.CreateFileFromTemplateDialog
5+
import com.intellij.openapi.project.DumbAware
6+
import com.intellij.openapi.project.Project
57
import com.intellij.psi.PsiDirectory
68
import com.tang.intellij.lua.lang.LuaIcons
7-
import com.intellij.openapi.project.DumbAware;
8-
import com.intellij.openapi.project.Project;
99

1010

1111
/**

src/main/java/com/tang/intellij/lua/annotator/LuaLspExternalAnnotator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import java.util.concurrent.TimeUnit
1919
* LSP 外部注解器,使用最高优先级确保渲染效果
2020
* 解决多个高亮系统冲突时只有背景色高亮显示的问题
2121
*/
22-
class LuaLspExternalAnnotator : ExternalAnnotator<LuaLspExternalAnnotator.CollectedInfo, LuaLspExternalAnnotator.AnnotationResult>() {
22+
class LuaLspExternalAnnotator :
23+
ExternalAnnotator<LuaLspExternalAnnotator.CollectedInfo, LuaLspExternalAnnotator.AnnotationResult>() {
2324

2425
data class CollectedInfo(
2526
val psiFile: PsiFile,

src/main/java/com/tang/intellij/lua/braces/LuaBraceMatcher.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ class LuaBraceMatcher : PairedBraceMatcher {
2727
}
2828

2929
companion object {
30-
private val PAIRS = arrayOf(BracePair(LuaTypes.LCURLY, LuaTypes.RCURLY, true), //{}
31-
BracePair(LuaTypes.LPAREN, LuaTypes.RPAREN, true), //()
32-
BracePair(LuaTypes.LBRACK, LuaTypes.RBRACK, true), //[]
33-
BracePair(LuaTypes.DO, LuaTypes.END, true), //do end
34-
BracePair(LuaTypes.IF, LuaTypes.END, true), //if end
35-
BracePair(LuaTypes.REPEAT, LuaTypes.UNTIL, true), //repeat until
36-
BracePair(LuaTypes.FUNCTION, LuaTypes.END, true) //function end
30+
private val PAIRS = arrayOf(
31+
BracePair(LuaTypes.LCURLY, LuaTypes.RCURLY, true), //{}
32+
BracePair(LuaTypes.LPAREN, LuaTypes.RPAREN, true), //()
33+
BracePair(LuaTypes.LBRACK, LuaTypes.RBRACK, true), //[]
34+
BracePair(LuaTypes.DO, LuaTypes.END, true), //do end
35+
BracePair(LuaTypes.IF, LuaTypes.END, true), //if end
36+
BracePair(LuaTypes.REPEAT, LuaTypes.UNTIL, true), //repeat until
37+
BracePair(LuaTypes.FUNCTION, LuaTypes.END, true) //function end
3738
)
3839
}
3940
}

src/main/java/com/tang/intellij/lua/codeInsight/LuaReadWriteAccessDetector.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.intellij.codeInsight.highlighting.ReadWriteAccessDetector
44
import com.intellij.psi.PsiElement
55
import com.intellij.psi.PsiReference
66
import com.tang.intellij.lua.psi.LuaExpr
7-
import com.tang.intellij.lua.psi.LuaIndexExpr
87
import com.tang.intellij.lua.psi.LuaNameDef
98
import com.tang.intellij.lua.psi.LuaPsiElement
109

src/main/java/com/tang/intellij/lua/codeInsight/editorActions/LuaWordSelectionHandler.kt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,83 +12,86 @@ import com.tang.intellij.lua.psi.LuaTypes
1212
* 当双击字符串内的单词时,只选择单词而不是整个字符串
1313
*/
1414
class LuaWordSelectionHandler : ExtendWordSelectionHandlerBase() {
15-
15+
1616
override fun canSelect(e: PsiElement): Boolean {
1717
return e.node.elementType == LuaTypes.STRING
1818
}
1919

2020
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange>? {
2121
val text = e.text
2222
val content = LuaString.getContent(text)
23-
23+
2424
// 计算相对于字符串内容的光标位置
2525
val relativeOffset = cursorOffset - e.textRange.startOffset - content.start
26-
26+
2727
// 如果光标不在字符串内容区域内,返回null让默认处理器处理
2828
if (relativeOffset < 0 || relativeOffset >= content.value.length || content.value.isEmpty()) {
2929
return null
3030
}
31-
31+
3232
val stringContent = content.value
33-
33+
3434
// 查找当前光标位置的单词
3535
val wordRange = findWordAt(stringContent, relativeOffset) ?: return null
36-
36+
3737
val absoluteStart = e.textRange.startOffset + content.start + wordRange.first
3838
val absoluteEnd = e.textRange.startOffset + content.start + wordRange.second
39-
39+
4040
// 确保范围有效且在字符串内容范围内
41-
if (absoluteStart >= e.textRange.startOffset + content.start &&
41+
if (absoluteStart >= e.textRange.startOffset + content.start &&
4242
absoluteEnd <= e.textRange.startOffset + content.end &&
43-
absoluteStart < absoluteEnd) {
43+
absoluteStart < absoluteEnd
44+
) {
4445
return listOf(TextRange(absoluteStart, absoluteEnd))
4546
}
46-
47+
4748
return null
4849
}
49-
50+
5051
/**
5152
* 在指定位置查找单词
5253
*/
5354
private fun findWordAt(text: String, offset: Int): Pair<Int, Int>? {
5455
if (offset < 0 || offset >= text.length) return null
55-
56+
5657
var start = offset
5758
var end = offset
58-
59+
5960
// 如果当前字符不是单词字符,寻找最近的单词
6061
if (!isWordChar(text[offset])) {
6162
// 向左查找
6263
var leftPos = offset - 1
6364
while (leftPos >= 0 && !isWordChar(text[leftPos])) leftPos--
64-
65+
6566
// 向右查找
6667
var rightPos = offset
6768
while (rightPos < text.length && !isWordChar(text[rightPos])) rightPos++
68-
69+
6970
// 选择最近的单词
7071
when {
7172
leftPos >= 0 && (rightPos >= text.length || (offset - leftPos <= rightPos - offset)) -> {
7273
start = leftPos
7374
end = leftPos + 1
7475
}
76+
7577
rightPos < text.length -> {
7678
start = rightPos
7779
end = rightPos + 1
7880
}
81+
7982
else -> return null
8083
}
8184
}
82-
85+
8386
// 向左扩展到单词开始
8487
while (start > 0 && isWordChar(text[start - 1])) start--
85-
88+
8689
// 向右扩展到单词结束
8790
while (end < text.length && isWordChar(text[end])) end++
88-
91+
8992
return if (start < end) Pair(start, end) else null
9093
}
91-
94+
9295
/**
9396
* 判断字符是否为单词字符(字母、数字、下划线)
9497
*/

src/main/java/com/tang/intellij/lua/codeInsight/editorActions/StringLiteralPasteProvider.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package com.tang.intellij.lua.codeInsight.editorActions
33
import com.intellij.ide.PasteProvider
44
import com.intellij.openapi.actionSystem.CommonDataKeys
55
import com.intellij.openapi.actionSystem.DataContext
6-
import java.awt.datatransfer.DataFlavor
7-
import com.intellij.openapi.ide.CopyPasteManager
8-
import com.intellij.psi.PsiElement
9-
import com.tang.intellij.lua.psi.LuaTypes
106
import com.intellij.openapi.command.WriteCommandAction
117
import com.intellij.openapi.editor.EditorModificationUtil
8+
import com.intellij.openapi.ide.CopyPasteManager
9+
import com.intellij.psi.PsiElement
1210
import com.tang.intellij.lua.lang.type.LuaString
11+
import com.tang.intellij.lua.psi.LuaTypes
12+
import java.awt.datatransfer.DataFlavor
1313

1414

1515
class StringLiteralPasteProvider : PasteProvider {

src/main/java/com/tang/intellij/lua/codeInsight/highlighting/LuaHighlightExitPointsHandler.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import com.tang.intellij.lua.psi.*
1111
1212
* Created by tangzx on 2017/3/18.
1313
*/
14-
class LuaHighlightExitPointsHandler internal constructor(editor: Editor, file: PsiFile, private val target: LuaReturnStat, private val funcBody: LuaFuncBody) : HighlightUsagesHandlerBase<PsiElement>(editor, file) {
14+
class LuaHighlightExitPointsHandler internal constructor(
15+
editor: Editor,
16+
file: PsiFile,
17+
private val target: LuaReturnStat,
18+
private val funcBody: LuaFuncBody
19+
) : HighlightUsagesHandlerBase<PsiElement>(editor, file) {
1520

1621
override fun getTargets(): List<PsiElement> {
1722
return listOf<PsiElement>(target)

src/main/java/com/tang/intellij/lua/codeInsight/highlighting/LuaHighlightUsagesHandlerFactory.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ import com.tang.intellij.lua.psi.*
3737
*/
3838
class LuaHighlightUsagesHandlerFactory : HighlightUsagesHandlerFactoryBase() {
3939

40-
override fun createHighlightUsagesHandler(editor: Editor,
41-
psiFile: PsiFile,
42-
psiElement: PsiElement): HighlightUsagesHandlerBase<*>? {
43-
when(psiElement.node.elementType) {
40+
override fun createHighlightUsagesHandler(
41+
editor: Editor,
42+
psiFile: PsiFile,
43+
psiElement: PsiElement
44+
): HighlightUsagesHandlerBase<*>? {
45+
when (psiElement.node.elementType) {
4446
LuaTypes.RETURN -> {
4547
val returnStat = PsiTreeUtil.getParentOfType(psiElement, LuaReturnStat::class.java)
4648
if (returnStat != null) {
@@ -56,7 +58,10 @@ class LuaHighlightUsagesHandlerFactory : HighlightUsagesHandlerFactoryBase() {
5658
val parentType = parent.node.elementType
5759
if (parentType == LuaTypes.BINARY_OP || parentType == LuaTypes.UNARY_OP) {
5860
return object : HighlightUsagesHandlerBase<PsiElement>(editor, psiFile) {
59-
override fun selectTargets(list: MutableList<out PsiElement>, consumer: Consumer<in MutableList<out PsiElement>>) {
61+
override fun selectTargets(
62+
list: MutableList<out PsiElement>,
63+
consumer: Consumer<in MutableList<out PsiElement>>
64+
) {
6065
}
6166

6267
override fun computeUsages(list: MutableList<out PsiElement>) {
@@ -65,8 +70,7 @@ class LuaHighlightUsagesHandlerFactory : HighlightUsagesHandlerFactoryBase() {
6570

6671
override fun getTargets() = arrayListOf(psiElement)
6772
}
68-
}
69-
else if (parent is LuaNameExpr || parent is LuaIndexExpr) {
73+
} else if (parent is LuaNameExpr || parent is LuaIndexExpr) {
7074
return ReferenceHighlightHandler(editor, psiFile, parent)
7175
}
7276
}
@@ -78,7 +82,8 @@ class LuaHighlightUsagesHandlerFactory : HighlightUsagesHandlerFactoryBase() {
7882
/**
7983
* 由于新版本IDEA 202采用了新的Reference高亮算法,导致Lua高亮失效,这里自己处理高亮
8084
*/
81-
private class ReferenceHighlightHandler(editor: Editor, psiFile: PsiFile, val psi:PsiElement) : HighlightUsagesHandlerBase<PsiElement>(editor, psiFile) {
85+
private class ReferenceHighlightHandler(editor: Editor, psiFile: PsiFile, val psi: PsiElement) :
86+
HighlightUsagesHandlerBase<PsiElement>(editor, psiFile) {
8287

8388
private val list: List<PsiElement> by lazy {
8489
val result = mutableListOf<PsiElement>()
@@ -94,13 +99,15 @@ private class ReferenceHighlightHandler(editor: Editor, psiFile: PsiFile, val ps
9499

95100
override fun getTargets() = arrayListOf(psi)
96101

97-
override fun selectTargets(list: MutableList<out PsiElement>, consumer: Consumer<in MutableList<out PsiElement>>) = Unit
102+
override fun selectTargets(list: MutableList<out PsiElement>, consumer: Consumer<in MutableList<out PsiElement>>) =
103+
Unit
98104

99105
override fun computeUsages(list: MutableList<out PsiElement>) {
100106
val detector = LuaReadWriteAccessDetector()
101107
this.list.forEach { psi ->
102108
val rangeElement = (psi as? PsiNameIdentifierOwner)?.nameIdentifier ?: psi
103-
val range = InjectedLanguageManager.getInstance(this.psi.project).injectedToHost(rangeElement, rangeElement.textRange)
109+
val range = InjectedLanguageManager.getInstance(this.psi.project)
110+
.injectedToHost(rangeElement, rangeElement.textRange)
104111
val access = detector.getExpressionAccess(psi)
105112
if (access == ReadWriteAccessDetector.Access.Read)
106113
myReadUsages.add(range)

src/main/java/com/tang/intellij/lua/comment/LuaCommenter.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.tang.intellij.lua.comment
22

33
import com.intellij.codeInsight.generation.IndentedCommenter
4-
import com.intellij.lang.Commenter
54

65
class LuaCommenter : IndentedCommenter {
76
override fun getLineCommentPrefix(): String {

src/main/java/com/tang/intellij/lua/comment/psi/impl/LuaCommentImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ package com.tang.intellij.lua.comment.psi.impl
33
import com.intellij.extapi.psi.ASTWrapperPsiElement
44
import com.intellij.lang.ASTNode
55

6-
class LuaCommentImpl(node: ASTNode) : ASTWrapperPsiElement(node) {
7-
}
6+
class LuaCommentImpl(node: ASTNode) : ASTWrapperPsiElement(node)

0 commit comments

Comments
 (0)