Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    nafg
    @nafg
    seems I can get sbt to generate them, which results in a predictable path
    I've switched to using scalameta as a library, now I will have to pass it multiple paths
    Tomasz Godzik
    @tgodzik
    Bloop generates multiple build target directories for each client so that it can be used without conflicts, you should be able to know from the BSP client which is the right for you. Alternatively sbt has a stable directory, so that should work ok too
    @nafg something like having a flag if a method is an override would be super useful here I guess, for now in Metals for example we analyze all files and build an index for inheritance. Then if needed we compare all methods between a super class and subclass to see if it's and overriden method
    Tomasz Godzik
    @tgodzik
    however even with an override flag it's a pretty tough topic as we can also have generics
    nafg
    @nafg
    I don't need something perfect, it's just a script that prints a bunch of symbols, at the end of the day I use intellij's Safe Delete
    Some heuristics to clean up the noise would be good
    The docs are very unclear what dependency to add, in the end the regular scalameta one seemed right, however metals (vscode) does not find all the dependencies when doing it as an ammonite script
    This is what I'm doing right now:
    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)
      }
    It can't go do definition of most things, like TextDocument
    are they autogenerated from protobuf and not added to the source jar?
    (Another metals issue is that it's acting like it's interpreting ammonite scripts on scala 2.12)
    Tomasz Godzik
    @tgodzik
    @nafg yeah, they are not added to source jar, which is why we don't have sources to go to
    compute inheritance refreshes the inheritance indexes
    we keep the whole structure of classes in memory
    then we check an exact method if needed.
    nafg
    @nafg
    @tgodzik my question is, to know what logic I should add to my script how much of that file do I need to read?
    Tomasz Godzik
    @tgodzik
    probably most of it. You could throw out all the constructor parameters and remove anything related - only pass all semnticdb documents by hand, but it's still a lot of logic
    Tilman Zuckmantel
    @tizuck

    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 ?

    Tomasz Godzik
    @tgodzik
    @tizuck does the code compile for you? I don't think you can use (), when run in repl I am also getting an error
    scala> def apply(v1: ()) = ""
    <console>:1: error: '=>' expected but ')' found.
    Tilman Zuckmantel
    @tizuck
    I am compiling this code without issues in my IDE, strange.
    Tomasz Godzik
    @tgodzik
    what Scala version are you on?
    Tilman Zuckmantel
    @tizuck

    I am using IntelliJ IDEA 2020.3 (Ultimate Edition)
    Build #IU-203.5981.155, built on November 30, 2020

    Scala Version: 2.13.3

    Tomasz Godzik
    @tgodzik
    Ach, you need the 2.13 dialect for that
    import scala.meta.dialects.Scala213 I think
    Tilman Zuckmantel
    @tizuck
    I tried parsing this with the Dotty dialect, cause i need this dialect to. Can i combine multiple dialects ?
    But thanks! Seems Scala 2.12 does not support this.
    Martijn Hoekstra
    @martijnhoekstra
    singleton type literals are fairly new I think. It's a bit weird to use one here
    () 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
    Tilman Zuckmantel
    @tizuck
    That is an interesting observation. I really thought this was just syntactic sugar for Unit types.
    Martijn Hoekstra
    @martijnhoekstra
    no, () as type is equivalent to for example false as a type
    Tilman Zuckmantel
    @tizuck
    thx :)
    Tomasz Godzik
    @tgodzik
    @tizuck you can use with... methods to turn of/on particular features
    ollijh
    @liff:matrix.org
    [m]
    might it be possible to use semanticdb to find unused symbols within the scope of a project? has someone perhaps done something like that already?
    Tomasz Godzik
    @tgodzik
    @liff:matrix.org I think the compiler is a much better place for it. You can add the flag and use scalafix to remove unused automatically
    ollijh
    @liff:matrix.org
    [m]
    i mean within the larger scope of a project, like detect the situation where i have a public class Foo somewhere but it’s not used by anything anywhere in the project
    or a symbol within such a class
    Tomasz Godzik
    @tgodzik
    ach, it should be possible to do. You would need to index all semanticdb files first
    and check is a reference is just used once
    so if a symbol has a single occurence
    though it might not work perfectly if there is multiple classes with the same name and package
    and there is no such functionality yet implemented really
    ollijh
    @liff:matrix.org
    [m]
    okay then, i’ll try it out then, thanks
    Ólafur Páll Geirsson
    @olafurpg
    @liff:matrix.org it's possible to implement this analysis but it's not easy. One challenge is to detect the usage of overridden methods. SemanticDB occurrences tell you which symbol a method call resolved to at compile-time but you need custom analysis to find all of the implementations of that method (or supermethods)
    Runtime reflection and compile-time macros add another layer of complexity, which might be relevant or not depending on your use-case
    Bartosz Bąbol
    @BBartosz
    Hey, i have extremely simple question: I read my scala file, parse it to Tree, make small modifications and want to save it back but i realised after i parsed my code to Tree i lost all the formatting. I found in documentation following statement: 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