taig / scala-linguist   0.0.18

MIT License GitHub

A Scala wrapper around github/linguist based on GraalVM's TruffleRuby

Scala versions: 3.x 2.13
Scala.js versions: 1.x

Scala Linguist

CI & CD scala-linguist-core Scala version support Scala Steward badge

A Scala wrapper around github/linguist based on GraalVM's TruffleRuby

Prerequisites

GraalVM with support for TruffleRuby must be used as the Java runtime

gu install ruby

The github/linguist Ruby gem must be installed (instructions)

gem install github-linguist

Installation

sbt

libraryDependencies ++=
  "io.taig" %%% "scala-linguist-core" % "x.y.z" :: 
  "io.taig" %%% "scala-linguist-naive" % "x.y.z" ::
  "io.taig" %% "scala-linguist-graalvm-ruby" % "x.y.z" ::
  Nil

Usage

  • Detect the language when given a path and source code
import cats.effect.{IO, IOApp}
import io.taig.linguist.GraalVmLinguist

import java.nio.file.Paths

object App extends IOApp.Simple {
  override def run: IO[Unit] =
    GraalVmRubyLinguist.default[IO]
      .use(_.detect(Paths.get("Main.scala"), "trait Foo {}"))
      .flatMap(IO.println)
}
sbt> run 
Some(Scala)
  • Detect the potential languages when only given a path
import cats.effect.{IO, IOApp}
import io.taig.linguist.GraalVmLinguist

import java.nio.file.Paths

object App extends IOApp.Simple {
  override def run: IO[Unit] =
    GraalVmRubyLinguist.default[IO]
      .use(_.detect(Paths.get("Main.scala")))
      .flatMap(IO.println)
}
sbt> run 
List(Scala)

Benchmarks

> benchmarks/Jmh/run -wi 10 -i 5 -f1 -t4