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

bugfix: handle CR #5651

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import scala.concurrent.Future
import scala.util.Try
import scala.{meta => m}

import scala.meta.inputs.Input
import scala.meta.internal.metals.Buffers
import scala.meta.internal.metals.ClientCommands
import scala.meta.internal.metals.ClientConfiguration
Expand Down Expand Up @@ -551,8 +550,8 @@ final class SyntheticsDecorationProvider(
val uri = path.toURI.toString
val typeDecorations = for {
tree <- trees.get(path).toIterable
textDocumentInput = Input.VirtualFile(uri, textDocument.text)
treeInput = Input.VirtualFile(uri, tree.pos.input.text)
textDocumentInput = VirtualFile(uri, textDocument.text)
treeInput = VirtualFile(uri, tree.pos.input.text)
semanticDbToTreeEdit = TokenEditDistance(
textDocumentInput,
treeInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scala.meta.internal.metals

import scala.collection.concurrent.TrieMap

import scala.meta.inputs.Input
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.parsing.TokenEditDistance
import scala.meta.internal.parsing.Trees
Expand All @@ -26,7 +25,7 @@ case class Buffers(
trees: Trees,
): TokenEditDistance = {
val bufferInput = source.toInputFromBuffers(this)
val snapshotInput = Input.VirtualFile(bufferInput.path, snapshot)
val snapshotInput = VirtualFile(bufferInput.path, snapshot)
TokenEditDistance(snapshotInput, bufferInput, trees).getOrElse(
TokenEditDistance.NoMatch
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ final class DefinitionProvider(

val defResult = for {
sourceText <- buffers.get(path)
virtualFile = Input.VirtualFile(path.toURI.toString(), sourceText)
virtualFile = VirtualFile(path.toURI.toString(), sourceText)
metaPos <- pos.toMeta(virtualFile)
tokens <- trees.tokenized(virtualFile).toOption
ident <- tokens.collectFirst {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ final case class Indexer(
val updatedContent =
sourceItem.getTopWrapper + content + sourceItem.getBottomWrapper
(
Input.VirtualFile(
VirtualFile(
generatedPath.toNIO.toString
.stripSuffix(".scala") + ".sc.scala",
updatedContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ object MetalsEnrichments
def toUriInput: Input.VirtualFile = {
val uri = path.toAbsolutePath.toUri.toString
val text = new String(Files.readAllBytes(path), StandardCharsets.UTF_8)
Input.VirtualFile(uri, text)
VirtualFile(uri, text)
}

def isSemanticdb: Boolean =
Expand Down Expand Up @@ -489,7 +489,7 @@ object MetalsEnrichments
*/
def toInputFromBuffers(buffers: Buffers): m.Input.VirtualFile = {
buffers.get(path) match {
case Some(text) => Input.VirtualFile(path.toURI.toString(), text)
case Some(text) => VirtualFile(path.toURI.toString(), text)
case None => path.toInput
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ class PackageProvider(
val result = for {
content <- path.content()
} yield {
val input = Input.VirtualFile(filename, content)
val input = VirtualFile(filename, content)

def isPackageObjectLike(symbol: String) =
Set("package", filenamePart ++ "$package").contains(symbol)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package scala.meta.internal.metals.formatting

import scala.meta.inputs.Input
import scala.meta.internal.metals.Buffers
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals.UserConfiguration
Expand Down Expand Up @@ -51,7 +50,7 @@ class OnTypeFormattingProvider(

val edits = for {
sourceText <- buffers.get(path)
virtualFile = Input.VirtualFile(path.toURI.toString(), sourceText)
virtualFile = VirtualFile(path.toURI.toString(), sourceText)
startPos <- range.getStart.toMeta(virtualFile)
endPos <- range.getEnd.toMeta(virtualFile)
} yield {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package scala.meta.internal.metals.formatting

import scala.meta.inputs.Input
import scala.meta.internal.metals.Buffers
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals.UserConfiguration
Expand Down Expand Up @@ -47,7 +46,7 @@ class RangeFormattingProvider(
val formattingOptions = params.getOptions
val edits = for {
sourceText <- buffers.get(path)
virtualFile = Input.VirtualFile(path.toURI.toString(), sourceText)
virtualFile = VirtualFile(path.toURI.toString(), sourceText)
startPos <- range.getStart.toMeta(virtualFile)
endPos <- range.getEnd.toMeta(virtualFile)
} yield {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package scala.meta.internal.parsing
import java.util
import java.util.Collections

import scala.meta.inputs.Input
import scala.meta.inputs.Position
import scala.meta.internal.metals.Buffers
import scala.meta.internal.metals.MetalsEnrichments._
Expand All @@ -26,9 +25,9 @@ final class FoldingRangeProvider(
if filePath.isScala
tree <- trees.get(filePath)
} yield {
val revised = Input.VirtualFile(filePath.toURI.toString(), code)
val revised = VirtualFile(filePath.toURI.toString(), code)
val fromTree =
Input.VirtualFile(filePath.toURI.toString(), tree.pos.input.text)
VirtualFile(filePath.toURI.toString(), tree.pos.input.text)
val distance = TokenEditDistance(fromTree, revised, trees).getOrElse(
TokenEditDistance.NoMatch
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ final class Trees(
} yield try {
val skipFistShebang =
if (text.startsWith("#!")) text.replaceFirst("#!", "//") else text
val input = Input.VirtualFile(path.toURI.toString(), skipFistShebang)
val input = VirtualFile(path.toURI.toString(), skipFistShebang)
if (path.isAmmoniteScript || path.isMill) {
val ammoniteInput = Input.Ammonite(input)
dialect(ammoniteInput).parse(Parse.parseAmmonite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ trait ScalametaCommonEnrichments extends CommonMtagsEnrichments {
def toInput: Input.VirtualFile = {
val text = FileIO.slurp(path, StandardCharsets.UTF_8)
val file = path.toURI.toString()
Input.VirtualFile(file, text)
VirtualFile(file, text)
}

def jarPath: Option[AbsolutePath] = {
Expand Down Expand Up @@ -526,4 +526,19 @@ trait ScalametaCommonEnrichments extends CommonMtagsEnrichments {

}

object VirtualFile {
def apply(path: String, value: String): Input.VirtualFile = {
val buffer = new StringBuilder()
var isLastCR = false
value.foreach { char =>
val isCR = char == '\r'
def CRSubstitute = if (char == '\n') ' ' else '\n'
if (isLastCR) buffer.append(CRSubstitute)
if (!isCR) buffer.append(char)
isLastCR = isCR
}
Input.VirtualFile(path, buffer.result())
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import scala.util.Properties
import scala.util.control.NonFatal

import scala.meta.Dialect
import scala.meta.inputs.Input
import scala.meta.internal.io.FileIO
import scala.meta.internal.io.PathIO
import scala.meta.internal.mtags.ScalametaCommonEnrichments._
Expand Down Expand Up @@ -129,7 +128,7 @@ class SymbolIndexBucket(
dialect: Dialect
): List[String] = {
val text = FileIO.slurp(source, StandardCharsets.UTF_8)
val input = Input.VirtualFile(uri, text)
val input = VirtualFile(uri, text)
val sourceToplevels = mtags.toplevels(input, dialect)
if (source.isAmmoniteScript)
sourceToplevels
Expand Down
4 changes: 2 additions & 2 deletions tests/mtest/src/main/scala/tests/TestingSymbolSearch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import java.nio.file.Files
import java.util.Optional
import java.{util => ju}

import scala.meta.inputs.Input
import scala.meta.internal.metals.ClasspathSearch
import scala.meta.internal.metals.Docstrings
import scala.meta.internal.metals.EmptyReportContext
Expand All @@ -15,6 +14,7 @@ import scala.meta.internal.metals.WorkspaceSymbolQuery
import scala.meta.internal.mtags.GlobalSymbolIndex
import scala.meta.internal.mtags.Mtags
import scala.meta.internal.mtags.OnDemandSymbolIndex
import scala.meta.internal.mtags.ScalametaCommonEnrichments._
import scala.meta.internal.mtags.Symbol
import scala.meta.internal.{semanticdb => s}
import scala.meta.pc.ParentSymbols
Expand Down Expand Up @@ -73,7 +73,7 @@ class TestingSymbolSearch(
import scala.collection.JavaConverters._
val filename = value.path.toNIO.getFileName().toString()
val content = new String(Files.readAllBytes(value.path.toNIO))
val input = Input.VirtualFile(
val input = VirtualFile(
filename,
content,
)
Expand Down
5 changes: 2 additions & 3 deletions tests/mtest/src/main/scala/tests/TestingWorkspaceSearch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import java.nio.file.Paths
import scala.collection.mutable

import scala.meta.Dialect
import scala.meta.inputs.Input
import scala.meta.internal.metals.EmptyReportContext
import scala.meta.internal.metals.ReportContext
import scala.meta.internal.metals.SemanticdbDefinition
import scala.meta.internal.metals.WorkspaceSymbolInformation
import scala.meta.internal.metals.WorkspaceSymbolQuery
import scala.meta.internal.mtags.ScalametaCommonEnrichments.XtensionWorkspaceSymbolQuery
import scala.meta.internal.mtags.ScalametaCommonEnrichments._
import scala.meta.pc.SymbolSearchVisitor

object TestingWorkspaceSearch {
Expand All @@ -32,7 +31,7 @@ class TestingWorkspaceSearch(implicit rc: ReportContext = EmptyReportContext) {
(path, (text, dialect)) <- inputs
} {
SemanticdbDefinition.foreach(
Input.VirtualFile(path, text),
VirtualFile(path, text),
dialect,
includeMembers = true,
) { defn =>
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/src/main/scala/tests/Library.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ object Library {
).sources.entries
.filter(_.toString.endsWith("bindings-rxjava-2.0.0-sources.jar"))

def msal4jSources: List[AbsolutePath] =
fetchSources(
"azure",
List(Dependency.of("com.microsoft.azure", "msal4j", "1.13.8")),
).sources.entries
.filter(_.toString().endsWith("msal4j-1.13.8-sources.jar"))

def allScala2: List[Library] = {
import mtags.BuildInfo.scalaCompilerVersion

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/src/test/scala/tests/ToplevelLibrarySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class ToplevelLibrarySuite extends BaseSuite {
"/dotty/tools/dotc/transform/patmat/Space.scala",
)

val javaTestClasspath: List[AbsolutePath] = Library.damlrxjavaSources
val javaTestClasspath: List[AbsolutePath] =
Library.damlrxjavaSources ++ Library.msal4jSources

scala2TestClasspath.foreach { entry =>
test(entry.toNIO.getFileName.toString) {
Expand Down
Loading