alephium / ralph-lsp

Ralph language server
7 stars 1 forks source link

`alephium.config.ts` build overwrites all configured `ralph.json` values when a configuration is missing #280

Closed simerplaha closed 1 month ago

simerplaha commented 1 month ago

Issue

The alephium.config.ts build overwrites ALL configured values when one of the configs is missing.

Reproduce

  1. Update ralph.json to following, where the ignoreUnusedFunctionReturnWarnings config is missing:

    {
      "compilerOptions": {
        "ignoreUnusedConstantsWarnings": true,
        "ignoreUnusedVariablesWarnings": true,
        "ignoreUnusedFieldsWarnings": true,
        "ignoreUnusedPrivateFunctionsWarnings": true,
        "ignoreUpdateFieldsCheckWarnings": true,
        "ignoreCheckExternalCallerWarnings": true
      },
      "contractPath": "my_code"
    }
  2. Create, edit or save alephium.config.ts the following configurations, so TSBuild process gets triggered:

    compilerOptions: {
      ignoreUnusedConstantsWarnings: false
    },
    
    • Expected behaviour: The existing configurations in ralph.json should remain unchanged, and only the missing ignoreUnusedFunctionReturnWarnings should be added with a default value, along with other updated configs in alephium.config.ts.
    • Actual behaviour:
      • All existing configurations are overwritten to false.
      • It also overwrites contractPath from "my_code" to "contracts".
    {
      "compilerOptions": {
        "ignoreUnusedConstantsWarnings": false,
        "ignoreUnusedVariablesWarnings": false,
        "ignoreUnusedFieldsWarnings": false,
        "ignoreUnusedPrivateFunctionsWarnings": false,
        "ignoreUpdateFieldsCheckWarnings": false,
        "ignoreCheckExternalCallerWarnings": false,
        "ignoreUnusedFunctionReturnWarnings": false
      },
      "contractPath": "contracts"
    }

Cause

This occurs because the JSON parser in the build process requires all configurations to be present in order to create the config object RalphcConfigState.Parsed, which becomes unavailable to TSBuild.

Solution

PR #272 resolves this.