fix: add context-aware SPDX and pragma completions#224
Conversation
There was a problem hiding this comment.
Looks like you need to specify the start and end to replace if we need the version completions.
pragma solidity 0.*| ^0.8.35;
// ^ completion cursorThere was a problem hiding this comment.
Fixed in 1e2f3e0. Version completions now use a text edit from the start of the pragma solidity value through the end of the existing version expression before ;. So the example pragma solidity 0.*| ^0.8.35; is replaced as a whole value and becomes pragma solidity ^0.8.35;, instead of inserting at the cursor or duplicating the trailing text.
Added test_context_completion_pragma_solidity_version_replaces_partial_token for this exact shape. I also tightened the pragma directive matching so pragma solidityx / pragma abicoderx do not get treated as directive contexts.
Verified with:
cargo check
cargo test --test completion test_context_completion
cargo test --test completion
cargo test919c1ff to
6a4663e
Compare
6a4663e to
1e2f3e0
Compare
|
Hi @mmsaki, quick follow-up on this one. I updated the PR based on your replacement-range feedback. Latest head is
Re-ran: cargo check
cargo test --test completion test_context_completion
cargo test --test completion
cargo testDoes this direction still look good for completion-side context handling, or would you prefer this split differently with codeActions? |
Closes #223
Problem
Completion inside source-unit directive contexts can fall through to normal/global Solidity completions. This makes early SPDX and pragma typing noisy, and SPDX insertion can duplicate the existing
//prefix depending on the client.Fix
// S,// SP,// SPD, and// SPDX.pragma,pragma solidity, andpragma abicodercontexts.Tests
rustfmt src/completion.rs tests/completion.rscargo checkcargo test --test completion -- --nocapturecargo test --lib -- --nocapturecargo testcargo build --release --bin solidity-language-servergit diff --check