alephium / ralph-lsp

Ralph language server
7 stars 1 forks source link

Investigate default `ralph.json` in ralph home folder #214

Closed tdroxler closed 1 month ago

tdroxler commented 4 months ago

If no ralph.json is found in project, we could fallback to a default one inside the RALPH_LSP_HOME.

This would help the new users, but it might introduce other problems as discussed here

tdroxler commented 3 months ago

some default values are defined in web3 :

we have the web3 files available, but not sure we could extract those information from those TS file. I'll dig a bit

tdroxler commented 3 months ago

Configuration Management in ralph-lsp

Current State

The ralph-lsp project stores configuration details in ralph.json, including:

View source

Only dependencyPath is specific to ralph-lsp. The other three options are also used by the web3 project for compiling/deploying through the node, stored in alephium.config.ts within the Configuration interface.

When ralph-lsp starts in a project without ralph.json, an error prompts the user to create that file.

Since all Ralph developers already have alephium.config.ts, requiring them to maintain compiler options in two files is not viable.

Requirements

To streamline this process, we propose the following:

  1. Extract Compiler Configurations from TS File: Avoid duplication by extracting configurations from the TypeScript file.
  2. Move LSP-related Configurations: Shift ralph-lsp specific configurations to .ralph-lsp folder with default values to simplify its usage, avoid errors for new developers and increase adoption.

Extraction from TS can be achieved with fastparse, instead of deserializing a JSON file into Scala with upickle.

@simerplaha requesting your feedback on this, thx

simerplaha commented 3 months ago

Hey @tdroxler,

Just to re-confirm: This suggests that we extract compilerOptions, contractPath and artifactPath from alephium.config.ts right? Because the above fastparse code extracts compilerOptions from a contract.ts file in web3.

Question 1 for Requirement 1 - Extract Compiler Configurations from TS File

Since the configuration we want to parse using fastparse is regular TypeScript code, we are kinda restricting devs to use constants for these settings. For example, if they want to configure it via environment variables or some complex function calls, they won't be able to, as the parser expects constants.

tdroxler commented 3 months ago

From the contracts.ts we extract the default compiler options, then from alephium.config.ts we need to extract optional compiler options that can override the default ones, each compiler option is optional.

So my current idea was to extract once the default values and then we watch alephium.confif.ts and check if some compilerOptions are defined and/or changed.

Now you raised a very good point, we indeed won't be able to manage any kind of values that aren't just plain constants...

Default values could still be extracted from web3, even at compile time and stored into /resources. So at least user can start using ralph-lsp without having to configure something.

But for the "live" config, I don't have yet a solution. I see two directions:

  1. Web3 defines everything compiler related stuff in ralph.json file and import that file in alephium.config.ts pro: ralph-lsp can watch that json file
    cons: There are 2 files for configuration (but in a sense it make a clear separation between compiler and sdk)

  2. When web3 compiles, it outputs a json file with the values defined in alephium.config.ts pro: Only 1 configuration file cons: ralph-lsp will reflect the compiling changes only when user compile the project with web3.

None are ideal, I'll try to think more about it.

Do you have any proposition?

simerplaha commented 3 months ago

From the contracts.ts we extract the default compiler options,

Can we use node instead as it's simpler to do? Or is it important that we extract default compiler options from web3?

I see two directions:

Your first suggestion for having compiler related stuff in ralph.json file sounds good. It would also be the standard approach following Cargo.toml, package.json etc.

Two or more systems want to share some configuration data so using a shared configuration file makes things simple.

Question 2 for Requirement 2 - Move LSP-related Configurations

Shift ralph-lsp specific configurations to .ralph-lsp folder with default values to simplify its usage, avoid errors for new developers and increase adoption.

Considering issue #44 implementing library support: If we move ralph-lsp specific configurations to the home/common folder .ralph-lsp then all configured dependencies in that config file would get downloaded, parsed and compiled for every project? Even for the ones that do not require any dependency? This might increase boot-up and compile time.

{
  "compilerOptions":  {...},
  "contractPath": "...",
  "artifactPath": "...",
  "dependencyPath": "...",
  "dependencies": {
    "web3": "0.38.0",
    "ralph-test": "0.0.0",
    "data-structures": "0.0.0"
  }
}
tdroxler commented 3 months ago

Can we use node instead as it's simpler to do? Or is it important that we extract default compiler options from web3?

Oh I didn't know we had default one in node, I guess we could. I'll confirm with the node team once we have a clear vision on everything, if we can guarantee that node and web3 always have the same default value, I think we'll be good.

Question 2

I was unclear sorry (still a bit messy in my head too ^^) this time I was thinking of having a .ralph-lsp inside every project, but it's true that the first comment in this issue was mentioning home folder.

As you said it won't make sense to have those in the home folder.

Next Move

simerplaha commented 1 month ago

Closing as resolved.