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

Fix determine position for value in directive without quotes #2141

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ class ActionableDiagnosticTests extends munit.FunSuite {
}
}

test("actionable diagnostic report correct position") {
val dependencyOsLib = "com.lihaoyi::os-lib:0.7.8"
val dependencyPprintLib = "com.lihaoyi::pprint:0.6.6"
val testInputs = TestInputs(
os.rel / "Foo.scala" ->
s"""//> using dep $dependencyOsLib
|//> using dep "$dependencyPprintLib"
|
|object Hello extends App {
| println("Hello")
|}
|""".stripMargin
)
testInputs.withBuild(baseOptions, buildThreads, None, actionableDiagnostics = true) {
(root, _, maybeBuild) =>
val build = maybeBuild.orThrow
val updateDiagnostics =
ActionablePreprocessor.generateActionableDiagnostics(build.options).orThrow

val actionableDiagnostics = updateDiagnostics.collect {
case diagnostic: ActionableDependencyUpdateDiagnostic => diagnostic
}

val osLib = actionableDiagnostics.find(_.suggestion.startsWith("com.lihaoyi::os-lib")).get
val pprintLib =
actionableDiagnostics.find(_.suggestion.startsWith("com.lihaoyi::pprint")).get

expect(osLib.positions == Seq(File(Right(root / "Foo.scala"), (0, 14), (0, 39))))
expect(pprintLib.positions == Seq(File(Right(root / "Foo.scala"), (1, 15), (1, 40))))
}
}

test("using outdated dependencies with --suppress-outdated-dependency-warning") {
val dependencyOsLib = "com.lihaoyi::os-lib:0.7.8"
val dependencyPprintLib = "com.lihaoyi::pprint:0.6.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object DirectiveValueParser {
}

def position(path: Either[String, os.Path]): Position =
DirectiveUtil.position(value, path, skipQuotes = isString)
DirectiveUtil.position(value, path)
}

given DirectiveValueParser[Boolean] = { (values, scopePath, path) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scala.build.preprocessing.directives

import com.virtuslab.using_directives.custom.model.{BooleanValue, EmptyValue, StringValue, Value}
import com.virtuslab.using_directives.custom.utils.ast.StringLiteral
import dependency.AnyDependency
import dependency.parser.DependencyParser

Expand All @@ -14,9 +15,16 @@ object DirectiveUtil {

def position(
v: Value[_],
path: Either[String, os.Path],
skipQuotes: Boolean = false
path: Either[String, os.Path]
): Position.File = {
val skipQuotes: Boolean = v match {
case stringValue: StringValue =>
stringValue.getRelatedASTNode match {
case literal: StringLiteral => literal.getIsWrappedDoubleQuotes()
case _ => false
}
case _ => false
}
val line = v.getRelatedASTNode.getPosition.getLine
val column = v.getRelatedASTNode.getPosition.getColumn + (if (skipQuotes) 1 else 0)
val endLinePos = column + v.toString.length
Expand All @@ -31,13 +39,13 @@ object DirectiveUtil {
): Seq[Positioned[String]] =
scopedDirective.directive.values.map {
case v: StringValue =>
val pos = position(v, scopedDirective.maybePath, skipQuotes = true)
val pos = position(v, scopedDirective.maybePath)
Positioned(pos, v.get)
case v: BooleanValue =>
val pos = position(v, scopedDirective.maybePath, skipQuotes = false)
val pos = position(v, scopedDirective.maybePath)
Positioned(pos, v.get.toString)
case v: EmptyValue =>
val pos = position(v, scopedDirective.maybePath, skipQuotes = false)
val pos = position(v, scopedDirective.maybePath)
Positioned(pos, v.get)
}

Expand Down
2 changes: 1 addition & 1 deletion project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ object Deps {
val typelevelToolkitVersion = "0.0.11"
def typelevelToolkit = ivy"org.typelevel:toolkit:$typelevelToolkitVersion"
def typelevelToolkitTest = ivy"org.typelevel:toolkit-test:$typelevelToolkitVersion"
def usingDirectives = ivy"org.virtuslab:using_directives:1.0.0"
def usingDirectives = ivy"org.virtuslab:using_directives:1.1.0"
// Lives at https://github.com/scala-cli/no-crc32-zip-input-stream, see #865
// This provides a ZipInputStream that doesn't verify CRC32 checksums, that users
// can enable by setting SCALA_CLI_VENDORED_ZIS=true in the environment, to workaround
Expand Down