Skip to content

Commit

Permalink
Merge pull request #1042 from aml-org/r/v6.2.2
Browse files Browse the repository at this point in the history
R/v6.2.2
  • Loading branch information
emilianoascona authored Jul 4, 2024
2 parents ece397f + e94cf07 commit ea27fb3
Show file tree
Hide file tree
Showing 41 changed files with 343 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.concurrent.Future
trait AmfResolvedUnit extends UnitWithNextReference {
override protected type T = AmfResolvedUnit
val alsConfigurationState: ALSConfigurationState
val configuration: AMLSpecificConfiguration = AMLSpecificConfiguration(alsConfigurationState.getAmfConfig)
val configuration: AMLSpecificConfiguration = AMLSpecificConfiguration(alsConfigurationState.getAmfConfig(false))

protected def resolvedUnitFn(): Future[AMFResult]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ case class ALSConfigurationState(
editorResourceLoader: Option[ResourceLoader]
) extends PlatformSecrets {

lazy val amfParseContext: AmfParseContext = AmfParseContext(getAmfConfig, this)
lazy val amfParseContext: AmfParseContext = AmfParseContext(getAmfConfig(false), this)

def configForUnit(unit: BaseUnit): AMLSpecificConfiguration =
configForSpec(unit.sourceSpec.getOrElse(Spec.AML))

private val rootConfiguration: AMFConfiguration = projectState.rootProjectConfiguration
private def rootConfiguration(asMain: Boolean): AMFConfiguration = projectState.rootProjectConfiguration(asMain)

def configForDialect(d: Dialect): AMLSpecificConfiguration =
ProfileMatcher.spec(d) match {
Expand All @@ -52,14 +52,16 @@ case class ALSConfigurationState(
.contains(
"file://vocabularies/dialects/metadialect.yaml"
) => // TODO change when Dialect name and version be spec
AMLSpecificConfiguration(rootConfiguration)
AMLSpecificConfiguration(rootConfiguration(false))
case Some(spec) => configForSpec(spec)
case _ => AMLSpecificConfiguration(predefinedWithDialects)
}

def configForSpec(spec: Spec): AMLSpecificConfiguration =
def configForSpec(spec: Spec): AMLSpecificConfiguration = // todo: check if asMain = true has any inconvenience
AMLSpecificConfiguration(
getAmlConfig(apiConfigurationForSpec(spec).map(projectState.customSetUp).getOrElse(predefinedWithDialects))
getAmlConfig(
apiConfigurationForSpec(spec).map(projectState.customSetUp(_, asMain = true)).getOrElse(predefinedWithDialects)
)
)

private def apiConfigurationForSpec(spec: Spec): Option[AMFConfiguration] =
Expand All @@ -76,15 +78,15 @@ case class ALSConfigurationState(
case _ => None
}

def getAmfConfig(url: String): AMFConfiguration = {
def getAmfConfig(url: String, asMain: Boolean): AMFConfiguration = {
val base =
if (url.endsWith("graphql"))
projectState.getProjectConfig
else getAmfConfig.withPlugins(editorState.alsParsingPlugins)
getAmfConfig(base)
projectState.getProjectConfig(asMain)
else getAmfConfig(asMain).withPlugins(editorState.alsParsingPlugins)
getAmfConfig(base, asMain)
}

def getAmfConfig: AMFConfiguration = getAmfConfig(rootConfiguration)
def getAmfConfig(asMain: Boolean): AMFConfiguration = getAmfConfig(rootConfiguration(asMain), asMain)

def getAmfConfig(spec: Spec): AMFConfiguration = {
val base = spec match {
Expand All @@ -93,7 +95,7 @@ case class ALSConfigurationState(
case _ =>
APIConfiguration.fromSpec(spec)
}
getAmfConfig(base)
getAmfConfig(base, asMain = true) // todo: check if asMain = true has any inconvenience
}

def allDialects: Seq[Dialect] = dialects ++ BaseAlsDialectProvider.allBaseDialects
Expand All @@ -118,14 +120,14 @@ case class ALSConfigurationState(
dialects.foldLeft(configuration)((c, dialect) => c.withDialect(dialect))
}

def getAmfConfig(base: AMFConfiguration): AMFConfiguration =
projectState.customSetUp(getAmlConfig(base).asInstanceOf[AMFConfiguration])
def getAmfConfig(base: AMFConfiguration, asMain: Boolean): AMFConfiguration =
projectState.customSetUp(getAmlConfig(base).asInstanceOf[AMFConfiguration], asMain)

def findSemanticByName(name: String): Option[(SemanticExtension, Dialect)] =
configForSpec(Spec.AML).config.configurationState().findSemanticByName(name)

def parse(url: String, maxFileSize: Option[Int] = None): Future[AmfParseResult] =
parse(getAmfConfig(url), url, maxFileSize)
def parse(url: String, asMain: Boolean = false, maxFileSize: Option[Int] = None): Future[AmfParseResult] =
parse(getAmfConfig(url, asMain), url, maxFileSize)

private def parse(amfConfiguration: AMFConfiguration, uri: String, maxFileSize: Option[Int]): Future[AmfParseResult] =
wrapLoadersIfNeeded(amfConfiguration, maxFileSize)
Expand Down Expand Up @@ -189,12 +191,12 @@ case class ALSConfigurationState(
}

def findSemanticFor(uri: String): Seq[(SemanticExtension, Dialect)] =
getAmfConfig(uri)
getAmfConfig(uri, asMain = true) // todo: check if asMain = true has any inconvenience
.configurationState()
.findSemanticByTarget(uri)

def findSemanticForName(name: String): Option[(SemanticExtension, Dialect)] =
getAmfConfig
getAmfConfig(false)
.configurationState()
.findSemanticByName(name)

Expand Down Expand Up @@ -254,12 +256,12 @@ case class ALSConfigurationState(
predefinedWithDialects.configurationState().getDialects().find(_.nameAndVersion() == nameAndVersion)

def fetchContent(uri: String): Future[Content] = try {
platform.fetchContent(uri, getAmfConfig)
platform.fetchContent(uri, getAmfConfig(false))
} catch {
case e: Exception =>
Future.failed(e)
}

def buildJsonSchema(shape: AnyShape): String =
JsonSchemaShapeRenderer.buildJsonSchema(shape, getAmfConfig)
JsonSchemaShapeRenderer.buildJsonSchema(shape, getAmfConfig(false))
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ object ProfileMatcher {
DialectWithVendor(MetaDialect(), Spec.AML)
)

def dialect(spec: Spec): Option[Dialect] =
webApiDialects.find(_.spec == spec).map(_.dialect)

def spec(dialect: Dialect): Option[Spec] =
webApiDialects.find(_.dialect == dialect).map(_.spec)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.concurrent.Future

trait ProjectConfigurationState {

def customSetUp(amfConfiguration: AMFConfiguration): AMFConfiguration = amfConfiguration
def customSetUp(amfConfiguration: AMFConfiguration, asMain: Boolean): AMFConfiguration = amfConfiguration
def cache: UnitCache
def getCompanionForDialect(d: Dialect): Future[Option[Module]] =
Future
Expand All @@ -30,17 +30,16 @@ trait ProjectConfigurationState {
)
.map(r => r.flatten.find(_._2).map(_._1))

def getProjectConfig: AMFConfiguration = {
def getProjectConfig(asMain: Boolean): AMFConfiguration =
GraphQLConfiguration.GraphQL()
}

val extensions: Seq[Dialect]
val profiles: Seq[ValidationProfile]
val config: ProjectConfiguration
val results: Seq[AMFParseResult]
val resourceLoaders: Seq[ResourceLoader]
val projectErrors: Seq[AMFValidationResult]
val rootProjectConfiguration: AMFConfiguration = APIConfiguration.APIWithJsonSchema()
def rootProjectConfiguration(asMain: Boolean): AMFConfiguration = APIConfiguration.APIWithJsonSchema()
}

case class EmptyProjectConfigurationState(folder: String) extends ProjectConfigurationState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ class DeclarationCreatorTests extends AsyncFlatSpec with DeclarationCreator {

private def baseUnit(file: String): Future[BaseUnit] =
for {
state <- EditorConfiguration().getState
result <- ALSConfigurationState(state, EmptyProjectConfigurationState, None).parse(uriTemplate(file))
state <- EditorConfiguration().getState
result <- ALSConfigurationState(state, EmptyProjectConfigurationState, None).parse(
uriTemplate(file),
asMain = true
)
} yield {
result.result.baseUnit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ case class ObjectInTreeBaseTest(instanceFile: String, dialectFile: String) exten

private val eventualResult: Future[AmfParseResult] = {
for {
s <- global.getState
result <- ALSConfigurationState(s, EmptyProjectConfigurationState, None).parse(uriTemplate(instanceFile))
s <- global.getState
result <- ALSConfigurationState(s, EmptyProjectConfigurationState, None).parse(
uriTemplate(instanceFile),
asMain = true
)
} yield result
}
private def fn(pos: AmfPosition, result: AmfParseResult, dialect: Dialect): ObjectInTree =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ object MessageTypes extends Enumeration {
type MessageTypes = String
val BEGIN_PARSE = "BEGIN_PARSE"
val END_PARSE = "END_PARSE"
val BEGIN_PARSE_EXTERNAL = "BEGIN_PARSE_EXTERNAL"
val END_PARSE_EXTERNAL = "END_PARSE_EXTERNAL"
val BEGIN_PARSE_PATCHED = "BEGIN_PARSE_PATCHED"
val END_PARSE_PATCHED = "END_PARSE_PATCHED"
val BEGIN_REPORT = "BEGIN_REPORT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6596,6 +6596,7 @@ declare module '@aml-org/als-node-client' {
configuration?: AlsConfiguration
hotReload?: boolean
maxFileSize?: number
shouldRetryExternalFragments?: boolean
}

export type DidFocusParams = {
Expand Down
1 change: 1 addition & 0 deletions als-server/js/node-package/typescript/als-server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6596,6 +6596,7 @@ declare module '@aml-org/als-server' {
configuration?: AlsConfiguration
hotReload?: boolean
maxFileSize?: number
shouldRetryExternalFragments?: boolean
}

export type DidFocusParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ trait ClientAlsInitializeParams extends js.Object {
def workspaceFolders: js.Array[ClientWorkspaceFolder] = js.native // Nullable
def hotReload: UndefOr[Boolean] = js.native
def maxFileSize: UndefOr[Int] = js.native
def shouldRetryExternalFragments: UndefOr[Boolean] = js.native
}

object ClientAlsInitializeParams {
Expand All @@ -39,7 +40,8 @@ object ClientAlsInitializeParams {
rootPath = internal.rootPath.orUndefined,
initializationOptions = internal.initializationOptions.collect { case js: js.Object => js }.orUndefined,
hotReload = internal.hotReload.orUndefined,
maxFileSize = internal.maxFileSize.orUndefined
maxFileSize = internal.maxFileSize.orUndefined,
shouldRetryExternalFragments = internal.shouldRetryExternalFragments.orUndefined
)
.asInstanceOf[ClientAlsInitializeParams]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ object LspConvertersClientToShared {
initializationOptions = v.initializationOptions.toOption,
configuration = v.configuration.toOption.map(_.toShared),
hotReload = v.hotReload.toOption,
maxFileSize = v.maxFileSize.toOption
maxFileSize = v.maxFileSize.toOption,
shouldRetryExternalFragments = v.shouldRetryExternalFragments.toOption
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ object LspConversions {
initializationOptions = Option(p.getInitializationOptions),
configuration = Option(p.getConfiguration),
hotReload = Option(p.getHotReload),
maxFileSize = Option(p.getMaxFileSize).map(_.toInt)
maxFileSize = Option(p.getMaxFileSize).map(_.toInt),
shouldRetryExternalFragments = Option(p.getShouldRetryExternalFragments)
)
} getOrElse AlsInitializeParams.default

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class AlsInitializeParams extends InitializeParams {
private AlsClientCapabilities alsClientCapabilities;
private AlsConfiguration configuration;
private Boolean hotReload;
private Boolean shouldRetryExternalFragments;
private Integer maxFileSize;

@Override
Expand Down Expand Up @@ -39,11 +40,17 @@ public void setConfiguration(AlsConfiguration configuration) {
public Boolean getHotReload() {
return hotReload;
}

public void setHotReload(Boolean hotReload) {
this.hotReload = hotReload;
}

public Boolean getShouldRetryExternalFragments() {
return shouldRetryExternalFragments;
}
public void setShouldRetryExternalFragments(Boolean shouldRetryExternalFragments) {
this.shouldRetryExternalFragments = shouldRetryExternalFragments;
}

public Integer getMaxFileSize() {
return maxFileSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public AlsInitializeParams read(final JsonReader in) throws IOException {
case "hotReload":
result.setHotReload(readHotReload(in));
break;
case "shouldRetryExternalFragments":
result.setShouldRetryExternalFragments(readShouldRetryExternalFragments(in));
break;
case "maxFileSize":
result.setMaxFileSize(readMaxFileSize(in));
break;
Expand All @@ -109,6 +112,9 @@ public AlsInitializeParams read(final JsonReader in) throws IOException {
private Boolean readHotReload(JsonReader in) {
return gson.fromJson(in, Boolean.class);
}
private Boolean readShouldRetryExternalFragments(JsonReader in) {
return gson.fromJson(in, Boolean.class);
}

private Integer readMaxFileSize(JsonReader in) {
return gson.fromJson(in, Integer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class LanguageServerImpl(
override def initialize(params: AlsInitializeParams): Future[AlsInitializeResult] = {
logParams(params)
params.hotReload.foreach(configuration.setHotReloadDialects)
params.shouldRetryExternalFragments.foreach(configuration.setShouldRetryExternalFragments)
configuration.setMaxFileSize(params.maxFileSize)
params.configuration.foreach(c => {
updateConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait CleanAmfProcess {
alsConfigurationState: ALSConfigurationState
): Future[(AmfResultWrap, AMFResult, ALSConfigurationState)] =
for {
pr <- AMLSpecificConfiguration(alsConfigurationState.getAmfConfig(refinedUri))
pr <- AMLSpecificConfiguration(alsConfigurationState.getAmfConfig(refinedUri, asMain = true))
.parse(refinedUri)
.map(new AmfResultWrap(_))
helper <- Future(alsConfigurationState.configForUnit(pr.result.baseUnit))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class ConfigurationManager
*/
def setHotReloadDialects(p: Boolean): Unit = hotReloadDialects = p

private var shouldRetryExternalFragments: Boolean = false

override def getShouldRetryExternalFragments: Boolean = shouldRetryExternalFragments

/** Should only be called from initialization
*/
def setShouldRetryExternalFragments(p: Boolean): Unit = shouldRetryExternalFragments = p

private var maxFileSize: Option[Int] = None

override def getMaxFileSize: Option[Int] = maxFileSize
Expand All @@ -58,4 +66,5 @@ class ConfigurationManager
}

override def initialize(): Future[Unit] = { Future.successful() }

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ trait ConfigurationProvider {
def getConfiguration: AlsConfigurationReader
def getHotReloadDialects: Boolean
def getMaxFileSize: Option[Int]
def getShouldRetryExternalFragments: Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SerializationManager[S](
for {
state <- wcm.getConfigurationState(uri)
(_, resolved, configurationState) <- parseAndResolve(refinedUri, state)
} yield serialize(resolved.baseUnit, configurationState.getAmfConfig, sourcemaps)
} yield serialize(resolved.baseUnit, configurationState.getAmfConfig(false), sourcemaps)
case _ =>
Future.failed(new RuntimeException("no workspaceConfigurationManager set"))
}
Expand Down
Loading

0 comments on commit ea27fb3

Please sign in to comment.