Skip to content

Commit

Permalink
impl status bar and optimize self highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed Mar 5, 2024
1 parent d9e599a commit 4e6a6ca
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 7 deletions.
11 changes: 8 additions & 3 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/main/java/com/tang/intellij/lua/annotator/LuaAnnotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ class LuaAnnotator : Annotator {
}
}
}

override fun visitNameExpr(o: LuaNameExpr) {
super.visitNameExpr(o)
val name = o.id.text
if (name != null) {
if (name == "self") {
newInfoAnnotation(o, null) {
it.textAttributes(LuaHighlightingData.SELF)
}
}
}
}
}

internal inner class LuaDocElementVisitor : LuaDocVisitor() {
Expand Down
59 changes: 59 additions & 0 deletions src/main/kotlin/com/cppcxy/ide/editor/statusbar/StatusBarWidget.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.cppcxy.ide.editor.statusbar


import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.StatusBarWidget
import com.intellij.openapi.wm.StatusBarWidget.WidgetPresentation
import com.intellij.openapi.wm.StatusBarWidgetFactory


class StatusBarWidgetFactory() : StatusBarWidgetFactory {
override fun getId(): String {
return ID
}

override fun getDisplayName(): String {
return "Sumneko Lua"
}

override fun createWidget(project: Project): StatusBarWidget {
return SumnekoBar()
}

override fun isEnabledByDefault(): Boolean {
return true
}

override fun isAvailable(project: Project): Boolean {
return true
}

class SumnekoBar() : StatusBarWidget, StatusBarWidget.TextPresentation {
var toolTip = "Sumneko LSP"
var message = "Lua"

override fun ID(): String {
return ID
}

override fun getPresentation(): WidgetPresentation {
return this
}

override fun getAlignment(): Float {
return 0.0f
}

override fun getText(): String {
return message
}

override fun getTooltipText(): String {
return toolTip
}
}

companion object {
private val ID: String = "SumnekoBar"
}
}
6 changes: 6 additions & 0 deletions src/main/kotlin/com/cppcxy/ide/lsp/CustomLspData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cppcxy.ide.lsp

data class StatusReport(
val text: String,
val tooltip: String,
)
30 changes: 30 additions & 0 deletions src/main/kotlin/com/cppcxy/ide/lsp/SumnekoClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.cppcxy.ide.lsp

import com.cppcxy.ide.editor.statusbar.StatusBarWidgetFactory
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.WindowManager
import com.intellij.platform.lsp.api.Lsp4jClient
import com.intellij.platform.lsp.api.LspServerNotificationsHandler
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification

class SumnekoClient(private val serverNotificationsHandler: LspServerNotificationsHandler, val project: Project) :
Lsp4jClient(serverNotificationsHandler) {

@JsonNotification("$/status/show")
fun statusShow() {
}

@JsonNotification("$/status/hide")
fun statusHide() {
}

@JsonNotification("$/status/report")
fun statusReport(report: StatusReport) {
val statusBar = WindowManager.getInstance().getStatusBar(project)
val widget = statusBar.getWidget("SumnekoBar") as StatusBarWidgetFactory.SumnekoBar?
if (widget != null) {
widget.message = report.text
widget.toolTip = report.tooltip
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.tang.intellij.lua.lang.LuaFileType
import com.tang.intellij.lua.lang.LuaIcons
import org.eclipse.lsp4j.CompletionItem
import org.eclipse.lsp4j.CompletionItemKind
import org.eclipse.lsp4j.InitializeParams
import javax.swing.Icon


Expand All @@ -33,8 +32,8 @@ class SumnekoLspServerDescriptor(project: Project) : ProjectWideLspServerDescrip
}
}

override fun createInitializeParams(): InitializeParams {
return super.createInitializeParams()
override fun createLsp4jClient(handler: LspServerNotificationsHandler): Lsp4jClient {
return SumnekoClient(handler, project)
}

override val lspCompletionSupport = object : LspCompletionSupport() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@

package com.cppcxy.ide.lsp


import com.cppcxy.ide.setting.SumnekoSettingsPanel
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.api.LspServer
import com.tang.intellij.lua.lang.LuaFileType
import com.intellij.platform.lsp.api.LspServerSupportProvider
import com.intellij.platform.lsp.api.lsWidget.LspServerWidgetItem
import com.tang.intellij.lua.lang.LuaIcons

class SumnekoLspServerSupportProvider : LspServerSupportProvider {
override fun fileOpened(project: Project, file: VirtualFile, serverStarter: LspServerSupportProvider.LspServerStarter) {
override fun fileOpened(
project: Project,
file: VirtualFile,
serverStarter: LspServerSupportProvider.LspServerStarter
) {
if (file.fileType !is LuaFileType) return

serverStarter.ensureServerStarted(SumnekoLspServerDescriptor(project))
}

override fun createLspServerWidgetItem(lspServer: LspServer, currentFile: VirtualFile?): LspServerWidgetItem =
LspServerWidgetItem(lspServer, currentFile, LuaIcons.FILE, SumnekoSettingsPanel::class.java)
}
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@
id="SumnekoLua.Settings"
>
</applicationConfigurable>

<statusBarWidgetFactory id="SumnekoBar" implementation="com.cppcxy.ide.editor.statusbar.StatusBarWidgetFactory"/>
</extensions>
<actions>
<action class="com.tang.intellij.lua.actions.CreateLuaFileAction"
Expand Down

0 comments on commit 4e6a6ca

Please sign in to comment.