Skip to content

Commit 3e5dd24

Browse files
committed
实验性的支持未定义field检查
1 parent 8a0c08b commit 3e5dd24

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

EmmyLua-LS/src/main/kotlin/com/tang/vscode/diagnostics/DiagnosticsOptions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ object DiagnosticsOptions {
1212

1313
// nil 是否可以赋值给任何定义类型
1414
var defineTypeCanReceiveNilType = true
15+
16+
var fieldValidation = true
1517
}

EmmyLua-LS/src/main/kotlin/com/tang/vscode/diagnostics/DiagnosticsService.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.tang.lsp.toRange
1313
import org.eclipse.lsp4j.Diagnostic
1414
import org.eclipse.lsp4j.DiagnosticSeverity
1515
import org.eclipse.lsp4j.DiagnosticTag
16+
import kotlin.math.exp
1617

1718
object DiagnosticsService {
1819
fun diagnosticFile(file: ILuaFile, diagnostics: MutableList<Diagnostic>) {
@@ -110,6 +111,36 @@ object DiagnosticsService {
110111
diagnostics.add(diagnostic)
111112
}
112113
}
114+
115+
if(DiagnosticsOptions.fieldValidation){
116+
if(it.parent is LuaVarList){
117+
return@processElements true
118+
}
119+
120+
if(resolve == null) {
121+
it.id?.let { id ->
122+
val diagnostic = Diagnostic()
123+
diagnostic.message = "undefined property '${id.text}'"
124+
diagnostic.severity = DiagnosticSeverity.Warning
125+
diagnostic.range = id.textRange.toRange(file)
126+
diagnostics.add(diagnostic)
127+
}
128+
}
129+
}
130+
}
131+
is LuaCallExpr -> {
132+
val expr = it.expr
133+
if(expr is LuaNameExpr) {
134+
val resolve = expr.reference?.resolve()
135+
if (resolve is LuaFuncDef && resolve.isDeprecated) {
136+
val diagnostic = Diagnostic()
137+
diagnostic.message = "deprecated"
138+
diagnostic.severity = DiagnosticSeverity.Hint
139+
diagnostic.tags = listOf(DiagnosticTag.Deprecated)
140+
diagnostic.range = expr.textRange.toRange(file)
141+
diagnostics.add(diagnostic)
142+
}
143+
}
113144
}
114145
}
115146

0 commit comments

Comments
 (0)