SemanticDB for Scala developer tools (ScalaSphere Krakow 2018)
展开查看详情
1.SemanticDB For Scala developer tools !1
2. About me • Author of Scalafmt and Scalafix • Software developer at Scala Center • Scalameta maintainer 2
3. Credits • Eugene Burmako: Advanced Scala Tools team lead at Twitter • Co-maintainer of Scalameta and SemanticDB 3
4. Tooling 4
5. Scalameta • Open Source Project with 50+ contributors • Full-time developers funded by Scala Center + Twitter • 120k downloads/month for core module • !5
6.scalafmt 6
7. scalafix Rewrite and linting tool 7
8. We used Scalafix to perform a large-scale refactoring of our Scala codebase at Twitter with great success. – Shane Delmore, Advanced Scala Tools Team @Twitter 8
9. Scalafix enabled us to run refactorings in a distributed fashion, which is necessary for a codebase the size of ours. – Shane Delmore, Advanced Scala Tools Team @Twitter 9
10. Agenda • Compiler plugin vs. SemanticDB • Schema • Utilities • Demo !10
11. Build Tool -Xplugin:scalafix.jar Compiler plugin developer tools scalac !11
12. Build Tool -Xplugin:semanticdb.jar SemanticDB developer tools scalac *.semanticdb scalafix !12
13. Compiler plugins • Undocumented and unsupported internal APIs • Relevant data available in different phases • Analysis limited to single compilation run • Difficult to test and maintain !13
14. SemanticDB • 300 LOC protobuf schema: symbols, types, occurrences • 11.000 word specification: Scala, Java • Utilities: metacp, metac, mtags, metap • Applications: metadoc, metals, scalafix !14
15.Schema !15
16. TextDocument Uri: src/spire/math/Complex.scala Schema: SEMANTICDB3 Text: “package spire.math\n\n@…” Language: SCALA SymbolOccurrence: [ scala.SerialVersionUID# spire.math.Complex# … ] SymbolInformation: [ spire.math.Complex# spire.math.Complex#[T] … ] Diagnostics: […] Synthetics: […] !16
17. SymbolOccurence Symbol: spire.math.Complex# Range: 4:18-4:25 Role: DEFINITION !17
18. SymbolOccurence Symbol: spire.math.Complex#real(). Range: 10:18-10:22 Role: REFERENCE !18
19. SymbolInformation Kind: CLASS Language: SCALA Name: Complex Symbol: spire.math.Complex# Owner: spire.math. Type: ClassInfoType { +6 decls } Properties: final, case Annotations: scala.SerialVersionUID# Accessibility: PUBLIC !19
20. SymbolInformation Kind: PARAMETER Language: SCALA Name: r Symbol: spire.math.Complex#`+`(T,Semiring).(r) Owner: spire.math.Complex#`+`(T,Semiring). Type: TypeRef { Semiring[T] } Properties: implicit !20
21.Spec !21
22.Scala parameters !22
23.Java class !23
24.$ metac $ metacp Utilities $ mtags $ metap !24
25. metac Build SemanticDB with compiler !25
26. $ scalac -Xplugin:semanticdb.jar -Xstop-after:semanticdb-typer src/Complex.scala "## out $ %## META-INF $ %## semanticdb $ %## src $ %## Complex.scala.semanticdb %## src %## Complex.scala !26
27. $ metac src/Complex.scala "## out $ %## META-INF $ %## semanticdb $ %## src $ %## Complex.scala.semanticdb %## src %## Complex.scala !27
28."## out $ %## META-INF $ %## semanticdb $ %## $ %## Complex.scala.semanticdb %## src %## Complex.scala !28
29. metacp Build SemanticDB with classpath !29