@@ -232,30 +232,30 @@ class MetabrowseServer(
232
232
.build()
233
233
234
234
private def getBytes (exchange : HttpServerExchange ): Array [Byte ] = {
235
- val path = exchange.getRequestPath.stripSuffix(" .gz" )
236
- if (path.endsWith(" index.workspace" )) {
235
+ val path = os. SubPath ( " . " + exchange.getRequestPath.stripSuffix(" .gz" ) )
236
+ if (path.lastOpt.exists(_. endsWith(" index.workspace" ) )) {
237
237
getWorkspace.toByteArray
238
- } else if (path.endsWith(" .symbolindexes" )) {
238
+ } else if (path.lastOpt.exists(_. endsWith(" .symbolindexes" ) )) {
239
239
val header = exchange.getRequestHeaders.get(" Metabrowse-Symbol" )
240
240
if (header.isEmpty) {
241
241
logger.error(s " no Metabrowse-Symbol header: $exchange" )
242
242
Array .emptyByteArray
243
243
} else {
244
244
getSymbol(header.getFirst).toByteArray
245
245
}
246
- } else if (path.endsWith(" .semanticdb" )) {
246
+ } else if (path.lastOpt.exists(_. endsWith(" .semanticdb" ) )) {
247
247
getSemanticdb(path).toByteArray
248
- } else if (path.endsWith(" .map" )) {
248
+ } else if (path.lastOpt.exists(_. endsWith(" .map" ) )) {
249
249
// Ignore requests for sourcemaps.
250
250
Array .emptyByteArray
251
251
} else {
252
- val actualPath = if (path == " / " ) " / index.html" else path
252
+ val actualPath = if (path == os.sub) os.sub / " index.html" else path
253
253
withInputStream(
254
254
Thread
255
255
.currentThread()
256
256
.getContextClassLoader
257
257
.getResourceAsStream(
258
- s " metabrowse/ server/ assets/ ${actualPath.stripPrefix( " / " )} "
258
+ (os.sub / " metabrowse" / " server" / " assets" / actualPath).toString
259
259
)
260
260
) { is =>
261
261
if (is == null ) {
@@ -301,27 +301,35 @@ class MetabrowseServer(
301
301
Workspace (filenames.result().toSeq)
302
302
}
303
303
304
- private def getSemanticdb (filename : String ): TextDocuments = {
305
- val path = filename
306
- .stripPrefix(" /semanticdb/" )
307
- .stripPrefix(" /" ) // optional '/'
308
- .stripSuffix(" .semanticdb" )
309
- logger.info(path)
304
+ private def getSemanticdb (subPath : os.SubPath ): TextDocuments = {
305
+ val path = {
306
+ val subPath0 =
307
+ if (subPath.startsWith(os.sub / " semanticdb" ))
308
+ subPath.relativeTo(os.sub / " semanticdb" ).asSubPath
309
+ else
310
+ subPath
311
+ subPath0.lastOpt match {
312
+ case Some (name) if name.endsWith(" .semanticdb" ) =>
313
+ subPath0 / os.up / name.stripSuffix(" .semanticdb" )
314
+ case _ => subPath0
315
+ }
316
+ }
317
+ logger.info(path.toString)
310
318
for {
311
- text <- state.get().source(path).orElse {
319
+ text <- state.get().source(path.toString ).orElse {
312
320
logger.warn(s " no source file: $path" )
313
321
None
314
322
}
315
323
doc <- try {
316
324
val timeout = TimeUnit .SECONDS .toMillis(10 )
317
- val textDocument = if (path.endsWith(" .java" )) {
318
- val input = Input .VirtualFile (path, text)
325
+ val textDocument = if (path.lastOpt.exists(_. endsWith(" .java" ) )) {
326
+ val input = Input .VirtualFile (path.toString , text)
319
327
t.JavaMtags .index(input, includeMembers = true ).index()
320
328
} else {
321
329
InteractiveSemanticdb .toTextDocument(
322
330
global,
323
331
text,
324
- filename ,
332
+ subPath.toString ,
325
333
timeout,
326
334
List (
327
335
" -P:semanticdb:synthetics:on" ,
@@ -332,7 +340,7 @@ class MetabrowseServer(
332
340
Some (textDocument)
333
341
} catch {
334
342
case NonFatal (e) =>
335
- logger.error(s " compile error: $filename " , e)
343
+ logger.error(s " compile error: $subPath " , e)
336
344
None
337
345
}
338
346
} yield TextDocuments (List (doc.withText(text)))
0 commit comments