Skip to content

Commit

Permalink
Merge pull request #955 from aml-org/r/v6.0.1
Browse files Browse the repository at this point in the history
R/v6.0.1 W-13999714
  • Loading branch information
emilianoascona authored Aug 25, 2023
2 parents 7f48d9d + 87bb11a commit 275cc4d
Show file tree
Hide file tree
Showing 120 changed files with 526 additions and 496 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ trait BaseCodeActionTests extends AsyncFlatSpec with Matchers with FileAssertion
}

protected val dummyTelemetryProvider: TelemetryProvider = new TelemetryProvider {
override protected def addTimedMessage(
override def addTimedMessage(
code: String,
messageType: MessageTypes,
msg: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package org.mulesoft.als.common

import amf.core.internal.remote.File
import amf.core.internal.unsafe.PlatformSecrets
import org.mulesoft.als.common.URIImplicits._

import scala.concurrent.Future

trait DirectoryResolver {
val FilePrefix = "file://"
trait DirectoryResolver extends PlatformSecrets {
def exists(path: String): Future[Boolean]

def readDir(path: String): Future[Seq[String]]

def isDirectory(path: String): Future[Boolean]

def toPath(uri: String): String =
File.unapply(uri).getOrElse(uri)
uri.toPath(platform)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import amf.core.internal.remote.Platform
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class PlatformDirectoryResolver(private val platform: Platform) extends DirectoryResolver {
override def exists(uri: String): Future[Boolean] = platform.fs.asyncFile(FileUtils.getPath(uri, platform)).exists
class PlatformDirectoryResolver(override val platform: Platform) extends DirectoryResolver {
override def exists(uri: String): Future[Boolean] = platform.fs.asyncFile(toPath(uri)).exists

override def readDir(uri: String): Future[Seq[String]] =
platform.fs.asyncFile(FileUtils.getPath(uri, platform)).list.map(array => array.toSeq)
platform.fs.asyncFile(toPath(uri)).list.map(array => array.toSeq)

override def isDirectory(uri: String): Future[Boolean] =
platform.fs.asyncFile(FileUtils.getPath(uri, platform)).isDirectory

override def toPath(uri: String): String = FileUtils.getPath(uri, platform)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait AbstractLogger extends Logger {

filtered.foreach(logMessage => {
val toLog =
f" ${logMessage.severity} ${logMessage.component}:${logMessage.subComponent} ${logMessage.content}"
f"[${logMessage.severity}] - ${logMessage.component}:${logMessage.subComponent} - ${logMessage.content}"
this.executeLogging(toLog, logMessage.severity)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.mulesoft.als.logger

import org.mulesoft.als.logger.MessageSeverity.MessageSeverity
import org.mulesoft.lsp.feature.telemetry.MessageTypes.MessageTypes
import org.mulesoft.lsp.feature.telemetry.TelemetryProvider

import scala.scalajs.js.annotation.JSExportAll

Expand Down Expand Up @@ -53,3 +55,48 @@ trait Logger {
*/
def error(message: String, component: String, subComponent: String): Unit
}

object Logger extends Logger with TelemetryProvider {

var delegateLogger: Logger = PrintLnLogger
var delegateTelemetryProvider: Option[TelemetryProvider] = None

def withLogger(logger: Logger): this.type = {
delegateLogger = logger
this
}
def withTelemetry(telemetry: TelemetryProvider): this.type = {
delegateTelemetryProvider = Some(telemetry)
this
}

override def log(message: String, severity: MessageSeverity, component: String, subComponent: String): Unit = {
delegateLogger.log(message, severity, component, subComponent)
}

override def debug(message: String, component: String, subComponent: String): Unit = {
delegateLogger.debug(message, component, subComponent)
}

override def warning(message: String, component: String, subComponent: String): Unit = {
delegateLogger.warning(message, component, subComponent)
}

override def error(message: String, component: String, subComponent: String): Unit = {
delegateLogger.error(message, component, subComponent)
}

override def addTimedMessage(
code: String,
messageType: MessageTypes,
msg: String,
uri: String,
uuid: String
): Unit = {
delegateTelemetryProvider.foreach(_.addTimedMessage(code, messageType, msg, uri, uuid))
}

override def addErrorMessage(code: String, msg: String, uri: String, uuid: String): Unit = {
delegateTelemetryProvider.foreach(_.addErrorMessage(code, msg, uri, uuid))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ package org.mulesoft.amfintegration.amfconfiguration

import amf.aml.client.scala.AMLConfiguration
import amf.aml.client.scala.model.document.Dialect
import amf.apicontract.client.scala.{
AMFConfiguration,
APIConfiguration,
AsyncAPIConfiguration,
OASConfiguration,
RAMLConfiguration
}
import amf.core.client.scala.AMFParseResult
import amf.apicontract.client.scala.{AsyncAPIConfiguration, OASConfiguration, RAMLConfiguration}
import amf.core.client.scala.model.document.BaseUnit
import amf.core.client.scala.parse.AMFSyntaxParsePlugin
import amf.core.client.scala.resource.ResourceLoader
Expand All @@ -18,7 +11,7 @@ import amf.core.internal.remote.Spec
import amf.core.internal.unsafe.PlatformSecrets
import amf.graphql.client.scala.GraphQLConfiguration
import amf.shapes.client.scala.config.JsonSchemaConfiguration
import org.mulesoft.als.logger.{EmptyLogger, Logger}
import org.mulesoft.als.logger.Logger
import org.mulesoft.amfintegration.AmfImplicits.DialectInstanceImp
import org.mulesoft.amfintegration.dialect.integration.BaseAlsDialectProvider
import org.mulesoft.amfintegration.vocabularies.integration.{
Expand All @@ -38,8 +31,7 @@ trait EditorConfigurationProvider {
case class EditorConfiguration(
resourceLoaders: Seq[ResourceLoader],
syntaxPlugins: Seq[AMFSyntaxParsePlugin],
validationPlugin: Seq[AMFShapePayloadValidationPlugin],
logger: Logger
validationPlugin: Seq[AMFShapePayloadValidationPlugin]
) extends EditorConfigurationProvider { // todo: add hot reload

val baseConfiguration: AMLConfiguration = AMLConfiguration
Expand Down Expand Up @@ -116,14 +108,14 @@ case class EditorConfiguration(
def withDialect(uri: String): EditorConfiguration = synchronized {
dialects = uri +: dialects
parsedDialects = parseDialects
logger.debug(s"New editor dialect: $uri", "EditorConfiguration", "indexDialect")
Logger.debug(s"New editor dialect: $uri", "EditorConfiguration", "indexDialect")
this
}

def withProfile(uri: String): EditorConfiguration = synchronized {
profiles = uri +: profiles
parsedProfiles = parseProfiles
logger.debug(s"New editor validation profile: $uri", "EditorConfiguration", "indexProfile")
Logger.debug(s"New editor validation profile: $uri", "EditorConfiguration", "indexProfile")
this
}
}
Expand Down Expand Up @@ -154,14 +146,12 @@ object EditorConfigurationState {

object EditorConfiguration extends PlatformSecrets {
def apply(): EditorConfiguration = withPlatformLoaders(Seq.empty)
def apply(logger: Logger): EditorConfiguration =
EditorConfiguration(platform.loaders(), Seq.empty, Seq.empty, logger)

def withPlatformLoaders(rls: Seq[ResourceLoader]): EditorConfiguration =
EditorConfiguration(rls ++ platform.loaders(), Seq.empty, Seq.empty, EmptyLogger)
EditorConfiguration(rls ++ platform.loaders(), Seq.empty, Seq.empty)

def withoutPlatformLoaders(rls: Seq[ResourceLoader]): EditorConfiguration =
EditorConfiguration(rls, Seq.empty, Seq.empty, EmptyLogger)
EditorConfiguration(rls, Seq.empty, Seq.empty)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package org.mulesoft.amfintegration.visitors.links
import amf.core.client.scala.model.document.BaseUnit
import org.mulesoft.als.common.dtoTypes.PositionRange
import org.mulesoft.als.convert.LspRangeConverter
import org.mulesoft.als.logger.{EmptyLogger, Logger}
import org.mulesoft.amfintegration.AmfImplicits.AmfAnnotationsImp
import org.mulesoft.lsp.feature.link.DocumentLink

object FindLinks {
def getLinks(bu: BaseUnit, log: Logger = EmptyLogger): Seq[DocumentLink] =
def getLinks(bu: BaseUnit): Seq[DocumentLink] =
bu.annotations
.targets()
.flatMap { case (targetLocation, originRange) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.mulesoft.als.common

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

import scala.concurrent.Future

class DirectoryResolverTest extends AnyFlatSpec with Matchers {

private val dr = new DirectoryResolver {
override def exists(path: String): Future[Boolean] = ???

override def readDir(path: String): Future[Seq[String]] = ???

override def isDirectory(path: String): Future[Boolean] = ???
}

behavior of "Directory Resolver"

it should "transform simple absolute URI to Path" in {
dr.toPath("file:///my/path") shouldBe "/my/path"
}

it should "transform simple relative URI to Path" in {
dr.toPath("file://my/path") shouldBe "my/path"
}

it should "transform URI with spaces to Path" in {
dr.toPath("file:///my/path%20with%20spaces") shouldBe "/my/path with spaces"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,23 @@ object MessageTypes extends Enumeration {
val END_CUSTOM_DIAGNOSTIC = "END_CUSTOM_DIAGNOSTIC"
val BEGIN_GET_WORKSPACE_CONFIGURATION = "BEGIN_GET_WORKSPACE_CONFIGURATION"
val END_GET_WORKSPACE_CONFIGURATION = "END_GET_WORKSPACE_CONFIGURATION"
val BEGIN_EXCHANGE_CLIENT = "BEGIN_EXCHANGE_CLIENT"
val END_EXCHANGE_CLIENT = "END_EXCHANGE_CLIENT"
val BEGIN_GET_DEPENDENCY_MODEL = "BEGIN_GET_DEPENDENCY_MODEL"
val END_GET_DEPENDENCY_MODEL = "END_GET_DEPENDENCY_MODEL"
val BEGIN_GET_DESCRIPTOR = "BEGIN_GET_DESCRIPTOR"
val END_GET_DESCRIPTOR = "END_GET_DESCRIPTOR"
val BEGIN_SET_DESCRIPTOR = "BEGIN_SET_DESCRIPTOR"
val END_SET_DESCRIPTOR = "END_SET_DESCRIPTOR"
val BEGIN_GET_METADATA = "BEGIN_GET_METADATA"
val END_GET_METADATA = "END_GET_METADATA"
val BEGIN_GET_ASSET = "BEGIN_GET_ASSET"
val END_GET_ASSET = "END_GET_ASSET"
}

trait TelemetryProvider {

protected def addTimedMessage(code: String, messageType: MessageTypes, msg: String, uri: String, uuid: String): Unit
def addTimedMessage(code: String, messageType: MessageTypes, msg: String, uri: String, uuid: String): Unit
def addErrorMessage(code: String, msg: String, uri: String, uuid: String): Unit

final def timeProcess[T](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Main extends PlatformSecrets {

val logger = JsPrintLnLogger()

val clientConnection = ClientNotifierFactory.createWithClientAware(logger)
val clientConnection = ClientNotifierFactory.createWithClientAware
val serializationProps = JsSerializationProps(clientConnection)

val languageServer = new AlsLanguageServerFactory(clientConnection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.mulesoft.als.server.modules.diagnostic
import amf.core.client.scala.AMFGraphConfiguration
import amf.custom.validation.client.ProfileValidatorNodeBuilder
import org.mulesoft.als.common.ByDirectoryTest
import org.mulesoft.als.logger.Logger
import org.mulesoft.als.server.client.scala.LanguageServerBuilder
import org.mulesoft.als.server.feature.diagnostic.CustomValidationClientCapabilities
import org.mulesoft.als.server.modules.WorkspaceManagerFactoryBuilder
Expand All @@ -24,7 +25,7 @@ import scala.concurrent.Future
class NodeJsCustomValidationByDirectoryTest extends ByDirectoryTest with ChangesWorkspaceConfiguration {
def rootPath: String = "custom-validation/byDirectory"

val logger: TestLogger = TestLogger()
Logger.withLogger(TestLogger())
override def fileExtensions: Seq[String] = Seq(".yaml")

override def testFile(content: String, file: SyncFile, parent: String): Unit = {
Expand Down Expand Up @@ -101,7 +102,7 @@ class NodeJsCustomValidationByDirectoryTest extends ByDirectoryTest with Changes
}

def buildServer(diagnosticNotifier: MockDiagnosticClientNotifier): LanguageServer = {
val builder = new WorkspaceManagerFactoryBuilder(diagnosticNotifier, logger, EditorConfiguration())
val builder = new WorkspaceManagerFactoryBuilder(diagnosticNotifier, EditorConfiguration())
val dm = builder.buildDiagnosticManagers(Some(ProfileValidatorNodeBuilder))
val factory = builder.buildWorkspaceManagerFactory()
val b = new LanguageServerBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NodeJsCustomValidationTest
override def rootPath: String = "custom-validation"

def buildServer(diagnosticNotifier: MockDiagnosticClientNotifier): LanguageServer = {
val builder = new WorkspaceManagerFactoryBuilder(diagnosticNotifier, logger, EditorConfiguration())
val builder = new WorkspaceManagerFactoryBuilder(diagnosticNotifier, EditorConfiguration())
val dm = builder.buildDiagnosticManagers(Some(ProfileValidatorNodeBuilder))
val factory = builder.buildWorkspaceManagerFactory()
val b = new LanguageServerBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import scala.scalajs.js.annotation.{JSExportAll, JSExportTopLevel}
@JSExportAll
@JSExportTopLevel("ClientNotifierFactory")
object ClientNotifierFactory {
def createWithClientAware(
logger: JsClientLogger
): ClientNotifier with LspLanguageClientAware with AlsClientNotifier[js.Any] with AlsLanguageClientAware[js.Any] =
ClientConnection[js.Any](ClientLoggerAdapter(logger))
def createWithClientAware
: ClientNotifier with LspLanguageClientAware with AlsClientNotifier[js.Any] with AlsLanguageClientAware[js.Any] =
ClientConnection[js.Any]()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.mulesoft.als.server.lsp4j

import org.eclipse.lsp4j.jsonrpc.Launcher
import org.eclipse.lsp4j.services.LanguageClient
import org.mulesoft.als.logger.{Logger, PrintLnLogger}
import org.mulesoft.als.server.JvmSerializationProps
import org.mulesoft.als.server.client.{AlsLanguageClientExtensions, AlsLanguageClientWrapper, platform}
Expand Down Expand Up @@ -57,11 +56,12 @@ object Main {
}

val logger: Logger = PrintLnLogger
val clientConnection = platform.ClientConnection[StringWriter](logger)
val clientConnection = platform.ClientConnection[StringWriter]()

logger.debug("Building LanguageServerImpl", "Main", "main")
val server = new LanguageServerImpl(
new AlsLanguageServerFactory(clientConnection)
.withLogger(logger)
.withSerializationProps(JvmSerializationProps(clientConnection))
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait AMFValidatorTest extends LanguageServerBaseTest with PlatformSecrets {
case class TestValidator(fn: () => Unit) extends AMFShapePayloadValidationPlugin {
override def applies(element: ValidatePayloadRequest): Boolean = {
fn()
logger.debug(s"Test validator called", "TestValidator", "applies")
logger.debug("Test validator called", "TestValidator", "applies")
false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ class Lsp4jLanguageServerDiagnosticImplTest extends LanguageServerBaseTest with
}

def buildServer(diagnosticsClient: MockDiagnosticClientNotifier): LanguageServer = {
val builder = new WorkspaceManagerFactoryBuilder(diagnosticsClient, logger)

val builder = new WorkspaceManagerFactoryBuilder(diagnosticsClient)
val dm = builder.buildDiagnosticManagers()
val managers = builder.buildWorkspaceManagerFactory()

Expand Down
Loading

0 comments on commit 275cc4d

Please sign in to comment.