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