refactor: use SlintFileType for type-safe file detection

Co-Authored-By: Claude (auto) <noreply@anthropic.com>
This commit is contained in:
me
2026-01-29 13:16:35 +08:00
parent 2d8f817cd2
commit 198af79707

View File

@@ -9,6 +9,7 @@ import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor
import com.intellij.platform.lsp.api.lsWidget.LspServerWidgetItem
import me.zhouxi.slint.SlintRuntime
import me.zhouxi.slint.icons.SlintIcons
import me.zhouxi.slint.lang.SlintFileType
class SlintLspServerSupportProvider : LspServerSupportProvider {
override fun fileOpened(
@@ -16,8 +17,8 @@ class SlintLspServerSupportProvider : LspServerSupportProvider {
file: VirtualFile,
serverStarter: LspServerSupportProvider.LspServerStarter
) {
if (file.extension == "slint") {
serverStarter.ensureServerStarted(FooLspServerDescriptor(project))
if (file.fileType == SlintFileType) {
serverStarter.ensureServerStarted(SlintLspServerDescriptor(project))
}
}
@@ -31,8 +32,8 @@ class SlintLspServerSupportProvider : LspServerSupportProvider {
SlintIcons.Primary,
)
private class FooLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "Slint") {
override fun isSupportedFile(file: VirtualFile) = file.extension == "slint"
private class SlintLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "Slint") {
override fun isSupportedFile(file: VirtualFile) = file.fileType == SlintFileType
override fun createCommandLine(): GeneralCommandLine {
val line = GeneralCommandLine(SlintRuntime.LspExecutable.toAbsolutePath().toString())