diff --git a/compiler/src/main/scala/com/rawlabs/compiler/CompilerServiceProvider.scala b/compiler/src/main/scala/com/rawlabs/compiler/CompilerServiceProvider.scala index 1a670e1e2..307776499 100644 --- a/compiler/src/main/scala/com/rawlabs/compiler/CompilerServiceProvider.scala +++ b/compiler/src/main/scala/com/rawlabs/compiler/CompilerServiceProvider.scala @@ -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") } } } diff --git a/compiler/src/main/scala/com/rawlabs/compiler/Errors.scala b/compiler/src/main/scala/com/rawlabs/compiler/Errors.scala index a78168e37..7363e353f 100644 --- a/compiler/src/main/scala/com/rawlabs/compiler/Errors.scala +++ b/compiler/src/main/scala/com/rawlabs/compiler/Errors.scala @@ -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] @@ -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) diff --git a/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/completions.proto b/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/completions.proto new file mode 100644 index 000000000..467ff42c6 --- /dev/null +++ b/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/completions.proto @@ -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; +} \ No newline at end of file diff --git a/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/docs.proto b/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/docs.proto index ed9d852d0..4b64d019b 100644 --- a/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/docs.proto +++ b/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/docs.proto @@ -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; diff --git a/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/location_config.proto b/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/location_config.proto index 751a42359..621696d70 100644 --- a/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/location_config.proto +++ b/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/location_config.proto @@ -1,3 +1,15 @@ +/* + * 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"; @@ -6,148 +18,148 @@ option java_multiple_files = true; package com.rawlabs.protocol.compiler; message LocationConfig { - oneof config { - S3Config s3 = 1; - MySqlConfig mysql = 2; - OracleConfig oracle = 3; - PostgreSQLConfig postgresql = 4; - SQLServerConfig sqlserver = 5; - SnowflakeConfig snowflake = 6; - SqliteConfig sqlite = 7; - TeradataConfig teradata = 8; - GitHubConfig github = 9; - JiraConfig jira = 10; - ConfluenceConfig confluence = 11; - SalesforceConfig salesforce = 12; - DropboxAccessTokenConfig dropboxAccessToken = 13; - DropboxUsernamePasswordConfig dropboxUsernamePassword = 14; - HttpHeadersConfig httpHeaders = 15; - SecretConfig secret = 99; - ErrorConfig error = 9999; - } + oneof config { + S3Config s3 = 1; + MySqlConfig mysql = 2; + OracleConfig oracle = 3; + PostgreSQLConfig postgresql = 4; + SQLServerConfig sqlserver = 5; + SnowflakeConfig snowflake = 6; + SqliteConfig sqlite = 7; + TeradataConfig teradata = 8; + GitHubConfig github = 9; + JiraConfig jira = 10; + ConfluenceConfig confluence = 11; + SalesforceConfig salesforce = 12; + DropboxAccessTokenConfig dropboxAccessToken = 13; + DropboxUsernamePasswordConfig dropboxUsernamePassword = 14; + HttpHeadersConfig httpHeaders = 15; + SecretConfig secret = 99; + ErrorConfig error = 9999; + } } message S3Config { - optional S3AccessSecretKey accessSecretKey = 1; - optional string region = 2; + optional S3AccessSecretKey accessSecretKey = 1; + optional string region = 2; } message S3AccessSecretKey { - string accessKey = 1; - string secretKey = 2; + string accessKey = 1; + string secretKey = 2; } message MySqlConfig { - string host = 1; - int32 port = 2; - string database = 3; - string user = 4; - string password = 5; + string host = 1; + int32 port = 2; + string database = 3; + string user = 4; + string password = 5; } message OracleConfig { - string host = 1; - int32 port = 2; - string database = 3; - string user = 4; - string password = 5; - optional string schema = 6; + string host = 1; + int32 port = 2; + string database = 3; + string user = 4; + string password = 5; + optional string schema = 6; } message PostgreSQLConfig { - string host = 1; - int32 port = 2; - string database = 3; - string user = 4; - string password = 5; - optional string schema = 6; + string host = 1; + int32 port = 2; + string database = 3; + string user = 4; + string password = 5; + optional string schema = 6; } message SQLServerConfig { - string host = 1; - int32 port = 2; - string database = 3; - string user = 4; - string password = 5; - optional string schema = 6; + string host = 1; + int32 port = 2; + string database = 3; + string user = 4; + string password = 5; + optional string schema = 6; } message SnowflakeConfig { - string database = 1; - string user = 2; - string password = 3; - string accountIdentifier = 4; - map parameters = 5; - optional string schema = 6; + string database = 1; + string user = 2; + string password = 3; + string accountIdentifier = 4; + map parameters = 5; + optional string schema = 6; } message SqliteConfig { - string path = 1; - optional string schema = 2; + string path = 1; + optional string schema = 2; } message TeradataConfig { - string host = 1; - int32 port = 2; - string database = 3; - string user = 4; - string password = 5; - map parameters = 6; - optional string schema = 7; + string host = 1; + int32 port = 2; + string database = 3; + string user = 4; + string password = 5; + map parameters = 6; + optional string schema = 7; } message GitHubConfig { - string token = 1; - optional string baseUrl = 2; + string token = 1; + optional string baseUrl = 2; } message JiraConfig { - string baseUrl = 1; - string username = 2; - string token = 3; - JiraTokenType tokenType = 4; -} + string baseUrl = 1; + string username = 2; + string token = 3; + JiraTokenType tokenType = 4; -enum JiraTokenType { + enum JiraTokenType { STANDARD_ACCESS_TOKEN = 0; PERSONAL_ACCESS_TOKEN = 1; + } } message ConfluenceConfig { - string baseUrl = 1; - string username = 2; - string token = 3; + string baseUrl = 1; + string username = 2; + string token = 3; } message SalesforceConfig { - string url = 1; - string username = 2; - string password = 3; - string securityToken = 4; - string clientId = 5; - string apiVersion = 6; - repeated string customObjects = 7; + string url = 1; + string username = 2; + string password = 3; + string securityToken = 4; + string clientId = 5; + string apiVersion = 6; + repeated string customObjects = 7; } message DropboxAccessTokenConfig { - string accessToken = 1; + string accessToken = 1; } message DropboxUsernamePasswordConfig { - string username = 1; - string password = 2; + string username = 1; + string password = 2; } message HttpHeadersConfig { - map headers = 1; + map headers = 1; } // This is not used in practice but is kept for compatibility with FDW interface. message SecretConfig { - string name = 1; - string value = 2; + string name = 1; + string value = 2; } message ErrorConfig { - string message = 1; + string message = 1; } \ No newline at end of file diff --git a/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/messages.proto b/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/messages.proto index 14c746b5b..cd4effd2a 100644 --- a/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/messages.proto +++ b/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/messages.proto @@ -20,7 +20,10 @@ package com.rawlabs.protocol.compiler; message Message { string message = 1; repeated Range positions = 2; - optional string code = 3; + string code = 3; + repeated int32 tags = 4; + Severity severity = 5; + enum Severity { HINT = 0; INFO = 10; diff --git a/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/program_environment.proto b/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/program_environment.proto index 4e8fc78f6..412353f4b 100644 --- a/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/program_environment.proto +++ b/protocol-compiler/src/main/protobuf/com/rawlabs/protocol/compiler/program_environment.proto @@ -17,6 +17,7 @@ option java_multiple_files = true; package com.rawlabs.protocol.compiler; +import "com/rawlabs/protocol/raw/values.proto"; import "com/rawlabs/protocol/compiler/location_config.proto"; message ProgramEnvironment { @@ -36,5 +37,5 @@ message Arguments { message Argument { string name = 1; - string value = 2; + com.rawlabs.protocol.raw.Value value = 2; } \ No newline at end of file