mirror of
https://github.com/enso-org/enso.git
synced 2024-12-21 14:21:31 +03:00
Enso language support with parser in VSCode, IGV, etc. (#7054)
Outline view and completions for Enso code in VSCode. # Important Notes This PR provides the necessary infrastructure for building VSCode extension that includes `enso_parser` library compiled for all supported platforms. VSCode extension can now use libraries from `sbt` that are `publishM2`-ready. To make that possible a documentation must have been provided and fixed for those modules - hence so many changes in `.scala` classes. <img width="862" alt="image" src="https://github.com/enso-org/enso/assets/26887752/7374bf41-bdc6-4322-b562-85a2e761de2a"> Last, but not least. The outline view and completions display something.
This commit is contained in:
parent
dc6e3a7031
commit
dee9e079d4
129
.github/workflows/enso4igv.yml
vendored
129
.github/workflows/enso4igv.yml
vendored
@ -8,29 +8,127 @@ on:
|
|||||||
paths:
|
paths:
|
||||||
- ".github/workflows/enso4igv.yml"
|
- ".github/workflows/enso4igv.yml"
|
||||||
- "tools/enso4igv/**/*"
|
- "tools/enso4igv/**/*"
|
||||||
|
- "engine/**/*"
|
||||||
|
- "lib/java/**/*"
|
||||||
|
- "lib/scala/**/*"
|
||||||
|
- "build.sbt"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build_linux_parser:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
java: ["11"]
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Java
|
|
||||||
uses: actions/setup-java@v2
|
- name: Install rustup
|
||||||
|
run: |
|
||||||
|
rustup target add x86_64-unknown-linux-musl
|
||||||
|
|
||||||
|
- name: Build Enso Parser
|
||||||
|
working-directory: .
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: "-C target-feature=-crt-static"
|
||||||
|
run: |
|
||||||
|
cargo build -p enso-parser-jni -Z unstable-options --target x86_64-unknown-linux-musl --out-dir target/lib/
|
||||||
|
|
||||||
|
- name: Upload Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
distribution: "zulu"
|
name: parser_linux
|
||||||
java-version: ${{ matrix.java }}
|
path: |
|
||||||
cache: maven
|
target/lib/**
|
||||||
|
|
||||||
|
build_mac_intel_parser:
|
||||||
|
runs-on: macos-12
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build Enso Parser
|
||||||
|
working-directory: .
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: "-C target-feature=-crt-static"
|
||||||
|
run: |
|
||||||
|
cargo build -p enso-parser-jni -Z unstable-options --out-dir target/lib/x86_64
|
||||||
|
|
||||||
|
- name: Upload Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: parser_mac_intel
|
||||||
|
path: |
|
||||||
|
target/lib/**
|
||||||
|
|
||||||
|
build_mac_arm_parser:
|
||||||
|
runs-on: macos-14
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build Enso Parser
|
||||||
|
working-directory: .
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: "-C target-feature=-crt-static"
|
||||||
|
run: |
|
||||||
|
cargo build -p enso-parser-jni -Z unstable-options --out-dir target/lib/aarch64/
|
||||||
|
|
||||||
|
- name: Upload Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: parser_mac_arm
|
||||||
|
path: |
|
||||||
|
target/lib/**
|
||||||
|
|
||||||
|
build_windows_parser:
|
||||||
|
runs-on: windows-2019
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build Enso Parser
|
||||||
|
working-directory: .
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: "-C target-feature=-crt-static"
|
||||||
|
run: |
|
||||||
|
cargo build -p enso-parser-jni -Z unstable-options --out-dir target/lib/
|
||||||
|
|
||||||
|
- name: Upload Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: parser_windows
|
||||||
|
path: |
|
||||||
|
target/lib/**
|
||||||
|
|
||||||
|
build_java:
|
||||||
|
needs:
|
||||||
|
[
|
||||||
|
build_linux_parser,
|
||||||
|
build_mac_intel_parser,
|
||||||
|
build_mac_arm_parser,
|
||||||
|
build_windows_parser,
|
||||||
|
]
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Download Libraries
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: enso_parser
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
|
- name: List Binaries
|
||||||
|
run: |
|
||||||
|
find . | grep -i enso.parser
|
||||||
|
|
||||||
|
- name: Set up Rustup
|
||||||
|
run: rustup show
|
||||||
|
|
||||||
- uses: graalvm/setup-graalvm@v1
|
- uses: graalvm/setup-graalvm@v1
|
||||||
with:
|
with:
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
distribution: "graalvm-community"
|
distribution: "graalvm-community"
|
||||||
|
|
||||||
- name: Publish to Maven Repository
|
- name: Publish Enso Libraries to Local Maven Repository
|
||||||
run: sbt publishM2
|
run: sbt publishM2
|
||||||
|
|
||||||
- name: Find out pom & micro versions
|
- name: Find out pom & micro versions
|
||||||
@ -48,9 +146,10 @@ jobs:
|
|||||||
mvn versions:set -DnewVersion="$POM_VERSION.$MICRO_VERSION"
|
mvn versions:set -DnewVersion="$POM_VERSION.$MICRO_VERSION"
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build with Maven
|
||||||
run: mvn -B -Pvsix package --file tools/enso4igv/pom.xml
|
run: mvn -B -Pvsix package --file tools/enso4igv/pom.xml -Denso.parser.lib=`pwd`/enso_parser/
|
||||||
|
|
||||||
- name: Archive NBM file
|
- name: Archive NBM file
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: Enso IGV Plugin
|
name: Enso IGV Plugin
|
||||||
path: tools/enso4igv/target/*.nbm
|
path: tools/enso4igv/target/*.nbm
|
||||||
@ -62,10 +161,10 @@ jobs:
|
|||||||
run: mvn -B -Pvsix npm:exec@version --file tools/enso4igv/pom.xml
|
run: mvn -B -Pvsix npm:exec@version --file tools/enso4igv/pom.xml
|
||||||
|
|
||||||
- name: Build VSCode Extension
|
- name: Build VSCode Extension
|
||||||
run: mvn -B -Pvsix npm:run@vsix --file tools/enso4igv/pom.xml
|
run: mvn -B -Pvsix npm:run@vsix --file tools/enso4igv/pom.xml -Denso.parser.lib=`pwd`/enso_parser/
|
||||||
|
|
||||||
- name: Archive VSCode extension
|
- name: Archive VSCode extension
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: VSCode Extension
|
name: VSCode Extension
|
||||||
path: tools/enso4igv/*.vsix
|
path: tools/enso4igv/*.vsix
|
||||||
|
18
build.sbt
18
build.sbt
@ -47,7 +47,7 @@ val currentEdition = sys.env.getOrElse(
|
|||||||
// Note [Stdlib Version]
|
// Note [Stdlib Version]
|
||||||
val stdLibVersion = defaultDevEnsoVersion
|
val stdLibVersion = defaultDevEnsoVersion
|
||||||
val targetStdlibVersion = ensoVersion
|
val targetStdlibVersion = ensoVersion
|
||||||
val persistanceVersion = "0.2-SNAPSHOT"
|
val mavenUploadVersion = "0.2-SNAPSHOT"
|
||||||
|
|
||||||
// Inspired by https://www.scala-sbt.org/1.x/docs/Howto-Startup.html#How+to+take+an+action+on+startup
|
// Inspired by https://www.scala-sbt.org/1.x/docs/Howto-Startup.html#How+to+take+an+action+on+startup
|
||||||
lazy val startupStateTransition: State => State = { s: State =>
|
lazy val startupStateTransition: State => State = { s: State =>
|
||||||
@ -731,11 +731,17 @@ lazy val `syntax-rust-definition` = project
|
|||||||
.enablePlugins(JPMSPlugin)
|
.enablePlugins(JPMSPlugin)
|
||||||
.configs(Test)
|
.configs(Test)
|
||||||
.settings(
|
.settings(
|
||||||
|
version := mavenUploadVersion,
|
||||||
Compile / exportJars := true,
|
Compile / exportJars := true,
|
||||||
|
javadocSettings,
|
||||||
|
publish / skip := false,
|
||||||
|
autoScalaLibrary := false,
|
||||||
|
crossPaths := false,
|
||||||
javaModuleName := "org.enso.syntax",
|
javaModuleName := "org.enso.syntax",
|
||||||
Compile / sourceGenerators += generateParserJavaSources,
|
Compile / sourceGenerators += generateParserJavaSources,
|
||||||
Compile / resourceGenerators += generateRustParserLib,
|
Compile / resourceGenerators += generateRustParserLib,
|
||||||
Compile / javaSource := baseDirectory.value / "generate-java" / "java"
|
Compile / javaSource := baseDirectory.value / "generate-java" / "java",
|
||||||
|
Compile / compile / javacOptions ++= Seq("-source", "11", "-target", "11")
|
||||||
)
|
)
|
||||||
|
|
||||||
lazy val yaml = (project in file("lib/java/yaml"))
|
lazy val yaml = (project in file("lib/java/yaml"))
|
||||||
@ -1306,7 +1312,7 @@ lazy val `ydoc-server` = project
|
|||||||
|
|
||||||
lazy val `persistance` = (project in file("lib/java/persistance"))
|
lazy val `persistance` = (project in file("lib/java/persistance"))
|
||||||
.settings(
|
.settings(
|
||||||
version := persistanceVersion,
|
version := mavenUploadVersion,
|
||||||
Test / fork := true,
|
Test / fork := true,
|
||||||
commands += WithDebugCommand.withDebug,
|
commands += WithDebugCommand.withDebug,
|
||||||
frgaalJavaCompilerSetting,
|
frgaalJavaCompilerSetting,
|
||||||
@ -1328,7 +1334,7 @@ lazy val `persistance` = (project in file("lib/java/persistance"))
|
|||||||
|
|
||||||
lazy val `persistance-dsl` = (project in file("lib/java/persistance-dsl"))
|
lazy val `persistance-dsl` = (project in file("lib/java/persistance-dsl"))
|
||||||
.settings(
|
.settings(
|
||||||
version := persistanceVersion,
|
version := mavenUploadVersion,
|
||||||
frgaalJavaCompilerSetting,
|
frgaalJavaCompilerSetting,
|
||||||
publish / skip := false,
|
publish / skip := false,
|
||||||
autoScalaLibrary := false,
|
autoScalaLibrary := false,
|
||||||
@ -2178,6 +2184,10 @@ lazy val `runtime-benchmarks` =
|
|||||||
lazy val `runtime-parser` =
|
lazy val `runtime-parser` =
|
||||||
(project in file("engine/runtime-parser"))
|
(project in file("engine/runtime-parser"))
|
||||||
.settings(
|
.settings(
|
||||||
|
version := mavenUploadVersion,
|
||||||
|
javadocSettings,
|
||||||
|
publish / skip := false,
|
||||||
|
crossPaths := false,
|
||||||
frgaalJavaCompilerSetting,
|
frgaalJavaCompilerSetting,
|
||||||
annotationProcSetting,
|
annotationProcSetting,
|
||||||
commands += WithDebugCommand.withDebug,
|
commands += WithDebugCommand.withDebug,
|
||||||
|
@ -42,7 +42,7 @@ public final class MetadataStorage {
|
|||||||
/**
|
/**
|
||||||
* Adds a metadata pair to the node metadata.
|
* Adds a metadata pair to the node metadata.
|
||||||
*
|
*
|
||||||
* <p>This will overwrite any entry whose key matches [[MetadataPair#pass]].
|
* <p>This will overwrite any entry whose key matches {@code MetadataPair.pass}.
|
||||||
*
|
*
|
||||||
* @param <K> the concrete type of the pass
|
* @param <K> the concrete type of the pass
|
||||||
* @param metadataPair the pair to add to the storage
|
* @param metadataPair the pair to add to the storage
|
||||||
|
@ -30,7 +30,7 @@ object Implicits {
|
|||||||
|
|
||||||
/** Converts a multiline string to a single line
|
/** Converts a multiline string to a single line
|
||||||
*
|
*
|
||||||
* @return [[string]], converted to a single line
|
* @return String, converted to a single line
|
||||||
*/
|
*/
|
||||||
def toSingleLine: String = {
|
def toSingleLine: String = {
|
||||||
val lines = string.stripMargin.split("\n").toList.filterNot(_ == "")
|
val lines = string.stripMargin.split("\n").toList.filterNot(_ == "")
|
||||||
@ -69,7 +69,7 @@ object Implicits {
|
|||||||
|
|
||||||
/** Adds a metadata pair to the node metadata.
|
/** Adds a metadata pair to the node metadata.
|
||||||
*
|
*
|
||||||
* This will overwrite any entry whose key matches [[MetadataPair#pass]].
|
* This will overwrite any entry whose key matches MetadataPair#pass.
|
||||||
*
|
*
|
||||||
* @param metadataPair the pair to add to the storage
|
* @param metadataPair the pair to add to the storage
|
||||||
* @tparam K the concrete type of the pass
|
* @tparam K the concrete type of the pass
|
||||||
@ -118,7 +118,7 @@ object Implicits {
|
|||||||
*/
|
*/
|
||||||
implicit class ListAsIr[T <: IR](list: List[T]) {
|
implicit class ListAsIr[T <: IR](list: List[T]) {
|
||||||
|
|
||||||
/** Calls [[IR#duplicate]] on the elements in [[list]].
|
/** Calls [[IR#duplicate]] on the elements in list.
|
||||||
*
|
*
|
||||||
* @param keepLocations whether or not locations should be kept in the
|
* @param keepLocations whether or not locations should be kept in the
|
||||||
* duplicated IR
|
* duplicated IR
|
||||||
@ -128,7 +128,7 @@ object Implicits {
|
|||||||
* the duplicated IR
|
* the duplicated IR
|
||||||
* @param keepIdentifiers whether or not the identifiers should be
|
* @param keepIdentifiers whether or not the identifiers should be
|
||||||
* regenerated in the duplicated IR
|
* regenerated in the duplicated IR
|
||||||
* @return a duplicate of [[list]]
|
* @return a duplicate of list
|
||||||
*/
|
*/
|
||||||
def duplicate(
|
def duplicate(
|
||||||
keepLocations: Boolean = true,
|
keepLocations: Boolean = true,
|
||||||
|
@ -124,7 +124,7 @@ object CallArgument {
|
|||||||
copy(name = name.map(n => n.mapExpressions(fn)), value = fn(value))
|
copy(name = name.map(n => n.mapExpressions(fn)), value = fn(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|CallArgument.Specified(
|
|CallArgument.Specified(
|
||||||
|
@ -158,7 +158,7 @@ object DefinitionArgument {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|DefinitionArgument.Specified(
|
|DefinitionArgument.Specified(
|
||||||
|
@ -64,7 +64,7 @@ sealed case class Empty(
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Empty = this
|
): Empty = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Empty(
|
|Empty(
|
||||||
|
@ -142,7 +142,7 @@ object Expression {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Expression.Block(
|
|Expression.Block(
|
||||||
@ -254,7 +254,7 @@ object Expression {
|
|||||||
copy(name = name.mapExpressions(fn), expression = fn(expression))
|
copy(name = name.mapExpressions(fn), expression = fn(expression))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Expression.Binding(
|
|Expression.Binding(
|
||||||
|
@ -154,7 +154,7 @@ object Function {
|
|||||||
copy(arguments = arguments.map(_.mapExpressions(fn)), body = fn(body))
|
copy(arguments = arguments.map(_.mapExpressions(fn)), body = fn(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Function.Lambda(
|
|Function.Lambda(
|
||||||
@ -320,7 +320,7 @@ object Function {
|
|||||||
body = fn(body)
|
body = fn(body)
|
||||||
)
|
)
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Function.Binding(
|
|Function.Binding(
|
||||||
|
@ -92,7 +92,7 @@ object Literal {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Number = this
|
): Number = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""Literal.Number(
|
s"""Literal.Number(
|
||||||
|base = $base,
|
|base = $base,
|
||||||
@ -217,7 +217,7 @@ object Literal {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Text = this
|
): Text = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Literal.Text(
|
|Literal.Text(
|
||||||
|
@ -115,7 +115,7 @@ final case class Module(
|
|||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
override def children: List[IR] = imports ++ exports ++ bindings
|
override def children: List[IR] = imports ++ exports ++ bindings
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Module(
|
|Module(
|
||||||
|
@ -131,7 +131,7 @@ object Name {
|
|||||||
copy(location = location)
|
copy(location = location)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Name.MethodReference(
|
|Name.MethodReference(
|
||||||
@ -341,7 +341,7 @@ object Name {
|
|||||||
override def setLocation(location: Option[IdentifiedLocation]): Blank =
|
override def setLocation(location: Option[IdentifiedLocation]): Blank =
|
||||||
copy(location = location)
|
copy(location = location)
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Name.Blank(
|
|Name.Blank(
|
||||||
@ -512,7 +512,7 @@ object Name {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Literal = this
|
): Literal = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Name.Literal(
|
|Name.Literal(
|
||||||
@ -617,7 +617,7 @@ object Name {
|
|||||||
): BuiltinAnnotation =
|
): BuiltinAnnotation =
|
||||||
this
|
this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Name.BuiltinAnnotation(
|
|Name.BuiltinAnnotation(
|
||||||
@ -705,7 +705,7 @@ object Name {
|
|||||||
): GenericAnnotation =
|
): GenericAnnotation =
|
||||||
copy(expression = fn(expression))
|
copy(expression = fn(expression))
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Name.GenericAnnotation(
|
|Name.GenericAnnotation(
|
||||||
@ -786,7 +786,7 @@ object Name {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Self = this
|
): Self = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Name.Self(
|
|Name.Self(
|
||||||
@ -863,7 +863,7 @@ object Name {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): SelfType = this
|
): SelfType = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Name.SelfType(
|
|Name.SelfType(
|
||||||
|
@ -98,7 +98,7 @@ object Pattern {
|
|||||||
copy(name = name.mapExpressions(fn))
|
copy(name = name.mapExpressions(fn))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Case.Pattern.Name(
|
|Case.Pattern.Name(
|
||||||
@ -245,7 +245,7 @@ object Pattern {
|
|||||||
fields = fields.map(_.mapExpressions(fn))
|
fields = fields.map(_.mapExpressions(fn))
|
||||||
)
|
)
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Case.Pattern.Constructor(
|
|Case.Pattern.Constructor(
|
||||||
@ -342,7 +342,7 @@ object Pattern {
|
|||||||
copy(literal = literal.mapExpressions(fn))
|
copy(literal = literal.mapExpressions(fn))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Case.Pattern.Literal(
|
|Case.Pattern.Literal(
|
||||||
@ -445,7 +445,7 @@ object Pattern {
|
|||||||
copy(name = name.mapExpressions(fn), tpe = tpe.mapExpressions(fn))
|
copy(name = name.mapExpressions(fn), tpe = tpe.mapExpressions(fn))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Case.Pattern.Type(
|
|Case.Pattern.Type(
|
||||||
@ -543,7 +543,7 @@ object Pattern {
|
|||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
override def children: List[IR] = Nil
|
override def children: List[IR] = Nil
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Case.Pattern.Documentation(
|
|Case.Pattern.Documentation(
|
||||||
|
@ -41,7 +41,7 @@ object ProcessingPass {
|
|||||||
* there is no default definition for this method.
|
* there is no default definition for this method.
|
||||||
*
|
*
|
||||||
* @param compiler the Enso compiler
|
* @param compiler the Enso compiler
|
||||||
* @return `this`, but restored from serialization, or [[None]] if
|
* @return `this`, but restored from serialization, or None if
|
||||||
* restoration could not be performed
|
* restoration could not be performed
|
||||||
*/
|
*/
|
||||||
def restoreFromSerialization(compiler: Compiler): Option[Metadata]
|
def restoreFromSerialization(compiler: Compiler): Option[Metadata]
|
||||||
|
@ -97,7 +97,7 @@ object Type {
|
|||||||
copy(args = args.map(fn.asScala), result = fn(result))
|
copy(args = args.map(fn.asScala), result = fn(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""Type.Function(
|
s"""Type.Function(
|
||||||
|args = $args,
|
|args = $args,
|
||||||
@ -204,7 +204,7 @@ object Type {
|
|||||||
copy(typed = fn(typed), signature = fn(signature))
|
copy(typed = fn(typed), signature = fn(signature))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""Type.Ascription(
|
s"""Type.Ascription(
|
||||||
|typed = $typed,
|
|typed = $typed,
|
||||||
@ -310,7 +310,7 @@ object Type {
|
|||||||
copy(typed = fn(typed), context = fn(context))
|
copy(typed = fn(typed), context = fn(context))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""Type.Context(
|
s"""Type.Context(
|
||||||
|typed = $typed,
|
|typed = $typed,
|
||||||
@ -413,7 +413,7 @@ object Type {
|
|||||||
): Error =
|
): Error =
|
||||||
copy(typed = fn(typed), error = fn(error))
|
copy(typed = fn(typed), error = fn(error))
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""Type.Error(
|
s"""Type.Error(
|
||||||
|typed = $typed,
|
|typed = $typed,
|
||||||
|
@ -108,7 +108,7 @@ object Application {
|
|||||||
copy(function = fn(function), arguments.map(_.mapExpressions(fn)))
|
copy(function = fn(function), arguments.map(_.mapExpressions(fn)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Application.Prefix(
|
|Application.Prefix(
|
||||||
@ -203,7 +203,7 @@ object Application {
|
|||||||
copy(target = fn(target))
|
copy(target = fn(target))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Application.Force(
|
|Application.Force(
|
||||||
@ -316,7 +316,7 @@ object Application {
|
|||||||
location: Option[IdentifiedLocation]
|
location: Option[IdentifiedLocation]
|
||||||
): Typeset = copy(location = location)
|
): Typeset = copy(location = location)
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""Application.Typeset(
|
s"""Application.Typeset(
|
||||||
|expression = $expression,
|
|expression = $expression,
|
||||||
@ -412,7 +412,7 @@ object Application {
|
|||||||
location: Option[IdentifiedLocation]
|
location: Option[IdentifiedLocation]
|
||||||
): Sequence = copy(location = location)
|
): Sequence = copy(location = location)
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Application.Vector(
|
|Application.Vector(
|
||||||
|
@ -130,7 +130,7 @@ object Case {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Case.Expr(
|
|Case.Expr(
|
||||||
@ -283,7 +283,7 @@ object Case {
|
|||||||
copy(pattern = pattern.mapExpressions(fn), expression = fn(expression))
|
copy(pattern = pattern.mapExpressions(fn), expression = fn(expression))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Case.Branch(
|
|Case.Branch(
|
||||||
|
@ -91,7 +91,7 @@ object Comment {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Documentation = this
|
): Documentation = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Comment.Documentation(
|
|Comment.Documentation(
|
||||||
|
@ -98,7 +98,7 @@ object Error {
|
|||||||
): InvalidIR =
|
): InvalidIR =
|
||||||
this
|
this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Error.InvalidIR(
|
|Error.InvalidIR(
|
||||||
|
@ -99,7 +99,7 @@ object Foreign {
|
|||||||
): Definition =
|
): Definition =
|
||||||
this
|
this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Foreign.Definition(
|
|Foreign.Definition(
|
||||||
|
@ -119,7 +119,7 @@ object Operator {
|
|||||||
copy(left = left.mapExpressions(fn), right = right.mapExpressions(fn))
|
copy(left = left.mapExpressions(fn), right = right.mapExpressions(fn))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Operator.Binary(
|
|Operator.Binary(
|
||||||
|
@ -111,7 +111,7 @@ object Section {
|
|||||||
operator = operator.mapExpressions(fn)
|
operator = operator.mapExpressions(fn)
|
||||||
)
|
)
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Section.Left(
|
|Section.Left(
|
||||||
@ -203,7 +203,7 @@ object Section {
|
|||||||
): Section =
|
): Section =
|
||||||
copy(operator = operator.mapExpressions(fn))
|
copy(operator = operator.mapExpressions(fn))
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Section.Sides(
|
|Section.Sides(
|
||||||
@ -308,7 +308,7 @@ object Section {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Section.Right(
|
|Section.Right(
|
||||||
|
@ -78,7 +78,7 @@ sealed case class ImportExport(
|
|||||||
): ImportExport =
|
): ImportExport =
|
||||||
this
|
this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Error.ImportExport(
|
|Error.ImportExport(
|
||||||
|
@ -209,7 +209,7 @@ object Redefined {
|
|||||||
): Conversion =
|
): Conversion =
|
||||||
this
|
this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Error.Redefined.Method(
|
|Error.Redefined.Method(
|
||||||
@ -332,7 +332,7 @@ object Redefined {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Method = this
|
): Method = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Error.Redefined.Method(
|
|Error.Redefined.Method(
|
||||||
@ -458,7 +458,7 @@ object Redefined {
|
|||||||
): MethodClashWithAtom =
|
): MethodClashWithAtom =
|
||||||
this
|
this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Error.Redefined.MethodClashWithAtom(
|
|Error.Redefined.MethodClashWithAtom(
|
||||||
@ -560,7 +560,7 @@ object Redefined {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Type = this
|
): Type = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Error.Redefined.Atom(
|
|Error.Redefined.Atom(
|
||||||
@ -661,7 +661,7 @@ object Redefined {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Arg = this
|
): Arg = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Error.Redefined.Arg(
|
|Error.Redefined.Arg(
|
||||||
@ -755,7 +755,7 @@ object Redefined {
|
|||||||
): Binding =
|
): Binding =
|
||||||
this
|
this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Error.Redefined.Binding(
|
|Error.Redefined.Binding(
|
||||||
|
@ -76,7 +76,7 @@ sealed case class Syntax(
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Syntax = this
|
): Syntax = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Error.Syntax(
|
|Error.Syntax(
|
||||||
|
@ -124,7 +124,7 @@ object Definition {
|
|||||||
members = members.map(_.mapExpressions(fn))
|
members = members.map(_.mapExpressions(fn))
|
||||||
)
|
)
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Module.Scope.Definition.Type(
|
|Module.Scope.Definition.Type(
|
||||||
@ -249,7 +249,7 @@ object Definition {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Module.Scope.Definition.Data(
|
|Module.Scope.Definition.Data(
|
||||||
@ -376,7 +376,7 @@ object Definition {
|
|||||||
location: Option[IdentifiedLocation]
|
location: Option[IdentifiedLocation]
|
||||||
): SugaredType = copy(location = location)
|
): SugaredType = copy(location = location)
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Module.Scope.Definition.SugaredType(
|
|Module.Scope.Definition.SugaredType(
|
||||||
|
@ -132,7 +132,7 @@ object Export {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Module = this
|
): Module = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Module.Scope.Export.Module(
|
|Module.Scope.Export.Module(
|
||||||
|
@ -147,7 +147,7 @@ object Import {
|
|||||||
fn: java.util.function.Function[Expression, Expression]
|
fn: java.util.function.Function[Expression, Expression]
|
||||||
): Module = this
|
): Module = this
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Module.Scope.Import.Module(
|
|Module.Scope.Import.Module(
|
||||||
|
@ -163,7 +163,7 @@ object Method {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Module.Scope.Definition.Method.Explicit(
|
|Module.Scope.Definition.Method.Explicit(
|
||||||
@ -342,7 +342,7 @@ object Method {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Module.Scope.Definition.Method.Binding(
|
|Module.Scope.Definition.Method.Binding(
|
||||||
@ -485,7 +485,7 @@ object Method {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Module.Scope.Definition.Method.Conversion(
|
|Module.Scope.Definition.Method.Conversion(
|
||||||
|
@ -91,7 +91,7 @@ sealed case class Polyglot(
|
|||||||
*/
|
*/
|
||||||
def getVisibleName: String = rename.getOrElse(entity.getVisibleName)
|
def getVisibleName: String = rename.getOrElse(entity.getVisibleName)
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|Module.Scope.Import.Polyglot(
|
|Module.Scope.Import.Polyglot(
|
||||||
|
@ -126,7 +126,7 @@ object Set {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|`type`.Set.Member(
|
|`type`.Set.Member(
|
||||||
@ -236,7 +236,7 @@ object Set {
|
|||||||
copy(left = fn(left), right = fn(right))
|
copy(left = fn(left), right = fn(right))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|`type`.Set.Subsumption(
|
|`type`.Set.Subsumption(
|
||||||
@ -341,7 +341,7 @@ object Set {
|
|||||||
copy(left = fn(left), right = fn(right))
|
copy(left = fn(left), right = fn(right))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|`type`.Set.Equality(
|
|`type`.Set.Equality(
|
||||||
@ -445,7 +445,7 @@ object Set {
|
|||||||
copy(left = fn(left), right = fn(right))
|
copy(left = fn(left), right = fn(right))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|`type`.Set.Concat(
|
|`type`.Set.Concat(
|
||||||
@ -542,7 +542,7 @@ object Set {
|
|||||||
copy(operands = operands.map(fn.asScala))
|
copy(operands = operands.map(fn.asScala))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|`type`.Set.Union(
|
|`type`.Set.Union(
|
||||||
@ -646,7 +646,7 @@ object Set {
|
|||||||
copy(left = fn(left), right = fn(right))
|
copy(left = fn(left), right = fn(right))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** String representation. */
|
||||||
override def toString: String =
|
override def toString: String =
|
||||||
s"""
|
s"""
|
||||||
|`type`.Set.Intersection(
|
|`type`.Set.Intersection(
|
||||||
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.processing.AbstractProcessor;
|
import javax.annotation.processing.AbstractProcessor;
|
||||||
import javax.annotation.processing.Processor;
|
import javax.annotation.processing.Processor;
|
||||||
import javax.annotation.processing.RoundEnvironment;
|
import javax.annotation.processing.RoundEnvironment;
|
||||||
@ -69,7 +70,7 @@ public class PersistableProcessor extends AbstractProcessor {
|
|||||||
private static String findNameInPackage(Element e) {
|
private static String findNameInPackage(Element e) {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
while (e != null && !(e instanceof PackageElement)) {
|
while (e != null && !(e instanceof PackageElement)) {
|
||||||
if (!sb.isEmpty()) {
|
if (sb.length() > 0) {
|
||||||
sb.insert(0, ".");
|
sb.insert(0, ".");
|
||||||
}
|
}
|
||||||
sb.insert(0, e.getSimpleName());
|
sb.insert(0, e.getSimpleName());
|
||||||
@ -112,7 +113,7 @@ public class PersistableProcessor extends AbstractProcessor {
|
|||||||
e.getModifiers().contains(Modifier.PUBLIC)
|
e.getModifiers().contains(Modifier.PUBLIC)
|
||||||
&& e.getKind() == ElementKind.CONSTRUCTOR)
|
&& e.getKind() == ElementKind.CONSTRUCTOR)
|
||||||
.sorted(richerConstructor)
|
.sorted(richerConstructor)
|
||||||
.toList();
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
ExecutableElement cons;
|
ExecutableElement cons;
|
||||||
Element singleton;
|
Element singleton;
|
||||||
@ -125,7 +126,7 @@ public class PersistableProcessor extends AbstractProcessor {
|
|||||||
&& e.getModifiers().contains(Modifier.STATIC)
|
&& e.getModifiers().contains(Modifier.STATIC)
|
||||||
&& e.getModifiers().contains(Modifier.PUBLIC))
|
&& e.getModifiers().contains(Modifier.PUBLIC))
|
||||||
.filter(e -> tu.isSameType(e.asType(), typeElem.asType()))
|
.filter(e -> tu.isSameType(e.asType(), typeElem.asType()))
|
||||||
.toList();
|
.collect(Collectors.toList());
|
||||||
if (singletonFields.isEmpty()) {
|
if (singletonFields.isEmpty()) {
|
||||||
processingEnv
|
processingEnv
|
||||||
.getMessager()
|
.getMessager()
|
||||||
|
@ -7,8 +7,8 @@ import java.lang.annotation.Target;
|
|||||||
/**
|
/**
|
||||||
* Annotation for an automatic persistance of a class. Use to generate implementation and
|
* Annotation for an automatic persistance of a class. Use to generate implementation and
|
||||||
* registration of {@link Persistance} subclass to read and write simple records and case classes:
|
* registration of {@link Persistance} subclass to read and write simple records and case classes:
|
||||||
*
|
* <br>
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="annotation"}
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="annotation"}
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Repeatable(Persistable.Group.class)
|
@Repeatable(Persistable.Group.class)
|
||||||
@ -17,13 +17,10 @@ public @interface Persistable {
|
|||||||
/**
|
/**
|
||||||
* The class to generate {@link Persistance} for. If the value is omitted then the code is
|
* The class to generate {@link Persistance} for. If the value is omitted then the code is
|
||||||
* generated for the class that is annotated by this annotation. Example of multiple
|
* generated for the class that is annotated by this annotation. Example of multiple
|
||||||
* {@code @Persistable} annotations on a single element.
|
* {@code @Persistable} annotations on a single element. <br>
|
||||||
*
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="annotation"} <br>
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="annotation"}
|
* Example of self annotated class: <br>
|
||||||
*
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="self-annotation"}
|
||||||
* <p>Example of self annotated class:
|
|
||||||
*
|
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="self-annotation"}
|
|
||||||
*
|
*
|
||||||
* @return the class to generate read/write persistance code for
|
* @return the class to generate read/write persistance code for
|
||||||
*/
|
*/
|
||||||
@ -43,7 +40,7 @@ public @interface Persistable {
|
|||||||
* {@code final} or <em>sealed</em> classes are inlined. Inlining is however not very helpful when
|
* {@code final} or <em>sealed</em> classes are inlined. Inlining is however not very helpful when
|
||||||
* a single object is shared between multiple other objects.
|
* a single object is shared between multiple other objects.
|
||||||
*
|
*
|
||||||
* @return
|
* @return allow or disallow inlining
|
||||||
*/
|
*/
|
||||||
boolean allowInlining() default true;
|
boolean allowInlining() default true;
|
||||||
|
|
||||||
|
@ -10,28 +10,24 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Central persistance class. Use static {@link Persistance#write write} method to turn a graph of
|
* Central persistance class. Use static {@link Persistance#write write} method to turn a graph of
|
||||||
* JVM objects into a {@code byte[]}.
|
* JVM objects into a {@code byte[]}. <br>
|
||||||
*
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="write"}
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="write"}
|
|
||||||
*
|
*
|
||||||
* <p>Use sibling static {@link Persistance#read readO} method to read the byte buffer back into
|
* <p>Use sibling static {@link Persistance#read readO} method to read the byte buffer back into
|
||||||
* their memory representation.
|
* their memory representation. <br>
|
||||||
*
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="read"}
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="read"}
|
|
||||||
*
|
*
|
||||||
* <h2>Manual Persistance</h2>
|
* <h2>Manual Persistance</h2>
|
||||||
*
|
*
|
||||||
* Unlike typical Java serialization (which tries to make things automatic), this framework requires
|
* Unlike typical Java serialization (which tries to make things automatic), this framework requires
|
||||||
* one to implement the persistance manually. For each class that one wants to support, one has to
|
* one to implement the persistance manually. For each class that one wants to support, one has to
|
||||||
* implement subclass {@link Persistance} and implement its {@link Persistance#writeObject} and
|
* implement subclass {@link Persistance} and implement its {@link Persistance#writeObject} and
|
||||||
* {@link Persistance#readObject} method.
|
* {@link Persistance#readObject} method. <br>
|
||||||
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="manual"} <br>
|
||||||
|
* There is a semi-automatic way to generate such subclasses of {@link Persistance} via the {@link
|
||||||
|
* Persistable @Persistable} annotation.
|
||||||
*
|
*
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="manual"}
|
* @param <T> type this persistance subclass operates on
|
||||||
*
|
|
||||||
* <p>There is a semi-automatic way to generate such subclasses of {@link Persistance} via the
|
|
||||||
* {@link Persistable @Persistable} annotation.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
*/
|
*/
|
||||||
public abstract class Persistance<T> implements Cloneable {
|
public abstract class Persistance<T> implements Cloneable {
|
||||||
final Class<T> clazz;
|
final Class<T> clazz;
|
||||||
@ -40,14 +36,11 @@ public abstract class Persistance<T> implements Cloneable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for subclasses to register persistance for certain {@code clazz}. Sample
|
* Constructor for subclasses to register persistance for certain {@code clazz}. Sample
|
||||||
* registration:
|
* registration: <br>
|
||||||
*
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="manual"} <br>
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="manual"}
|
* Each persistance requires unique ID. A stream created by {@link #write(Object, Function<Object,
|
||||||
*
|
* Object>)} and read by {@link #read(byte[], Function<Object, Object>)} contains a header derived
|
||||||
* <p>Each persistance requires unique ID. A stream created by {@link #write(Object,
|
* from the all the IDs present in the system. When versioning the protocol and implementation:
|
||||||
* Function<Object, Object>)} and read by {@link #read(byte[], Function<Object, Object>)} contains
|
|
||||||
* a header derived from the all the IDs present in the system. When versioning the protocol and
|
|
||||||
* implementation:
|
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>when you change something really core in the Persitance itself - change the header
|
* <li>when you change something really core in the Persitance itself - change the header
|
||||||
@ -74,8 +67,23 @@ public abstract class Persistance<T> implements Cloneable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle serialization of provided object.
|
||||||
|
*
|
||||||
|
* @param obj the object to serialize
|
||||||
|
* @param out the stream to persist the objec to
|
||||||
|
* @throws IOException thrown on I/O errors
|
||||||
|
*/
|
||||||
protected abstract void writeObject(T obj, Output out) throws IOException;
|
protected abstract void writeObject(T obj, Output out) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle deserialization on an object.
|
||||||
|
*
|
||||||
|
* @param in stream to read an instance of the object from
|
||||||
|
* @return instance of the deserialized object
|
||||||
|
* @throws IOException thrown on I/O errors
|
||||||
|
* @throws ClassNotFoundException thrown when class loading fails
|
||||||
|
*/
|
||||||
protected abstract T readObject(Input in) throws IOException, ClassNotFoundException;
|
protected abstract T readObject(Input in) throws IOException, ClassNotFoundException;
|
||||||
|
|
||||||
/** Prints the {@code clazz} and {@code id} values. */
|
/** Prints the {@code clazz} and {@code id} values. */
|
||||||
@ -158,9 +166,9 @@ public abstract class Persistance<T> implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read object written down by {@link #write} from an array.
|
* Read object written down by {@link #write} from an array. <br>
|
||||||
*
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="read"} <br>
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="read"}
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="read"}
|
||||||
*
|
*
|
||||||
* @param arr the stored bytes
|
* @param arr the stored bytes
|
||||||
* @param readResolve either {@code null} or function to call for each object being stored to
|
* @param readResolve either {@code null} or function to call for each object being stored to
|
||||||
@ -209,6 +217,7 @@ public abstract class Persistance<T> implements Cloneable {
|
|||||||
* deferred towards the end, allowing to handle circular references inside of the serialized
|
* deferred towards the end, allowing to handle circular references inside of the serialized
|
||||||
* structure.
|
* structure.
|
||||||
*
|
*
|
||||||
|
* @param <T> expected type of the referenced object
|
||||||
* @see Input#readReference
|
* @see Input#readReference
|
||||||
*/
|
*/
|
||||||
public abstract static sealed class Reference<T> permits PerBufferReference, PerMemoryReference {
|
public abstract static sealed class Reference<T> permits PerBufferReference, PerMemoryReference {
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
* Framework for persisting Java objects and reading them <em>"lazily"</em>. Use static {@link
|
* Framework for persisting Java objects and reading them <em>"lazily"</em>. Use static {@link
|
||||||
* Persistance#write write} method to turn a graph of JVM objects into a {@code byte[]}.
|
* Persistance#write write} method to turn a graph of JVM objects into a {@code byte[]}. <br>
|
||||||
*
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="write"}
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="write"}
|
|
||||||
*
|
*
|
||||||
* <p>Use sibling static {@link Persistance#read read} method to read the byte buffer back into
|
* <p>Use sibling static {@link Persistance#read read} method to read the byte buffer back into
|
||||||
* their memory representation.
|
* their memory representation. <br>
|
||||||
*
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="read"}
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="read"}
|
|
||||||
*
|
*
|
||||||
* <h2>Laziness</h2>
|
* <h2>Laziness</h2>
|
||||||
*
|
*
|
||||||
@ -20,9 +18,8 @@
|
|||||||
* Unlike typical Java serialization (which tries to make things automatic), this framework requires
|
* Unlike typical Java serialization (which tries to make things automatic), this framework requires
|
||||||
* one to implement the persistance manually. For each class one wants to serde, one has to
|
* one to implement the persistance manually. For each class one wants to serde, one has to
|
||||||
* implement a subclass of {@link Persistance} and implement its {@link Persistance#writeObject} and
|
* implement a subclass of {@link Persistance} and implement its {@link Persistance#writeObject} and
|
||||||
* {@link Persistance#readObject} methods.
|
* {@link Persistance#readObject} methods. <br>
|
||||||
*
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="manual"}
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="manual"}
|
|
||||||
*
|
*
|
||||||
* <h2>Semi-automatic Persistance</h2>
|
* <h2>Semi-automatic Persistance</h2>
|
||||||
*
|
*
|
||||||
@ -30,8 +27,7 @@
|
|||||||
* errorprone process. That's why there is a {@link Persistable @Persistable} annotation and
|
* errorprone process. That's why there is a {@link Persistable @Persistable} annotation and
|
||||||
* associated annotation processor that generates the necessary {@link Persistance} subclass based
|
* associated annotation processor that generates the necessary {@link Persistance} subclass based
|
||||||
* on the "richest" constructor in the class to be persisted. This approach seems to work well for
|
* on the "richest" constructor in the class to be persisted. This approach seems to work well for
|
||||||
* Java records and Scala case classes.
|
* Java records and Scala case classes. <br>
|
||||||
*
|
* {@snippet file="org/enso/persist/PersistanceTest.java" region="annotation"}
|
||||||
* <p>{@snippet file="org/enso/persist/PersistanceTest.java" region="annotation"}
|
|
||||||
*/
|
*/
|
||||||
package org.enso.persist;
|
package org.enso.persist;
|
||||||
|
@ -8,6 +8,12 @@ import java.nio.charset.StandardCharsets;
|
|||||||
|
|
||||||
public final class Parser implements AutoCloseable {
|
public final class Parser implements AutoCloseable {
|
||||||
private static void initializeLibraries() {
|
private static void initializeLibraries() {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("enso_parser");
|
||||||
|
return;
|
||||||
|
} catch (LinkageError err) {
|
||||||
|
// try harder to find the library
|
||||||
|
}
|
||||||
String os = System.getProperty("os.name");
|
String os = System.getProperty("os.name");
|
||||||
String name;
|
String name;
|
||||||
if (os.startsWith("Mac")) {
|
if (os.startsWith("Mac")) {
|
||||||
@ -34,7 +40,7 @@ public final class Parser implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
parser = path;
|
parser = path;
|
||||||
System.load(parser.getAbsolutePath());
|
System.load(parser.getAbsolutePath());
|
||||||
} catch (URISyntaxException | LinkageError e) {
|
} catch (IllegalArgumentException | URISyntaxException | LinkageError e) {
|
||||||
File root = new File(".").getAbsoluteFile();
|
File root = new File(".").getAbsoluteFile();
|
||||||
if (!searchFromDirToTop(e, root, "target", "rust", "debug", name)) {
|
if (!searchFromDirToTop(e, root, "target", "rust", "debug", name)) {
|
||||||
throw new IllegalStateException("Cannot load parser from " + parser, e);
|
throw new IllegalStateException("Cannot load parser from " + parser, e);
|
||||||
|
@ -22,6 +22,13 @@ following two extensions in the system:
|
|||||||
|
|
||||||
![Installed VSCode extensions](https://user-images.githubusercontent.com/26887752/274904239-ae1ad4cc-e2ec-4c5b-bca0-c7d7189c6885.png)
|
![Installed VSCode extensions](https://user-images.githubusercontent.com/26887752/274904239-ae1ad4cc-e2ec-4c5b-bca0-c7d7189c6885.png)
|
||||||
|
|
||||||
|
## Outline View
|
||||||
|
|
||||||
|
Since version 1.40 the extension fills content of _Outline View_ on supported
|
||||||
|
platforms (Linux amd64, Mac, Windows):
|
||||||
|
|
||||||
|
<img width="862" alt="image" src="https://github.com/enso-org/enso/assets/26887752/7374bf41-bdc6-4322-b562-85a2e761de2a">
|
||||||
|
|
||||||
## Debugging a Single Enso File
|
## Debugging a Single Enso File
|
||||||
|
|
||||||
Open any `.enso` files. Click left editor gutter to place breakpoints. Then
|
Open any `.enso` files. Click left editor gutter to place breakpoints. Then
|
||||||
|
14
tools/enso4igv/package-lock.json
generated
14
tools/enso4igv/package-lock.json
generated
@ -607,11 +607,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/braces": {
|
"node_modules/braces": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||||
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
|
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fill-range": "^7.0.1"
|
"fill-range": "^7.1.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
@ -1338,9 +1338,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fill-range": {
|
"node_modules/fill-range": {
|
||||||
"version": "7.0.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||||
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
|
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"to-regex-range": "^5.0.1"
|
"to-regex-range": "^5.0.1"
|
||||||
},
|
},
|
||||||
|
@ -57,6 +57,12 @@
|
|||||||
"configuration": "./src/main/resources/org/enso/tools/enso4igv/enso.tmLanguage.json"
|
"configuration": "./src/main/resources/org/enso/tools/enso4igv/enso.tmLanguage.json"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"netbeans.documentSelectors": [
|
||||||
|
{
|
||||||
|
"language": "enso",
|
||||||
|
"pattern": "**/*.enso"
|
||||||
|
}
|
||||||
|
],
|
||||||
"grammars": [
|
"grammars": [
|
||||||
{
|
{
|
||||||
"language": "enso",
|
"language": "enso",
|
||||||
|
@ -5,19 +5,30 @@
|
|||||||
<artifactId>enso4igv</artifactId>
|
<artifactId>enso4igv</artifactId>
|
||||||
<packaging>nbm</packaging>
|
<packaging>nbm</packaging>
|
||||||
<name>Enso Language Support for NetBeans & Ideal Graph Visualizer</name>
|
<name>Enso Language Support for NetBeans & Ideal Graph Visualizer</name>
|
||||||
<version>1.36-SNAPSHOT</version>
|
<version>1.40-SNAPSHOT</version>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.netbeans.utilities</groupId>
|
<groupId>org.apache.netbeans.utilities</groupId>
|
||||||
<artifactId>nbm-maven-plugin</artifactId>
|
<artifactId>nbm-maven-plugin</artifactId>
|
||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<version>4.7</version>
|
<version>14.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<useOSGiDependencies>true</useOSGiDependencies>
|
<useOSGiDependencies>false</useOSGiDependencies>
|
||||||
<author>Enso.org</author>
|
<author>Enso.org</author>
|
||||||
<licenseName>Apache 2.0</licenseName>
|
<licenseName>Apache 2.0</licenseName>
|
||||||
<licenseFile>../../LICENSE</licenseFile>
|
<licenseFile>../../LICENSE</licenseFile>
|
||||||
|
<nbmResources>
|
||||||
|
<nbmResource>
|
||||||
|
<directory>${enso.parser.lib}</directory>
|
||||||
|
<targetPath>modules/lib/</targetPath>
|
||||||
|
<includes>
|
||||||
|
<include>**/*.dll</include>
|
||||||
|
<include>**/*.so</include>
|
||||||
|
<include>**/*.dylib</include>
|
||||||
|
</includes>
|
||||||
|
</nbmResource>
|
||||||
|
</nbmResources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -217,6 +228,21 @@
|
|||||||
<version>${netbeans.version}</version>
|
<version>${netbeans.version}</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.netbeans.api</groupId>
|
||||||
|
<artifactId>org-netbeans-api-lsp</artifactId>
|
||||||
|
<version>RELEASE160</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<!--
|
||||||
|
$ sbt publishM2
|
||||||
|
-->
|
||||||
|
<groupId>org.enso</groupId>
|
||||||
|
<artifactId>runtime-parser</artifactId>
|
||||||
|
<version>0.2-SNAPSHOT</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.netbeans.api</groupId>
|
<groupId>org.netbeans.api</groupId>
|
||||||
<artifactId>org-netbeans-modules-nbjunit</artifactId>
|
<artifactId>org-netbeans-modules-nbjunit</artifactId>
|
||||||
@ -261,6 +287,8 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<netbeans.version>RELEASE140</netbeans.version>
|
<netbeans.version>RELEASE140</netbeans.version>
|
||||||
<netbeans.compile.on.save>none</netbeans.compile.on.save>
|
<netbeans.compile.on.save>none</netbeans.compile.on.save>
|
||||||
|
<enso.root>${basedir}/../../</enso.root>
|
||||||
|
<enso.parser.lib>${enso.root}/lib/rust/parser/target/classes/</enso.parser.lib>
|
||||||
</properties>
|
</properties>
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.enso.tools.enso4igv.enso;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import javax.swing.text.Document;
|
||||||
|
import org.netbeans.api.editor.mimelookup.MimeRegistration;
|
||||||
|
import org.netbeans.api.lsp.Completion;
|
||||||
|
import org.netbeans.spi.lsp.CompletionCollector;
|
||||||
|
|
||||||
|
@MimeRegistration(mimeType = "application/x-enso", service = CompletionCollector.class)
|
||||||
|
public class EnsoCompletionCollector implements CompletionCollector {
|
||||||
|
@Override
|
||||||
|
public boolean collectCompletions(Document dcmnt, int i, Completion.Context cntxt, Consumer<Completion> cnsmr) {
|
||||||
|
for (var e : EnsoStructure.collectStructure(dcmnt)) {
|
||||||
|
cnsmr.accept(CompletionCollector.newBuilder(e.getName()).build());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
package org.enso.tools.enso4igv.enso;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.swing.text.BadLocationException;
|
||||||
|
import javax.swing.text.Document;
|
||||||
|
import org.enso.compiler.core.EnsoParser;
|
||||||
|
import org.enso.compiler.core.IR;
|
||||||
|
import org.enso.compiler.core.ir.module.scope.Definition;
|
||||||
|
import org.enso.compiler.core.ir.module.scope.definition.Method;
|
||||||
|
import org.netbeans.api.editor.mimelookup.MimeRegistration;
|
||||||
|
import org.netbeans.api.lsp.StructureElement;
|
||||||
|
import org.netbeans.spi.lsp.StructureProvider;
|
||||||
|
import org.openide.filesystems.FileObject;
|
||||||
|
import org.openide.util.Lookup;
|
||||||
|
import scala.collection.Iterator;
|
||||||
|
|
||||||
|
@MimeRegistration(mimeType = "application/x-enso", service = StructureProvider.class)
|
||||||
|
public final class EnsoStructure implements StructureProvider {
|
||||||
|
@Override
|
||||||
|
public List<StructureElement> getStructure(Document dcmnt) {
|
||||||
|
return collectStructure(dcmnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<StructureElement> collectStructure(Document dcmnt) {
|
||||||
|
FileObject file = null;
|
||||||
|
if (dcmnt.getProperty(Document.StreamDescriptionProperty) instanceof Lookup.Provider p) {
|
||||||
|
if (p.getLookup().lookup(FileObject.class) instanceof FileObject fo) {
|
||||||
|
file = fo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var arr = new ArrayList<StructureElement>();
|
||||||
|
try {
|
||||||
|
var parser = new EnsoParser();
|
||||||
|
var text = dcmnt.getText(0, dcmnt.getLength());
|
||||||
|
var moduleIr = parser.compile(text);
|
||||||
|
var it = moduleIr.bindings().iterator();
|
||||||
|
collectStructure(file, arr, it);
|
||||||
|
return arr;
|
||||||
|
} catch (LinkageError err) {
|
||||||
|
err.printStackTrace();
|
||||||
|
throw new IllegalStateException(err);
|
||||||
|
} catch (BadLocationException ex) {
|
||||||
|
throw new IllegalStateException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void collectStructure(FileObject file, List<StructureElement> arr, Iterator<? extends IR> it) {
|
||||||
|
while (it.hasNext()) {
|
||||||
|
var b = it.next();
|
||||||
|
collectStructureItem(file, arr, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void collectStructureItem(FileObject file, List<StructureElement> arr, IR ir) {
|
||||||
|
var b = switch (ir) {
|
||||||
|
case Definition.SugaredType type -> {
|
||||||
|
var bldr = StructureProvider.newBuilder(type.name().name(), StructureElement.Kind.Class);
|
||||||
|
var children = new ArrayList<StructureElement>();
|
||||||
|
collectStructure(file, children, type.body().iterator());
|
||||||
|
bldr.children(children);
|
||||||
|
yield bldr;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Definition.Data data -> {
|
||||||
|
var bldr = StructureProvider.newBuilder(data.name().name(), StructureElement.Kind.Constructor);
|
||||||
|
yield bldr;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Method.Binding bind -> {
|
||||||
|
var bldr = StructureProvider.newBuilder(bind.methodName().name(), StructureElement.Kind.Method);
|
||||||
|
yield bldr;
|
||||||
|
}
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (b != null) {
|
||||||
|
if (ir.location() != null && ir.location().isDefined()) {
|
||||||
|
var loc = ir.location().get().location();
|
||||||
|
b.selectionStartOffset(loc.start());
|
||||||
|
b.selectionEndOffset(loc.end());
|
||||||
|
b.expandedStartOffset(loc.start());
|
||||||
|
b.expandedEndOffset(loc.end());
|
||||||
|
}
|
||||||
|
b.file(file);
|
||||||
|
var e = b.build();
|
||||||
|
arr.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package org.enso.tools.enso4igv.enso;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import javax.swing.text.PlainDocument;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.netbeans.api.lsp.StructureElement;
|
||||||
|
|
||||||
|
public class EnsoStructureTest {
|
||||||
|
|
||||||
|
public EnsoStructureTest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void processASimpleDocument() throws Exception {
|
||||||
|
var doc = new PlainDocument();
|
||||||
|
doc.insertString(0, """
|
||||||
|
type B
|
||||||
|
T
|
||||||
|
F
|
||||||
|
""", null);
|
||||||
|
|
||||||
|
var s = new EnsoStructure();
|
||||||
|
var root = s.getStructure(doc);
|
||||||
|
assertEquals("One root element: " + root, 1, root.size());
|
||||||
|
assertEquals("Type is class", StructureElement.Kind.Class, root.get(0).getKind());
|
||||||
|
final List<StructureElement> chldrn = root.get(0).getChildren();
|
||||||
|
assertEquals("Has two children", 2, chldrn.size());
|
||||||
|
assertEquals("Constructor is it at 0", StructureElement.Kind.Constructor, chldrn.get(0).getKind());
|
||||||
|
assertEquals("Constructor is it at 1", StructureElement.Kind.Constructor, chldrn.get(1).getKind());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void collectMethods() throws Exception {
|
||||||
|
var doc = new PlainDocument();
|
||||||
|
doc.insertString(0, """
|
||||||
|
main = 6 * 7
|
||||||
|
""", null);
|
||||||
|
|
||||||
|
var s = new EnsoStructure();
|
||||||
|
var root = s.getStructure(doc);
|
||||||
|
assertEquals("One root element: " + root, 1, root.size());
|
||||||
|
assertEquals("It is a method", StructureElement.Kind.Method, root.get(0).getKind());
|
||||||
|
assertEquals("It is a method", "main", root.get(0).getName());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user