Skip to content

Commit

Permalink
Merge pull request #282 from alephium/local_contractsPath
Browse files Browse the repository at this point in the history
Set default `contractPath` to the local workspace directory
  • Loading branch information
simerplaha authored Sep 3, 2024
2 parents 2d7933f + e63f434 commit 55b773a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,24 @@ Run the plugin by selecting the menu option `Run -> Run Without Debugging` or `R

# Configuration

After your IDE has booted up, a config file named `ralph.json` will be generated in your project's root
directory under the folder `.ralph-lsp/ralph.json`. The file contains the following default value for
`contractPath`, which configures a source directory named `contracts` for compilation:
Configurations in `alephium.config.ts` are the primary source for build settings, and `ralph.json` is secondary.
Any settings defined in `alephium.config.ts` will be mirrored in `ralph.json`.

```json
{
"contractPath": "contracts"
}
```
## `alephium.config.ts`

The `compilerOptions` and `dependencyPath` fields are optional. If `dependencyPath` is not specified,
the default path (`<user.home>/.ralph-lsp/dependencies/`) will be used.
Refer to the [documentation](https://docs.alephium.org/sdk/cli/#configuration) for more details about the `alephium.config.ts`.

Here’s an example of how the `ralph.json` file might look with additional configuration:
## `ralph.json`

Once your IDE has booted up, a config file named `ralph.json` will be generated in your project's root
directory under the folder `.ralph-lsp/ralph.json`.
This file reflects the `sourceDir` and `compilerOptions` settings defined in `alephium.config.ts`.
If `alephium.config.ts` is not present or if the settings are missing, default settings will be used.

The `dependencyPath` setting is specific to Ralph-LSP and configures the directory for dependencies.
If `dependencyPath` is not specified, the default path (`<user.home>/.ralph-lsp/dependencies/`) will be used.

Here’s an example of the `ralph.json` file with all configurations set:

```json
{
Expand All @@ -139,9 +143,6 @@ Here’s an example of how the `ralph.json` file might look with additional conf
}
```

This configuration allows you to customise the behavior of the compiler and define the paths for
your contracts, artifacts, and dependencies.

## Configure trace (VSCode)

![image](https://github.com/alephium/ralph-lsp/assets/1773953/ac537faf-492f-468a-ab88-a39323e6e821)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object RalphcConfigState {
/** Default parsed config */
val default: RalphcConfigState.Parsed =
RalphcConfigState.Parsed(
contractPath = "contracts",
contractPath = "",
artifactPath = None,
dependencyPath = None,
compilerOptions = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.alephium.ralph.lsp.pc.workspace.build.config

import org.alephium.ralph.CompilerOptions
import org.alephium.ralph.lsp.TestFile
import org.alephium.ralph.lsp.access.compiler.CompilerAccess
import org.alephium.ralph.lsp.access.file.FileAccess
import org.alephium.ralph.lsp.pc.client.TestClientLogger
Expand Down Expand Up @@ -122,7 +123,7 @@ class RalphcConfigSpec extends AnyWordSpec with Matchers {
|}
|""".stripMargin

val expected = RalphcConfigState.Parsed.default.copy(artifactPath = Some("artifacts"))
val expected = RalphcConfigState.Parsed.default.copy(contractPath = "contracts", artifactPath = Some("artifacts"))
val actual = RalphcConfig.parse(URI.create(""), build_ralph).value

actual shouldBe expected
Expand All @@ -131,7 +132,7 @@ class RalphcConfigSpec extends AnyWordSpec with Matchers {
"is not provided" in {
val build_ralph =
"""{
| "contractPath": "contracts"
| "contractPath": ""
|}
|""".stripMargin

Expand Down Expand Up @@ -174,13 +175,14 @@ class RalphcConfigSpec extends AnyWordSpec with Matchers {
.Parsed
.default
.copy(
contractPath = "contracts",
artifactPath = artifactPath,
dependencyPath = dependencyPath
)

val workspacePath = Files.createTempDirectory("root_workspace")

Files.createDirectory(workspacePath.resolve(config.contractPath))
TestFile.createDirectories(workspacePath.resolve(config.contractPath))

config
.artifactPath
Expand All @@ -205,7 +207,7 @@ class RalphcConfigSpec extends AnyWordSpec with Matchers {
actualBuildPath shouldBe expectedBuildPath

// Parse and compile the config file on disk
val readConfig =
val actualBuild =
Build.parseAndCompile(
buildURI = expectedBuildPath.toUri,
currentBuild = None,
Expand Down Expand Up @@ -255,14 +257,16 @@ class RalphcConfigSpec extends AnyWordSpec with Matchers {
Dependency.defaultPath().value
}

readConfig shouldBe
val expectedBuild =
BuildState.Compiled(
dependencies = compiledStd.dependencies,
dependencyPath = expectedDependenciesPath,
config = expectedCompiledConfig,
parsed = parsedBuild
)

actualBuild shouldBe expectedBuild

TestWorkspace delete WorkspaceState.Created(workspacePath.toUri)
}

Expand Down

0 comments on commit 55b773a

Please sign in to comment.