Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Scalameta v3.7 #275

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0aba1e2
Upgrade build dependency
olafurpg Apr 9, 2018
633bbc2
Fix all compile errors
olafurpg Apr 9, 2018
0ea9e56
Fix compile errors in tests
olafurpg Apr 10, 2018
3431fb7
Fix workspace/symbol by removing protobuf generation.
olafurpg Apr 10, 2018
4ec168f
Add note on package objects for workspace/symbol
olafurpg Apr 10, 2018
17380e8
Compute definition on the fly for local symbols.
olafurpg Apr 10, 2018
5eba30c
Fix indexing for local symbols.
olafurpg Apr 10, 2018
afa835e
Don't index message-only documents.
olafurpg Apr 10, 2018
b37d634
Fix mtags tests
olafurpg Apr 10, 2018
d413039
Fix remaining test cases.
olafurpg Apr 10, 2018
15b667a
Fix remaining deprecation warnings
olafurpg Apr 10, 2018
3f8c0b7
Address comment
olafurpg Apr 10, 2018
63487bf
Fix CI failures
olafurpg Apr 10, 2018
45abbe3
Upgrade scalafix dependency
olafurpg Apr 13, 2018
df272a6
Handle method overloads in Scala mtags.
amarrella Apr 15, 2018
bce8dd9
Handle conflicting method overlaods.
olafurpg Apr 15, 2018
ed9bb9d
Emit method symbols for val/var to be compliant with spec
olafurpg Apr 15, 2018
3fd7262
Emit correct disambiguator for singleton type
olafurpg Apr 15, 2018
7a3e0bf
Use scalafix PrettyType for HoverProvider
olafurpg Apr 20, 2018
525039c
Fix scalafix integration.
olafurpg Apr 20, 2018
1f6ec39
Polish new Hover implementation
olafurpg Apr 20, 2018
b20a6c9
Add more relevant tests for hover
olafurpg Apr 21, 2018
317fd60
Document hover requires metalsSetup
olafurpg Apr 21, 2018
0c9d0fc
Log slightly more helpful error message on failure to parse proto file
olafurpg Apr 21, 2018
42765d7
Address review feedback and polish.
olafurpg Apr 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- sbt ++2.11.12 jsonrpc/test
- env: TEST="sbt test"
script:
- sbt startServer metalsSetup test scalafixTest
- sbt startServer metalsSetup test
- env: TEST="sbt-metals"
script:
- ./bin/run-scripted.sh
Expand Down
11 changes: 2 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ inThisBuild(
// https://github.com/scala/bug/issues/10448
"-Ywarn-unused-import"
),
scalafixEnabled := false,
organization := "org.scalameta",
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
Expand Down Expand Up @@ -79,7 +78,7 @@ lazy val V = new {
val scala211 = MetalsPlugin.scala211
val scala212 = MetalsPlugin.scala212
val scalameta = MetalsPlugin.semanticdbVersion
val scalafix = "0.5.7"
val scalafix = "0.6.0-M5"
val enumeratum = "1.5.12"
val circe = "0.9.0"
val cats = "1.0.1"
Expand Down Expand Up @@ -127,11 +126,6 @@ lazy val metals = project
.enablePlugins(BuildInfoPlugin)
.disablePlugins(ScriptedPlugin)
.settings(
PB.targets.in(Compile) := Seq(
scalapb.gen(
flatPackage = true // Don't append filename to package
) -> sourceManaged.in(Compile).value./("protobuf")
),
fork in Test := true, // required for jni interrop with leveldb.
buildInfoKeys := Seq[BuildInfoKey](
"testWorkspaceBaseDirectory" ->
Expand All @@ -149,7 +143,7 @@ lazy val metals = project
"io.github.soc" % "directories" % "5", // for cache location
"me.xdrop" % "fuzzywuzzy" % "1.1.9", // for workspace/symbol
"org.fusesource.leveldbjni" % "leveldbjni-all" % "1.8", // for caching classpath index
"org.scalameta" %% "semanticdb-scalac" % V.scalameta cross CrossVersion.full,
"org.scalameta" % "interactive" % V.scalameta cross CrossVersion.full,
"org.scalameta" %% "testkit" % V.scalameta % Test
)
)
Expand Down Expand Up @@ -178,7 +172,6 @@ lazy val testWorkspace = project
scalacOptions += "-Ywarn-unused-import",
scalacOptions -= "-Xlint"
)
.disablePlugins(ScalafixPlugin)

lazy val metalsRoot = project
.in(file("."))
Expand Down
4 changes: 2 additions & 2 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ architecture as [Index-While-Building][] in XCode 9.
* [x] Symbol outline in the sidebar as you type (`textDocument/documentSymbol`).
* [ ] Goto implementation (`textDocument/implementation`)
* [ ] Goto type definition (`textDocument/typeDefinition`)
* [x] Show type of symbol at position (`textDocument/hover`). Requires
[semanticdb-scalac](#semanticdb-scalac).
* [x] Show type of symbol at position (`textDocument/hover`).
Requires [`metalsSetup`](#metalssetup).
* [ ] Show type of expression at position (`textDocument/hover`).

## Fast completions
Expand Down
19 changes: 18 additions & 1 deletion lsp4s/src/main/scala/org/langmeta/lsp/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,24 @@ import io.circe.generic.JsonCodec
/**
* A range in a text document.
*/
@JsonCodec case class Range(start: Position, end: Position)
@JsonCodec case class Range(start: Position, end: Position) {
def startLine = start.line
def startColumn = start.character
def endLine = end.line
def endColumn = end.character
}

object Range {
def apply(
startLine: Int,
startColumn: Int,
endLine: Int,
endColumn: Int
): Range = Range(
start = Position(startLine, startColumn),
end = Position(endLine, endColumn)
)
}

/**
* Represents a location inside a resource, such as a line
Expand Down
41 changes: 0 additions & 41 deletions metals/src/main/protobuf/metaserver.proto

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.langmeta.languageserver

import org.langmeta.lsp
import org.langmeta.{lsp => l}
import org.langmeta.inputs.Input
import org.langmeta.inputs.Position
import scala.meta.metals.{index => i}
import scala.meta.internal.semanticdb3

object InputEnrichments {
implicit class XtensionPositionOffset(val pos: Position) extends AnyVal {
Expand All @@ -24,13 +24,12 @@ object InputEnrichments {
}
}
implicit class XtensionInputOffset(val input: Input) extends AnyVal {
def toIndexRange(start: Int, end: Int): i.Range = {
val pos = Position.Range(input, start, end)
i.Range(
startLine = pos.startLine,
startColumn = pos.startColumn,
endLine = pos.endLine,
endColumn = pos.endColumn
def toIndexRange(r: semanticdb3.Range): l.Range = {
l.Range(
startLine = r.startLine,
startColumn = r.startCharacter,
endLine = r.endLine,
endColumn = r.endCharacter
)
}

Expand All @@ -39,7 +38,7 @@ object InputEnrichments {
Position.Range(input, offset, offset)

/** Returns a scala.meta.Position from an index range. */
def toPosition(range: lsp.Range): Position = {
def toPosition(range: l.Range): Position = {
toPosition(
range.start.line,
range.start.character,
Expand All @@ -48,17 +47,7 @@ object InputEnrichments {
)
}

/** Returns a scala.meta.Position from an index range. */
def toPosition(range: i.Range): Position = {
toPosition(
range.startLine,
range.startColumn,
range.endLine,
range.endColumn
)
}

def toOffset(pos: lsp.Position): Int =
def toOffset(pos: l.Position): Int =
toOffset(pos.line, pos.character)

/** Returns an offset for this input */
Expand Down
2 changes: 1 addition & 1 deletion metals/src/main/scala/scala/meta/metals/Linter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Linter(configuration: Observable[Configuration], cwd: AbsolutePath)(
case Parsed.Success(tree) =>
val ctx = RuleCtx.applyInternal(tree, config)
val patches = rule.fixWithNameInternal(ctx)
Patch.lintMessagesInternal(patches, ctx).map(_.toLSP)
Patch.lintMessagesInternal(patches, ctx, index).map(_.toLSP)
}

// megaCache needs to die, if we forget this we will read stale
Expand Down
27 changes: 19 additions & 8 deletions metals/src/main/scala/scala/meta/metals/MetalsServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ import monix.reactive.Observable
import monix.reactive.Observer
import monix.reactive.OverflowStrategy
import org.langmeta.inputs.Input
import org.langmeta.internal.semanticdb.XtensionDatabase
import org.langmeta.internal.semanticdb.schema
import scala.meta.internal.semanticdb3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curiosity: why are semanticdb3 data types internal?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because otherwise we'd have to provide strong compatibility guarantees for them: https://github.com/scalameta/scalameta/blob/master/COMPATIBILITY.md. I don't think we're fully ready to do this right now.

import scala.{meta => m}
import org.langmeta.io.AbsolutePath
import org.langmeta.languageserver.InputEnrichments._
import org.langmeta.lsp.LanguageClient
import org.langmeta.semanticdb
import org.langmeta.internal.semanticdb._
import scala.meta.metals.compiler.MetacpProvider
import scala.meta.metals.compiler.SymtabProvider
import scala.meta.metals.mtags.Mtags

class MetalsServices(
cwd: AbsolutePath,
Expand Down Expand Up @@ -87,7 +90,14 @@ class MetalsServices(
val diagnosticsProvider =
new DiagnosticsProvider(configurationPublisher, cwd)
val scalacProvider = new ScalacProvider
val interactiveSemanticdbs: Observable[semanticdb.Database] =
val metacpProvider = new MetacpProvider
val symtabProvider =
new SymtabProvider(
symbolIndex.documentIndex,
scalacProvider,
metacpProvider
)
val interactiveSemanticdbs: Observable[m.Database] =
sourceChangePublisher
.debounce(FiniteDuration(1, "s"))
.flatMap { input =>
Expand All @@ -97,9 +107,9 @@ class MetalsServices(
.executeOn(presentationCompilerScheduler)
} else Observable.empty
}
val interactiveSchemaSemanticdbs: Observable[schema.Database] =
val interactiveSchemaSemanticdbs: Observable[semanticdb3.TextDocuments] =
interactiveSemanticdbs.flatMap(db => Observable(db.toSchema(cwd)))
val metaSemanticdbs: Observable[semanticdb.Database] =
val metaSemanticdbs: Observable[m.Database] =
Observable.merge(
fileSystemSemanticdbsPublisher.map(_.toDb(sourcepath = None)),
interactiveSemanticdbs
Expand Down Expand Up @@ -317,6 +327,7 @@ class MetalsServices(
if (latestConfig().hover.enabled) {
HoverProvider.hover(
symbolIndex,
symtabProvider,
Uri(params.textDocument),
params.position.line,
params.position.character
Expand Down Expand Up @@ -529,7 +540,7 @@ object MetalsServices extends LazyLogging {
val path = AbsolutePath(
ProjectDirectories.fromProjectName("metals").projectCacheDir
)
Files.createDirectories(path.toNIO)
Files.createDirectories(path.resolve(Mtags.Version).toNIO)
path
}

Expand Down Expand Up @@ -565,7 +576,7 @@ object MetalsServices extends LazyLogging {

def fileSystemSemanticdbStream(cwd: AbsolutePath)(
implicit scheduler: Scheduler
): (Observer.Sync[AbsolutePath], Observable[schema.Database]) = {
): (Observer.Sync[AbsolutePath], Observable[semanticdb3.TextDocuments]) = {
val (subscriber, publisher) = multicast[AbsolutePath]()
val semanticdbPublisher = publisher
.map(path => Semanticdbs.loadFromFile(semanticdbPath = path, cwd))
Expand Down
Loading