@@ -12,7 +12,7 @@ import Flags._
12
12
import Decorators ._
13
13
import Names .Name
14
14
import StdNames .nme
15
- import util .SourcePosition
15
+ import util .{ SourceFile , SourcePosition }
16
16
import collection .mutable
17
17
import java .lang .Character .{isJavaIdentifierPart , isJavaIdentifierStart }
18
18
import java .nio .file .Paths
@@ -34,17 +34,7 @@ class ExtractSemanticDB extends Phase {
34
34
val extract = Extractor ()
35
35
val unit = ctx.compilationUnit
36
36
extract.traverse(unit.tpdTree)
37
- val targetRootSetting = ctx.settings.targetroot.value
38
- val targetRoot =
39
- if targetRootSetting.isEmpty then ctx.settings.outputDir.value.jpath
40
- else Paths .get(targetRootSetting)
41
- ExtractSemanticDB .write(
42
- unit.source.file.jpath,
43
- String (unit.source.content),
44
- Paths .get(ctx.settings.sourceroot.value),
45
- Paths .get(ctx.settings.targetroot.value),
46
- extract.occurrences.toList
47
- )
37
+ ExtractSemanticDB .write(unit.source, extract.occurrences.toList)
48
38
}
49
39
50
40
class Extractor extends TreeTraverser {
@@ -64,8 +54,6 @@ class ExtractSemanticDB extends Phase {
64
54
65
55
def isJavaIdent (str : String ) =
66
56
isJavaIdentifierStart(str.head) && str.tail.forall(isJavaIdentifierPart)
67
- || str == nme.CONSTRUCTOR .toString
68
- || str == nme.STATIC_CONSTRUCTOR .toString
69
57
70
58
def nameToString (name : Name ) =
71
59
val str = name.toString
@@ -76,22 +64,22 @@ class ExtractSemanticDB extends Phase {
76
64
|| (sym.is(Param ) || sym.owner.isClass) && isGlobal(sym.owner)
77
65
78
66
def ownerString (owner : Symbol ): String =
79
- if owner.isRoot || owner.isEmptyPackage then " " else symbolName(owner) + " / "
67
+ if owner.isRoot || owner.isEmptyPackage then " " else symbolName(owner)
80
68
81
69
def overloadIdx (sym : Symbol ): String =
82
70
val alts = sym.owner.info.decls.lookupAll(sym.name).toList
83
71
if alts.tail.isEmpty then " "
84
72
else
85
73
val idx = alts.indexOf(sym)
86
74
assert(idx >= 0 )
87
- idx.toString
75
+ " + " + idx.toString
88
76
89
77
def descriptor (sym : Symbol ): String =
90
78
if sym.is(ModuleClass ) then
91
79
descriptor(sym.sourceModule)
92
80
else
93
81
val str = nameToString(sym.name)
94
- if sym.is(Package ) then str
82
+ if sym.is(Package ) then str + " / "
95
83
else if sym.isType then str + " #"
96
84
else if sym.isRealMethod then str + " (" + overloadIdx(sym) + " )"
97
85
else if sym.is(TermParam ) || sym.is(ParamAccessor ) then " (" + str + " )"
@@ -154,26 +142,28 @@ object ExtractSemanticDB {
154
142
155
143
val name : String = " extractSemanticDB"
156
144
157
- def write (
158
- source : Path ,
159
- contents : String ,
160
- sourceroot : Path ,
161
- targetroot : Path ,
162
- occurrences : Seq [SymbolOccurrence ]
163
- ): Unit =
164
- val relpath = sourceroot.relativize(source)
165
- val reluri = relpath.iterator().asScala.mkString(" /" )
166
- val outpath = targetroot
145
+ def write (source : SourceFile , occurrences : List [SymbolOccurrence ])(given ctx : Context ): Unit =
146
+ val sourcePath = source.file.jpath
147
+ val sourceRoot = Paths .get(ctx.settings.sourceroot.value)
148
+ val targetRoot =
149
+ val targetRootSetting = ctx.settings.targetroot.value
150
+ if targetRootSetting.isEmpty then ctx.settings.outputDir.value.jpath
151
+ else Paths .get(targetRootSetting)
152
+ println(i " extract from $sourcePath from $sourceRoot, targetRoot = $targetRoot" )
153
+ val relPath = sourceRoot.relativize(sourcePath)
154
+ println(i " relPath = $relPath" )
155
+ val relURI = relPath.iterator().asScala.mkString(" /" )
156
+ val outpath = targetRoot
167
157
.resolve(" META-INF" )
168
158
.resolve(" semanticdb" )
169
- .resolve(relpath )
170
- .resolveSibling(source .getFileName().toString() + " .semanticdb" )
159
+ .resolve(relPath )
160
+ .resolveSibling(sourcePath .getFileName().toString() + " .semanticdb" )
171
161
Files .createDirectories(outpath.getParent())
172
162
val doc : TextDocument = TextDocument (
173
163
schema = Schema .SEMANTICDB4 ,
174
164
language = Language .SCALA ,
175
- uri = reluri ,
176
- md5 = MD5 .compute(contents ),
165
+ uri = relURI ,
166
+ md5 = MD5 .compute(String (source.content) ),
177
167
occurrences = occurrences
178
168
)
179
169
val docs = TextDocuments (List (doc))
0 commit comments