Skip to content

Commit 2bf4093

Browse files
committed
暂存
1 parent f0c16e2 commit 2bf4093

File tree

5 files changed

+67
-21
lines changed

5 files changed

+67
-21
lines changed

EmmyLua-Common/src/main/ext/com/tang/lsp/workspace.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ interface ILuaFile : IVirtualFile {
5353
fun unindex()
5454
fun getLine(offset: Int): Pair<Int, Int>
5555
fun didChange(params: DidChangeTextDocumentParams)
56+
fun diagnose();
5657
fun getPosition(line:Int, char: Int): Int
5758
fun processWords(processor: (w: Word) -> Boolean)
5859
}

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

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import com.tang.intellij.lua.project.LuaSettings
1818
import com.tang.intellij.lua.psi.*
1919
import com.tang.intellij.lua.reference.ReferencesSearch
2020
import com.tang.intellij.lua.search.SearchContext
21-
import com.tang.intellij.lua.ty.ITyFunction
22-
import com.tang.intellij.lua.ty.findPerfectSignature
23-
import com.tang.intellij.lua.ty.hasVarargs
24-
import com.tang.intellij.lua.ty.process
21+
import com.tang.intellij.lua.ty.*
2522
import com.tang.lsp.ILuaFile
2623
import com.tang.lsp.getRangeInFile
2724
import com.tang.lsp.nameRange
@@ -73,6 +70,7 @@ class LuaTextDocumentService(private val workspace: LuaWorkspaceService) : TextD
7370
val notUse = mutableListOf<TextRange>()
7471
val paramHints = mutableListOf<RenderRange>()
7572
val localHints = mutableListOf<RenderRange>()
73+
val overrideHint = mutableListOf<RenderRange>()
7674

7775
// 认为所有local名称定义一开始都是未使用的
7876
val psiNotUse = mutableSetOf<PsiElement>()
@@ -130,6 +128,35 @@ class LuaTextDocumentService(private val workspace: LuaWorkspaceService) : TextD
130128
o.acceptChildren(this)
131129
}
132130

131+
override fun visitClassMethodDef(o: LuaClassMethodDef) {
132+
val context = SearchContext.get(o.project)
133+
val classType = o.guessClassType(context)
134+
if(classType != null) {
135+
TyClass.processSuperClass(classType, context) { sup ->
136+
val id = o.classMethodName.id
137+
if(id != null) {
138+
val member = sup.findMember(id.text, context)
139+
if (member != null) {
140+
val funcBody = o.children.find { it is LuaFuncBody }
141+
if(funcBody is LuaFuncBody) {
142+
var fchild = funcBody.firstChild
143+
while(fchild != funcBody.lastChild){
144+
if(fchild.text == ")"){
145+
overrideHint.add(RenderRange(fchild.nameRange!!.toRange (file), null))
146+
}
147+
148+
fchild = fchild.nextSibling
149+
}
150+
}
151+
}
152+
}
153+
true
154+
}
155+
}
156+
157+
o.acceptChildren(this)
158+
}
159+
133160
override fun visitNameDef(o: LuaNameDef) {
134161
psiNotUse.add(o)
135162
}
@@ -308,6 +335,10 @@ class LuaTextDocumentService(private val workspace: LuaWorkspaceService) : TextD
308335
if (localHints.isNotEmpty()) {
309336
all.add(Annotator(uri, localHints, AnnotatorType.LocalHint))
310337
}
338+
if(overrideHint.isNotEmpty()){
339+
all.add(Annotator(uri, overrideHint, AnnotatorType.OverrideHint))
340+
}
341+
311342
return all
312343
}
313344

@@ -921,25 +952,29 @@ class LuaTextDocumentService(private val workspace: LuaWorkspaceService) : TextD
921952
val file = workspace.findFile(params.textDocument.uri)
922953
if (file is ILuaFile) {
923954
file.didChange(params)
955+
956+
file.diagnose()
924957
val diagnosticsParams = PublishDiagnosticsParams(params.textDocument.uri, file.diagnostics)
925958
client?.publishDiagnostics(diagnosticsParams)
926959
}
927960
}
928961

929962
override fun references(params: ReferenceParams): CompletableFuture<MutableList<out Location>> {
930-
val list = mutableListOf<Location>()
931-
withPsiFile(params.textDocument, params.position) { _, psiFile, pos ->
932-
val element = TargetElementUtil.findTarget(psiFile, pos)
933-
if (element != null) {
934-
val target = element.reference?.resolve() ?: element
935-
val query = ReferencesSearch.search(target)
936-
query.forEach { ref ->
937-
val luaFile = ref.element.containingFile.virtualFile as LuaFile
938-
list.add(Location(luaFile.uri.toString(), ref.getRangeInFile(luaFile)))
963+
return computeAsync {
964+
val list = mutableListOf<Location>()
965+
withPsiFile(params.textDocument, params.position) { _, psiFile, pos ->
966+
val element = TargetElementUtil.findTarget(psiFile, pos)
967+
if (element != null) {
968+
val target = element.reference?.resolve() ?: element
969+
val query = ReferencesSearch.search(target)
970+
query.forEach { ref ->
971+
val luaFile = ref.element.containingFile.virtualFile as LuaFile
972+
list.add(Location(luaFile.uri.toString(), ref.getRangeInFile(luaFile)))
973+
}
939974
}
940975
}
976+
list
941977
}
942-
return CompletableFuture.completedFuture(list)
943978
}
944979

945980
override fun foldingRange(params: FoldingRangeRequestParams?): CompletableFuture<MutableList<FoldingRange>> {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ class LuaWorkspaceService : WorkspaceService, IWorkspace {
238238
processedCount++
239239
val file = uri.toFile()
240240
if (file != null) {
241-
monitor.setProgress("Emmy parse file: ${file.canonicalPath}", processedCount / totalFileCount)
241+
monitor.setProgress("Emmy parse file[${(processedCount / totalFileCount * 100).toInt()}%]: ${file.canonicalPath}",
242+
processedCount / totalFileCount)
242243
}
243244
addFile(uri, null)
244245
}
@@ -253,8 +254,11 @@ class LuaWorkspaceService : WorkspaceService, IWorkspace {
253254
private fun sendAllDiagnostics() {
254255
project.process {
255256
val file = it.virtualFile
256-
if (file is LuaFile && file.diagnostics.isNotEmpty()) {
257-
client?.publishDiagnostics(PublishDiagnosticsParams(file.uri.toString(), file.diagnostics))
257+
if (file is LuaFile) {
258+
file.diagnose()
259+
if(file.diagnostics.isNotEmpty()) {
260+
client?.publishDiagnostics(PublishDiagnosticsParams(file.uri.toString(), file.diagnostics))
261+
}
258262
}
259263
true
260264
}

EmmyLua-LS/src/main/kotlin/com/tang/vscode/api/impl/LuaFile.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
8383
onChanged()
8484
}
8585

86+
override fun diagnose(){
87+
if(diagnostics.isEmpty()) {
88+
// 索引建立完之后再诊断
89+
DiagnosticsService.diagnosticFile(this, diagnostics)
90+
}
91+
}
92+
8693
@Synchronized
8794
private fun updateLines() {
8895
_lines.clear()
@@ -131,11 +138,9 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
131138
_myPsi?.virtualFile = this
132139

133140
index()
134-
135-
// 索引建立完之后再诊断
136-
DiagnosticsService.diagnosticFile(this, diagnostics)
137141
}
138142

143+
139144
/*private fun getLineStart(line: Int): Int {
140145
return _lines.firstOrNull { it.line == line } ?.startOffset ?: 0
141146
}*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ enum class AnnotatorType {
1212
Upvalue,
1313
NotUse,
1414
ParamHint,
15-
LocalHint
15+
LocalHint,
16+
OverrideHint
1617
}
1718

1819
data class AnnotatorParams(val uri: String)

0 commit comments

Comments
 (0)