Skip to content

Commit 6035cee

Browse files
committed
0.5.14
1 parent 1f09fa4 commit 6035cee

File tree

7 files changed

+56
-27
lines changed

7 files changed

+56
-27
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ interface ILuaFile : IVirtualFile {
5353
fun didChange(params: DidChangeTextDocumentParams)
5454
fun getPosition(line:Int, char: Int): Int
5555
fun processWords(processor: (w: Word) -> Boolean)
56-
fun getVersion(): Int
5756
fun lock(code: () -> Unit)
5857
}

EmmyLua-Common/src/main/java/com/tang/intellij/lua/ty/TySubstitutor.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface ITySubstitutor {
3232
class GenericAnalyzer(arg: ITy, private val par: ITy) : TyVisitor() {
3333
var cur: ITy = arg
3434

35-
var map:MutableMap<String, ITy>? = null
35+
var map: MutableMap<String, ITy>? = null
3636

3737
fun analyze(result: MutableMap<String, ITy>) {
3838
map = result
@@ -86,7 +86,7 @@ class GenericAnalyzer(arg: ITy, private val par: ITy) : TyVisitor() {
8686
warp(arg.returnTy) { par.returnTy.accept(this) }
8787
}
8888

89-
private fun warp(ty:ITy, action: () -> Unit) {
89+
private fun warp(ty: ITy, action: () -> Unit) {
9090
if (Ty.isInvalid(ty))
9191
return
9292
val arg = cur
@@ -108,13 +108,18 @@ open class TySubstitutor : ITySubstitutor {
108108
}
109109

110110
override fun substitute(function: ITyFunction): ITy {
111-
return TySerializedFunction(function.mainSignature.substitute(this),
112-
function.signatures.map { it.substitute(this) }.toTypedArray(),
113-
function.flags)
111+
return TySerializedFunction(
112+
function.mainSignature.substitute(this),
113+
function.signatures.map { it.substitute(this) }.toTypedArray(),
114+
function.flags
115+
)
114116
}
115117
}
116118

119+
// cppcxy: 我对这里的递归爆栈感到绝望
117120
class TyAliasSubstitutor private constructor(val project: Project) : ITySubstitutor {
121+
val walkedClassName = mutableSetOf<String>()
122+
118123
companion object {
119124
fun substitute(ty: ITy, context: SearchContext): ITy {
120125
/*if (context.forStub)
@@ -124,12 +129,18 @@ class TyAliasSubstitutor private constructor(val project: Project) : ITySubstitu
124129
}
125130

126131
override fun substitute(function: ITyFunction): ITy {
127-
return TySerializedFunction(function.mainSignature.substitute(this),
128-
function.signatures.map { it.substitute(this) }.toTypedArray(),
129-
function.flags)
132+
return TySerializedFunction(
133+
function.mainSignature.substitute(this),
134+
function.signatures.map { it.substitute(this) }.toTypedArray(),
135+
function.flags
136+
)
130137
}
131138

132139
override fun substitute(clazz: ITyClass): ITy {
140+
if (clazz.className in this.walkedClassName) {
141+
return clazz
142+
}
143+
this.walkedClassName.add(clazz.className)
133144
return clazz.recoverAlias(SearchContext.get(project), this)
134145
}
135146

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ interface LuaLanguageClient : LanguageClient {
1616
@JsonNotification("emmy/progressReport")
1717
fun progressReport(report: ProgressReport)
1818

19+
@JsonNotification("emmy/setServerStatus")
20+
fun setServerStatus(status: ServerStatusParams)
21+
1922
@JsonNotification("emmy/reportAPI")
2023
fun reportAPI(params: LuaReportApiParams)
2124
}

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class LuaWorkspaceService : WorkspaceService, IWorkspace {
7777
removeFile(change.uri)
7878
addFile(change.uri)
7979
}
80+
8081
else -> {}
8182
}
8283
}
@@ -290,15 +291,27 @@ class LuaWorkspaceService : WorkspaceService, IWorkspace {
290291
fun loadWorkspace() {
291292
cleanWorkspace()
292293
loadWorkspace(object : IProgressMonitor {
293-
override fun done() {
294+
override fun start() {
294295
if (VSCodeSettings.isVSCode)
296+
client?.setServerStatus(ServerStatusParams("ok", "load workspace", true))
297+
}
298+
299+
override fun done() {
300+
if (VSCodeSettings.isVSCode) {
295301
client?.progressReport(ProgressReport("Finished!", 1f))
302+
client?.setServerStatus(ServerStatusParams("ok", "EmmyLua Language Server", false))
303+
}
296304
}
297305

298306
override fun setProgress(text: String, percent: Float) {
299307
if (VSCodeSettings.isVSCode)
300308
client?.progressReport(ProgressReport(text, percent))
301309
}
310+
311+
override fun reportError(text: String) {
312+
if (VSCodeSettings.isVSCode)
313+
client?.setServerStatus(ServerStatusParams("error", "load fail", false))
314+
}
302315
})
303316
}
304317

@@ -318,6 +331,7 @@ class LuaWorkspaceService : WorkspaceService, IWorkspace {
318331

319332
private fun loadWorkspace(monitor: IProgressMonitor) {
320333
try {
334+
monitor.start();
321335
monitor.setProgress("load workspace folders", 0f)
322336
val collections = fileManager.findAllFiles()
323337
var totalFileCount = 0f
@@ -330,15 +344,15 @@ class LuaWorkspaceService : WorkspaceService, IWorkspace {
330344
val file = uri.toFile()
331345
if (file != null) {
332346
monitor.setProgress(
333-
"Emmy parse file[${(processedCount / totalFileCount * 100).toInt()}%]: ${file.name}",
347+
"indexing ${processedCount.toInt()} / ${totalFileCount.toInt()} (${file.name})",
334348
processedCount / totalFileCount
335349
)
336350
}
337351
addFile(uri, null)
338352
}
339353
}
340354
} catch (e: Exception) {
341-
System.err.println("workspace parse error: $e")
355+
monitor.reportError("workspace parse error: $e")
342356
}
343357

344358
monitor.done()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.tang.vscode
22

33
interface IProgressMonitor {
4+
fun start()
45
fun setProgress(text: String, percent: Float)
6+
fun reportError(text: String)
57
fun done()
68
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
3838
private var _lines = mutableListOf<Line>()
3939
private var _myPsi: LuaPsiFile? = null
4040
private var _words: List<Word>? = null
41-
private var _version: Int = 0
4241
private var _rwl = ReentrantReadWriteLock()
4342
private var _isOpen = false
4443

45-
var workspaceDiagnosticResultId: String? = null
46-
4744
override fun didChange(params: DidChangeTextDocumentParams) {
4845
_rwl.write {
4946
if (params.contentChanges.isEmpty())
@@ -120,7 +117,6 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
120117
}
121118

122119
private fun onChanged() {
123-
++_version
124120
updateLines()
125121
doParser()
126122
}
@@ -142,7 +138,6 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
142138
index()
143139
}
144140

145-
146141
/*private fun getLineStart(line: Int): Int {
147142
return _lines.firstOrNull { it.line == line } ?.startOffset ?: 0
148143
}*/
@@ -188,10 +183,6 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
188183
return pos
189184
}
190185

191-
override fun getVersion(): Int {
192-
return _version
193-
}
194-
195186
override fun lock(code: () -> Unit) {
196187
_rwl.read {
197188
code()

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ data class Annotator(val uri: String, val ranges: List<RenderRange>, val type: A
2323

2424
data class ProgressReport(val text: String, val percent: Float)
2525

26+
data class ServerStatusParams(
27+
val health: String,
28+
val message: String = "",
29+
val loading: Boolean = false,
30+
val command: String? = null,
31+
)
32+
2633
enum class UpdateType {
2734
Created,
2835
Changed,
@@ -49,13 +56,15 @@ data class EmmyConfigurationSource(val uri: String, val workspace: String) {
4956
}
5057
}
5158

52-
val fileURI: FileURI get() {
53-
return FileURI.uri(uri, false)
54-
}
59+
val fileURI: FileURI
60+
get() {
61+
return FileURI.uri(uri, false)
62+
}
5563

56-
val workspaceURI: FileURI get() {
57-
return FileURI.uri(workspace, true)
58-
}
64+
val workspaceURI: FileURI
65+
get() {
66+
return FileURI.uri(workspace, true)
67+
}
5968

6069
override fun equals(other: Any?): Boolean {
6170
return other is EmmyConfigurationSource && other.uri == uri

0 commit comments

Comments
 (0)