scalameta
one seemed right, however metals (vscode) does not find all the dependencies when doing it as an ammonite script
import java.nio.file._
import scala.collection.immutable.SortedSet
import scala.jdk.CollectionConverters._
import $ivy.`org.scalameta::scalameta:4.4.0`
import scala.meta.internal.semanticdb.Locator
import scala.meta.prettyprinters.Structure
import scala.meta.internal.semanticdb.SymbolOccurrence.Role.REFERENCE
import scala.meta.internal.semanticdb.SymbolOccurrence.Role.DEFINITION
import scala.meta.internal.semanticdb.SymbolOccurrence.Role.Unrecognized
import scala.meta.internal.semanticdb.SymbolOccurrence.Role.UNKNOWN_ROLE
import scala.meta.internal.semanticdb.SymbolInformation
import scala.meta.internal.semanticdb.Scala.ScalaSymbolOps
var rs, ds = Set.empty[String]
var syms = Map.empty[String, SymbolInformation]
val targetDirs =
os.walk.attrs(os.pwd, skip = (_, i) => i.isFile, maxDepth = 3)
.map(_._1.toNIO)
.filter(_.endsWith("target"))
Locator(targetDirs.toList) { (path, docs) =>
docs.documents.foreach { doc =>
// println(doc.uri)
doc.symbols.foreach { info =>
syms += info.symbol -> info
}
doc.occurrences.foreach { o =>
o.role match {
case REFERENCE => rs += o.symbol
case DEFINITION => ds += o.symbol
}
}
}
}
(ds -- rs)
.filterNot(_.isLocal)
// .filterNot(_.startsWith("db/migration/"))
// .filterNot(_.startsWith("chesednow/views/html/"))
// .filterNot(_.startsWith("views/html/"))
.filter(_.startsWith("chesednow/requests/sjs/"))
.to(SortedSet)
.foreach { sym =>
println(sym)
}
Hey guys, somehow the parser does not like the Unit Symbol ()
as a type:
package uml.strategies.rewriting.packagerep
import org.bitbucket.inkytonik.kiama.rewriting.Rewriter.rulef
import org.bitbucket.inkytonik.kiama.rewriting.Strategy
import uml.UMLUnit
import uml.strategies.rewriting.RewriteStrategy
object DeleteEmptyPackages extends RewriteStrategy[()] {
override def apply(v1: ()): Strategy = {
rulef {
case u@UMLUnit(_,toplevelElements) =>
val filtered = toplevelElements.filter( tp => tp match {
case uml.Package(Nil,_,_) => false
case _ => true
}
)
u.copy(toplevelElements = filtered)
case u@_ => u
}
}
}
This is not parsed with an Unreachable Code Sequence Error thrown. If i exchange v1:()
to v1:Unit
and [()]
to [Unit]
it does parse. Do I need to enable some dialect for this ?
scala> def apply(v1: ()) = ""
<console>:1: error: '=>' expected but ')' found.
()
is not a type in itself, but it's interpreted as a singleton type literal ().type
when a type is expected. That works out as equivalent to Unit
because it has only the single inhabitant
Foo
somewhere but it’s not used by anything anywhere in the project
Transformed trees do not preserve comments and formatting details when pretty-printed. Look into Scalafix if you need to implement fine-grained refactorings that preserve comments and formatting details.
Does it mean i can use scalafix in programmatic way from my code to retain formatting before i will save the code back to the file? If yes could you point me to example? After reading scalafix docs i understood i need to recompile my project to apply formatting but that doesnt sound like a process i want to follow and i would prefer to simply apply formatting at stage of writing tree back to file. Thx in advance