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

Minor fixes to compiler protocol #493

Merged
merged 2 commits into from
Aug 23, 2024
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.
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 @@ -54,11 +54,11 @@ object CompilerServiceProvider {
private def build(language: String)(implicit settings: RawSettings): CompilerService = {
val services = ServiceLoader.load(classOf[CompilerServiceBuilder]).asScala.toArray
if (services.isEmpty) {
throw new CompilerException("no compiler service available")
throw new AssertionError("no compiler service available")
} else {
services.find(p => p.language.contains(language)) match {
case Some(builder) => builder.build
case None => throw new CompilerException(s"cannot find compiler service: $language")
case None => throw new AssertionError(s"cannot find compiler service: $language")
}
}
}
Expand Down
41 changes: 6 additions & 35 deletions compiler/src/main/scala/com/rawlabs/compiler/Errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,15 @@

package com.rawlabs.compiler

import com.fasterxml.jackson.annotation.{JsonSubTypes, JsonTypeInfo}
import com.fasterxml.jackson.annotation.JsonSubTypes.{Type => JsonType}
import com.rawlabs.utils.core.RawException

/**
* Used for errors that are found during semantic analysis.
* message The error message.
* positions The positions where the error occurred.
* severity The severity of the error. 1 = Hint, 2 = Info, 4 = Warning, 8 = Error (compliant with monaco editor).
* - The below two should only be set by compiler errors
* code An optional error code.
* tags Indication for the error Unnecessary = 1, Deprecated = 2 (compliant with monaco editor).
*
* - message: The error message.
* - positions: The positions where the error occurred.
* - severity: The severity of the error. 1 = Hint, 2 = Info, 4 = Warning, 8 = Error (compliant with monaco editor).
* - code: An optional error code (should only be set by compiler errors)
* - tags: Indication for the error Unnecessary = 1, Deprecated = 2 (compliant with monaco editor).
*/

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes(
Array(
new JsonType(value = classOf[HintMessage], name = "hint"),
new JsonType(value = classOf[InfoMessage], name = "info"),
new JsonType(value = classOf[WarningMessage], name = "warning"),
new JsonType(value = classOf[ErrorMessage], name = "hint")
)
)
sealed trait Message {
val message: String
val positions: List[ErrorRange]
Expand Down Expand Up @@ -77,18 +63,3 @@ final case class ErrorMessage(

final case class ErrorRange(begin: ErrorPosition, end: ErrorPosition)
final case class ErrorPosition(line: Int, column: Int)

/**
* Used for exceptions that are thrown by the compiler itself.
* Must abort compilation.
* Should NOT BE USED for:
* - semantic analysis errors or other normal errors since there is no tracking of positions.
* - errors during execution.
* Should BE USED for:
* - errors that are not found during type checking but which prevent the compiler from proceeding, e.g.
* missing implementations or the like.
* Parsing may throw this exception if they encounter an error that they cannot recover from.
*
* The message can be safely shared with the user.
*/
sealed class CompilerException(message: String, cause: Throwable = null) extends RawException(message, cause)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2024 RAW Labs S.A.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.txt.
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0, included in the file
* licenses/APL.txt.
*/

syntax = "proto3";

option java_package = "com.rawlabs.protocol.compiler";
option java_multiple_files = true;

import "com/rawlabs/protocol/compiler/docs.proto";

package com.rawlabs.protocol.compiler;

message Completion {
oneof completion {
TypeCompletion type = 1;
FieldCompletion field = 2;
LetBindCompletion letBind = 3;
LetFunCompletion letFun = 4;
LetFunRecCompletion letFunRec = 5;
FunParamCompletion funParam = 6;
PackageCompletion package = 7;
EntryCompletion entry = 8;
}
}

message TypeCompletion {
string name = 1;
string type = 2;
}

message FieldCompletion {
string name = 1;
string type = 2;
}

message LetBindCompletion {
string name = 1;
string type = 2;
}

message LetFunCompletion {
string name = 1;
string type = 2;
}

message LetFunRecCompletion {
string name = 1;
string type = 2;
}

message FunParamCompletion {
string name = 1;
string type = 2;
}

message PackageCompletion {
string name = 1;
PackageDoc doc = 2;
}

message EntryCompletion {
string name = 1;
EntryDoc doc = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ message PackageDoc {
optional string danger = 4;
}

message EntryCompletion {
string name = 1;
EntryDoc doc = 2;
}

message EntryDoc {
string summary = 1;
optional string description = 2;
Expand Down
Loading