/*
 * Use of this source code is governed by the MIT license that can be
 * found in the LICENSE file.
 */

package org.toml.lang

import com.intellij.openapi.fileTypes.FileType
import com.intellij.openapi.fileTypes.FileTypeRegistry
import com.intellij.openapi.util.io.ByteSequence
import com.intellij.openapi.vfs.VirtualFile
import org.toml.lang.psi.TomlFileType

class TomlFileTypeDetector : FileTypeRegistry.FileTypeDetector {
    override fun getVersion(): Int = 1

    override fun detect(file: VirtualFile, firstBytes: ByteSequence, firstCharsIfText: CharSequence?): FileType? =
        if (file.name == "config" && file.parent?.name == ".cargo") TomlFileType else null
}

/*
 * Use of this source code is governed by the MIT license that can be
 * found in the LICENSE file.
 */

package org.toml.lang

import com.intellij.openapi.fileTypes.FileType
import com.intellij.openapi.fileTypes.FileTypeRegistry
import com.intellij.openapi.util.io.ByteSequence
import com.intellij.openapi.vfs.VirtualFile
import org.toml.lang.psi.TomlFileType

class TomlFileTypeDetector : FileTypeRegistry.FileTypeDetector {
    override fun getVersion() = 1

    override fun detect(file: VirtualFile, firstBytes: ByteSequence, firstCharsIfText: CharSequence?): FileType? =
        if (file.name == "config" && file.parent?.name == ".cargo") TomlFileType else null

    override fun getDetectedFileTypes() = listOf(TomlFileType)

    override fun getDesiredContentPrefixLength() = 0
}

Use performance optimizations provided by FileTypeDetector API not to slow down IDEs using TOML plugin
Use performance optimizations provided by FileTypeDetector API not to slow down IDEs using TOML plugin

intellij-rust/intellij-rust,intellij-rust/intellij-rust,intellij-rust/intellij-rust,Undin/intellij-rust,intellij-rust/intellij-rust,Undin/intellij-rust,Undin/intellij-rust,intellij-rust/intellij-rust,Undin/intellij-rust,Undin/intellij-rust,Undin/intellij-rust,intellij-rust/intellij-rust