Skip to content

Commit

Permalink
Make the SemanticDB compiler options used by mtags configurable.
Browse files Browse the repository at this point in the history
Previously, mtags used a hardcoded list of SemanticDB compiler options
to produce SemanticDB text documents from source. This commit makes the
options configurable via PresentationCompilerConfig. The motivation for
this change is that we recently started using mtags for LSIF indexing
Scala projects. To render Scala method/class signatures we need SemanticDB
`SymbolInformation`, which are not emitted by default in mtags since
they are not used by Metals.
  • Loading branch information
olafurpg committed Aug 3, 2021
1 parent 75355b2 commit 8dd3310
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package scala.meta.pc;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -98,4 +100,19 @@ enum OverrideDefFormat {
*/
TimeUnit timeoutUnit();

/**
* The SemanticDB compiler options to use for the <code>semanticdbTextDocument</code> method.
*
* The full list of supported options is documented here https://scalameta.org/docs/semanticdb/guide.html#scalac-compiler-plugin
*/
List<String> semanticdbCompilerOptions();

static List<String> defaultSemanticdbCompilerOptions() {
return Arrays.asList(
"-P:semanticdb:synthetics:on",
"-P:semanticdb:symbols:none",
"-P:semanticdb:text:on"
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ case class ScalaPresentationCompiler(
Array.emptyByteArray,
EmptyCancelToken
) { pc =>
new SemanticdbTextDocumentProvider(pc.compiler())
new SemanticdbTextDocumentProvider(
pc.compiler(),
config.semanticdbCompilerOptions().asScala.toList
)
.textDocument(uri, code)
.toByteArray
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import scala.meta.internal.semanticdb.scalac.SemanticdbConfig
import scala.meta.internal.{semanticdb => s}
import scala.meta.io.AbsolutePath

class SemanticdbTextDocumentProvider(val compiler: MetalsGlobal)
extends WorksheetSemanticdbProvider {
class SemanticdbTextDocumentProvider(
val compiler: MetalsGlobal,
semanticdbCompilerOptions: List[String]
) extends WorksheetSemanticdbProvider {
import compiler._

def textDocument(
Expand All @@ -31,11 +33,7 @@ class SemanticdbTextDocumentProvider(val compiler: MetalsGlobal)
// This cache is never updated in semanticdb and will contain the old source
gSourceFileInputCache.remove(unit.source)
semanticdbOps.config = SemanticdbConfig.parse(
List(
"-P:semanticdb:synthetics:on",
"-P:semanticdb:symbols:none",
"-P:semanticdb:text:on"
),
semanticdbCompilerOptions,
_ => (),
compiler.reporter,
SemanticdbConfig.default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ case class PresentationCompilerConfigImpl(
isCompletionItemResolve: Boolean = true,
_isStripMarginOnTypeFormattingEnabled: () => Boolean = () => true,
timeoutDelay: Long = 20,
timeoutUnit: TimeUnit = TimeUnit.SECONDS
timeoutUnit: TimeUnit = TimeUnit.SECONDS,
semanticdbCompilerOptions: util.List[String] =
PresentationCompilerConfig.defaultSemanticdbCompilerOptions()
) extends PresentationCompilerConfig {

override def isStripMarginOnTypeFormattingEnabled(): Boolean =
Expand Down

0 comments on commit 8dd3310

Please sign in to comment.