Skip to content

Commit

Permalink
0.5.14
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed May 22, 2023
1 parent 1f09fa4 commit 6035cee
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 27 deletions.
1 change: 0 additions & 1 deletion EmmyLua-Common/src/main/ext/com/tang/lsp/workspace.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,5 @@ interface ILuaFile : IVirtualFile {
fun didChange(params: DidChangeTextDocumentParams)
fun getPosition(line:Int, char: Int): Int
fun processWords(processor: (w: Word) -> Boolean)
fun getVersion(): Int
fun lock(code: () -> Unit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface ITySubstitutor {
class GenericAnalyzer(arg: ITy, private val par: ITy) : TyVisitor() {
var cur: ITy = arg

var map:MutableMap<String, ITy>? = null
var map: MutableMap<String, ITy>? = null

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

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

override fun substitute(function: ITyFunction): ITy {
return TySerializedFunction(function.mainSignature.substitute(this),
function.signatures.map { it.substitute(this) }.toTypedArray(),
function.flags)
return TySerializedFunction(
function.mainSignature.substitute(this),
function.signatures.map { it.substitute(this) }.toTypedArray(),
function.flags
)
}
}

// cppcxy: 我对这里的递归爆栈感到绝望
class TyAliasSubstitutor private constructor(val project: Project) : ITySubstitutor {
val walkedClassName = mutableSetOf<String>()

companion object {
fun substitute(ty: ITy, context: SearchContext): ITy {
/*if (context.forStub)
Expand All @@ -124,12 +129,18 @@ class TyAliasSubstitutor private constructor(val project: Project) : ITySubstitu
}

override fun substitute(function: ITyFunction): ITy {
return TySerializedFunction(function.mainSignature.substitute(this),
function.signatures.map { it.substitute(this) }.toTypedArray(),
function.flags)
return TySerializedFunction(
function.mainSignature.substitute(this),
function.signatures.map { it.substitute(this) }.toTypedArray(),
function.flags
)
}

override fun substitute(clazz: ITyClass): ITy {
if (clazz.className in this.walkedClassName) {
return clazz
}
this.walkedClassName.add(clazz.className)
return clazz.recoverAlias(SearchContext.get(project), this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ interface LuaLanguageClient : LanguageClient {
@JsonNotification("emmy/progressReport")
fun progressReport(report: ProgressReport)

@JsonNotification("emmy/setServerStatus")
fun setServerStatus(status: ServerStatusParams)

@JsonNotification("emmy/reportAPI")
fun reportAPI(params: LuaReportApiParams)
}
20 changes: 17 additions & 3 deletions EmmyLua-LS/src/main/kotlin/com/tang/vscode/LuaWorkspaceService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class LuaWorkspaceService : WorkspaceService, IWorkspace {
removeFile(change.uri)
addFile(change.uri)
}

else -> {}
}
}
Expand Down Expand Up @@ -290,15 +291,27 @@ class LuaWorkspaceService : WorkspaceService, IWorkspace {
fun loadWorkspace() {
cleanWorkspace()
loadWorkspace(object : IProgressMonitor {
override fun done() {
override fun start() {
if (VSCodeSettings.isVSCode)
client?.setServerStatus(ServerStatusParams("ok", "load workspace", true))
}

override fun done() {
if (VSCodeSettings.isVSCode) {
client?.progressReport(ProgressReport("Finished!", 1f))
client?.setServerStatus(ServerStatusParams("ok", "EmmyLua Language Server", false))
}
}

override fun setProgress(text: String, percent: Float) {
if (VSCodeSettings.isVSCode)
client?.progressReport(ProgressReport(text, percent))
}

override fun reportError(text: String) {
if (VSCodeSettings.isVSCode)
client?.setServerStatus(ServerStatusParams("error", "load fail", false))
}
})
}

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

private fun loadWorkspace(monitor: IProgressMonitor) {
try {
monitor.start();
monitor.setProgress("load workspace folders", 0f)
val collections = fileManager.findAllFiles()
var totalFileCount = 0f
Expand All @@ -330,15 +344,15 @@ class LuaWorkspaceService : WorkspaceService, IWorkspace {
val file = uri.toFile()
if (file != null) {
monitor.setProgress(
"Emmy parse file[${(processedCount / totalFileCount * 100).toInt()}%]: ${file.name}",
"indexing ${processedCount.toInt()} / ${totalFileCount.toInt()} (${file.name})",
processedCount / totalFileCount
)
}
addFile(uri, null)
}
}
} catch (e: Exception) {
System.err.println("workspace parse error: $e")
monitor.reportError("workspace parse error: $e")
}

monitor.done()
Expand Down
2 changes: 2 additions & 0 deletions EmmyLua-LS/src/main/kotlin/com/tang/vscode/ProgressMonitor.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.tang.vscode

interface IProgressMonitor {
fun start()
fun setProgress(text: String, percent: Float)
fun reportError(text: String)
fun done()
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
private var _lines = mutableListOf<Line>()
private var _myPsi: LuaPsiFile? = null
private var _words: List<Word>? = null
private var _version: Int = 0
private var _rwl = ReentrantReadWriteLock()
private var _isOpen = false

var workspaceDiagnosticResultId: String? = null

override fun didChange(params: DidChangeTextDocumentParams) {
_rwl.write {
if (params.contentChanges.isEmpty())
Expand Down Expand Up @@ -120,7 +117,6 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
}

private fun onChanged() {
++_version
updateLines()
doParser()
}
Expand All @@ -142,7 +138,6 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
index()
}


/*private fun getLineStart(line: Int): Int {
return _lines.firstOrNull { it.line == line } ?.startOffset ?: 0
}*/
Expand Down Expand Up @@ -188,10 +183,6 @@ class LuaFile(override val uri: FileURI) : VirtualFileBase(uri), ILuaFile, Virtu
return pos
}

override fun getVersion(): Int {
return _version
}

override fun lock(code: () -> Unit) {
_rwl.read {
code()
Expand Down
21 changes: 15 additions & 6 deletions EmmyLua-LS/src/main/kotlin/com/tang/vscode/rpc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ data class Annotator(val uri: String, val ranges: List<RenderRange>, val type: A

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

data class ServerStatusParams(
val health: String,
val message: String = "",
val loading: Boolean = false,
val command: String? = null,
)

enum class UpdateType {
Created,
Changed,
Expand All @@ -49,13 +56,15 @@ data class EmmyConfigurationSource(val uri: String, val workspace: String) {
}
}

val fileURI: FileURI get() {
return FileURI.uri(uri, false)
}
val fileURI: FileURI
get() {
return FileURI.uri(uri, false)
}

val workspaceURI: FileURI get() {
return FileURI.uri(workspace, true)
}
val workspaceURI: FileURI
get() {
return FileURI.uri(workspace, true)
}

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

0 comments on commit 6035cee

Please sign in to comment.