From 119daa3d5fcaba59466605f53b1bb11db41e98c6 Mon Sep 17 00:00:00 2001 From: davidsemakula Date: Thu, 28 Sep 2023 21:00:51 +0300 Subject: [PATCH] Amend ink! analyzer (phase 2) --- applications/ink-analyzer-phase-2.md | 41 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/applications/ink-analyzer-phase-2.md b/applications/ink-analyzer-phase-2.md index 898c83f8471..b22129c52ca 100644 --- a/applications/ink-analyzer-phase-2.md +++ b/applications/ink-analyzer-phase-2.md @@ -27,9 +27,8 @@ This allows ink! developers to leverage Rust tooling like [clippy](https://doc.r However, relying on only generic Rust language support in IDEs, code editors and other development tools has some significant limitations for the developer experience including: -- No language support (e.g. diagnostic errors/warnings and quick fixes) for ink!'s domain specific semantic rules for smart contracts (e.g. exactly one `#[ink(storage)]` struct, at least one `#[ink(message)]` method and the same for `#[ink(constructor)]`, ink! attributes should be applied to items of the correct type e.t.c). -- Inconsistent editor experience with issues like no code completion and/or hover content for some ink! attribute arguments (e.g `#[ink(payable)]`) because [macro expansion/name resolution and trait resolution are hard problems for generic IDE/code editor tools](https://rust-lang.github.io/compiler-team/working-groups/rls-2.0/#scope-and-purpose) (see also [https://rust-analyzer.github.io/blog/2021/11/21/ides-and-macros.html](https://rust-analyzer.github.io/blog/2021/11/21/ides-and-macros.html)). -- No language support (e.g. go to definition, find references and rename/refactor) for [ink! specific syntax like paths in ink! attribute argument values (e.g. `env` values)](https://github.com/paritytech/ink/blob/v4.2.1/crates/ink/ir/src/ast/mod.rs#L19-L25). +- No language support (e.g. diagnostic errors/warnings and quick fixes) for ink!'s domain specific semantic rules for smart contracts (e.g. exactly one `#[ink(storage)]` struct, at least one `#[ink(message)]` method and the same for `#[ink(constructor)]`, ink! attributes should be applied to items of the correct type, ink! `env` and `environment` argument values must `impl Environment` e.t.c). +- Inconsistent editor experience with issues like no code completion and/or hover content for some ink! attribute arguments (e.g `#[ink(payable)]`) because [macro expansion/name resolution and trait resolution are hard problems for generic IDE/code editor tools](https://rust-lang.github.io/compiler-team/working-groups/rls-2.0/#scope-and-purpose) (see also [https://rust-analyzer.github.io/blog/2021/11/21/ides-and-macros.html](https://rust-analyzer.github.io/blog/2021/11/21/ides-and-macros.html)). #### Solution @@ -57,10 +56,11 @@ This stage of the project will improve ink! language support features across all - Quick fixes for all existing diagnostic errors and warnings. - ink_e2e macro support (i.e diagnostics, quickfixes, completions, code actions and hover content). - Command for creating an ink! project and code/intent actions for inserting code stubs/snippets for relevant ink! entities. -- Go to definition, find references and rename/refactor support for path-based ink! attribute argument values (i.e. `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]`). -- Diagnostics that verify that the value of `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]` are `impl Environment` as well as quick fixes to `impl Environment` for the target item where necessary. - Inlay hints and signature help/parameter hints for ink! attribute arguments. - Code/intent actions for "flattening" ink! attributes. +- Diagnostics that verify that the value of `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]` are `impl Environment` as well as quick fixes to `impl Environment` for the target item where necessary. +- Diagnostics that verify chain extension `ErrorCode` types (and other chain extension utility types) implement required traits (e.g. `FromStatusCode` for `ErrorCode` types and SCALE code traits - i.e. scale's `Encode` and `Decode` and scale-info's `TypeInfo` traits - for error types, and input and output types of chain extension methods) as well as quick fixes to implement the required traits for the target items where necessary. +- Diagnostics and quickfixes for implementing missing methods for ink! trait definition implementations. #### Observation @@ -203,9 +203,9 @@ You can find a full list of available resources in the [introductory blog post f ### Overview -- **Total Estimated Duration:** ~7.75 months +- **Total Estimated Duration:** ~8.5 months - **Full-Time Equivalent (FTE):** 1 -- **Total Costs:** 54,400 USD +- **Total Costs:** 59,600 USD ### Milestone 1 — Semantic analyzer: Quick fixes, ink_e2e macro support, project creation command and code/intent actions for inserting code stubs/snippets for relevant ink! entities @@ -246,23 +246,22 @@ You can find a full list of available resources in the [introductory blog post f - **FTE:** 1 - **Costs:** 10,800 USD -| Number | Deliverable | Specification | -|--------:|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **0a.** | License | MIT or Apache 2.0 | -| **0b.** | Documentation | I will provide detailed source documentation including rustdoc documentation that will be published to [docs.rs](https://docs.rs/) and a README file (published on [Github](https://github.com/), [crates.io](https://crates.io/) and [docs.rs](https://docs.rs/)) providing general information about the library, instructions for installing and using the library and links to other documentation and resources related to the library. | -| **0c.** | Testing and Testing Guide | Core functions will be fully covered by comprehensive unit tests to ensure functionality and robustness. In the guide, I will describe how to run these tests. | -| **0d.** | Docker | I will provide a Dockerfile(s) that can be used to test all the functionality delivered with this milestone. | -| 1. | Rust crate update: Go to definition support for path-based ink! attribute argument values (i.e. `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]`) | I will update the semantic analyzer crate to provide an interface that accepts ink! smart contract code and a cursor position as input and returns the location where the item resolved by the path (if any) is defined (e.g. for `#[ink::contract(env=crate::MyEnvironment)]`, returns the location where `MyEnvironment` item is defined). While only `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]` can be defined as paths at the moment, this utility will be defined generically for any path-based value used as an ink! attribute argument value. | -| 2. | Rust crate update: Find references support for path-based ink! attribute argument values (i.e. `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]`) | I will update the semantic analyzer crate to provide an interface that accepts ink! smart contract code and a cursor position as input and returns locations where the item resolved by the path (if any) is used (e.g. for `#[ink::contract(env=crate::MyEnvironment)]`, returns the locations where the `MyEnvironment` item is used). While only `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]` can be defined as paths at the moment, this utility will be defined generically for any path-based value used as an ink! attribute argument value. | -| 3. | Rust crate update: Rename/refactor support for path-based ink! attribute argument values (i.e. `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]`) | I will update the semantic analyzer crate to provide an interface that accepts ink! smart contract code, a cursor position and the new name for the item as input and returns the text edits for renaming the item resolved by the path (if any) across the workspace (e.g. for a `MyEnvironment` defined used in an `#[ink::contract(env=crate::MyEnvironment)]` and an `#[ink_e2e::test(environment=crate::MyEnvironment)]`, this renames `MyEnvironment` across all these locations). While only `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]` can be defined as paths at the moment, this utility will be defined generically for any path-based value used as an ink! attribute argument value. | -| 4. | Rust crate update: Diagnostics that verify that `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]` are `impl Environment` as well as quick fixes to `impl Environment` for the target item where necessary | I will update the semantic analyzer crate by updating the existing interface that accepts ink! smart contract code as input and returns diagnostic errors and warnings to additionally return diagnostics for `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]` whose target item doesn't `impl Environment` as well as quick fixes in the form of code/intent actions that insert code stubs/snippets that `impl Environment` for the target item where necessary. | +| Number | Deliverable | Specification | +|--------:|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **0a.** | License | MIT or Apache 2.0 | +| **0b.** | Documentation | I will provide detailed source documentation including rustdoc documentation that will be published to [docs.rs](https://docs.rs/) and a README file (published on [Github](https://github.com/), [crates.io](https://crates.io/) and [docs.rs](https://docs.rs/)) providing general information about the library, instructions for installing and using the library and links to other documentation and resources related to the library. | +| **0c.** | Testing and Testing Guide | Core functions will be fully covered by comprehensive unit tests to ensure functionality and robustness. In the guide, I will describe how to run these tests. | +| **0d.** | Docker | I will provide a Dockerfile(s) that can be used to test all the functionality delivered with this milestone. | +| 1. | Rust crate update: Diagnostics that verify resolution of path expressions for `env` for `#[ink::contract]` and `environment` for `#[ink_e2e::test]` argument values as well as quick fixes that either fix paths (e.g. by fixing or adding a qualifier) or suggest paths to valid item definitions (where possible) | I will update the semantic analyzer crate by updating the existing interface that accepts ink! smart contract code as input and returns diagnostic errors and warnings to additionally return diagnostics for resolution of path expressions for `env` for `#[ink::contract]` and `environment` for `#[ink_e2e::test]` argument values whose value doesn't resolve to any item as well as quick fixes in the form of code/intent actions that either fix paths (e.g. by fixing or adding a qualifier) or suggest paths to valid item definitions (where possible). | +| 2. | Rust crate update: Diagnostics that verify that `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]` are `impl Environment` as well as quick fixes to `impl Environment` for the target item where necessary | I will update the semantic analyzer crate by updating the existing interface that accepts ink! smart contract code as input and returns diagnostic errors and warnings to additionally return diagnostics for `env` values for `#[ink::contract]` and `environment` values for `#[ink_e2e::test]` whose target item doesn't `impl Environment` as well as quick fixes in the form of code/intent actions that insert code stubs/snippets that `impl Environment` for the target item where necessary. | +| 3. | Rust crate update: Diagnostics that verify that ink! trait definition `impl` blocks implement all associated methods as well as quick fixes for implementing missing methods where necessary | I will update the semantic analyzer crate by updating the existing interface that accepts ink! smart contract code as input and returns diagnostic errors and warnings to additionally return diagnostics for ink! trait definition `impl` blocks that don't implement all associated methods as well as quick fixes in the form of code/intent actions that add code stubs/snippets for implementing missing methods where necessary. | -### Milestone 4 — Semantic Analyzer: Diagnostics, quick fixes and code/intent actions for chain extension `ErrorCode` type is `impl FromStatusCode` , and is not referred to using `Self::ErrorCode` anywhere in the chain extension or it's defined methods +### Milestone 4 — Semantic Analyzer: Diagnostics, quick fixes and code/intent actions for chain extension `ErrorCode` type is `impl FromStatusCode` , and is not referred to using `Self::ErrorCode` anywhere in the chain extension or its defined methods -- **Estimated duration:** ~3 weeks +- **Estimated duration:** ~5-6 weeks - **FTE:** 1 -- **Costs:** 5,600 USD +- **Costs:** 10,800 USD | Number | Deliverable | Specification | |--------:|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| @@ -272,6 +271,8 @@ You can find a full list of available resources in the [introductory blog post f | **0d.** | Docker | I will provide a Dockerfile(s) that can be used to test all the functionality delivered with this milestone. | | 1. | Rust crate update: Diagnostics that verify that the chain extension `ErrorCode` type is `impl FromStatusCode` as well as quick fixes and code/intent actions to `impl FromStatusCode` for the target item where necessary | I will update the semantic analyzer crate by updating the existing interface that accepts ink! smart contract code as input and returns diagnostic errors and warnings to additionally return diagnostics for chain extension `ErrorCode` types whose target item doesn't `impl FromStatusCode` as well as quick fixes in the form of code/intent actions that insert code stubs/snippets that `impl FromStatusCode` for the target item where necessary. | | 2. | Rust crate update: Diagnostics for references to the chain extension's `ErrorCode` type using `Self::ErrorCode` in the chain extension (i.e. the `#[ink::chain_extension]` annotated `trait`) or it's defined methods (i.e. `impl` blocks for the chain extension `trait` in a `#[ink::contract]` annotated `mod`) as well as quick fixes to replace `Self::ErrorCode` usages with the `ErrorCode` type directly | I will update the semantic analyzer crate by updating the existing interface that accepts ink! smart contract code as input and returns diagnostic errors and warnings to additionally return diagnostics for references to the chain extension's `ErrorCode` type using `Self::ErrorCode` in the chain extension (i.e. the `#[ink::chain_extension]` annotated `trait`) or it's defined methods (i.e. `impl` blocks for the chain extension `trait` in a `#[ink::contract]` annotated `mod`) as well as quick fixes in the form of code/intent actions that replace `Self::ErrorCode` usages with the `ErrorCode` type directly. | +| 3. | Rust crate update: Diagnostics that verify that the chain extension `ErrorCode` type implements SCALE codec traits (i.e. scale's `Encode` and `Decode` and scale-info's `TypeInfo`) as well as quick fixes and code/intent actions to implement the SCALE codec traits for the target item where necessary | I will update the semantic analyzer crate by updating the existing interface that accepts ink! smart contract code as input and returns diagnostic errors and warnings to additionally return diagnostics for chain extension `ErrorCode` types whose target item doesn't implement SCALE codec traits (i.e. scale's `Encode` and `Decode` and scale-info's `TypeInfo`) as well as quick fixes in the form of code/intent actions that insert code stubs/snippets that implement SCALE codec traits for the target item where necessary. | +| 4. | Rust crate update: Diagnostics that verify that input and output types of chain extension methods implement SCALE codec traits (i.e. scale's `Encode` and `Decode` and scale-info's `TypeInfo`) as well as quick fixes and code/intent actions to implement the SCALE codec traits for the target item where necessary | I will update the semantic analyzer crate by updating the existing interface that accepts ink! smart contract code as input and returns diagnostic errors and warnings to additionally return diagnostics for input and output types of chain extension methods whose target items don't implement SCALE codec traits (i.e. scale's `Encode` and `Decode` and scale-info's `TypeInfo`) as well as quick fixes in the form of code/intent actions that insert code stubs/snippets that implement SCALE codec traits for the target items where necessary. | ### Milestone 5 — Language Server: Updates #1