Skip to content

fix: add context-aware SPDX and pragma completions#224

Open
rifuki wants to merge 2 commits into
asyncswap:mainfrom
rifuki:fix/source-unit-directive-completions
Open

fix: add context-aware SPDX and pragma completions#224
rifuki wants to merge 2 commits into
asyncswap:mainfrom
rifuki:fix/source-unit-directive-completions

Conversation

@rifuki

@rifuki rifuki commented Jun 7, 2026

Copy link
Copy Markdown

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

  • Detect SPDX directive prefixes such as // S, // SP, // SPD, and // SPDX.
  • Offer full SPDX license directive lines using a line replacement edit.
  • Add pragma completions for pragma , pragma solidity , and pragma abicoder contexts.
  • Suppress unrelated generic/global completions in those directive contexts.

Tests

  • rustfmt src/completion.rs tests/completion.rs
  • cargo check
  • cargo test --test completion -- --nocapture
  • cargo test --lib -- --nocapture
  • cargo test
  • cargo build --release --bin solidity-language-server
  • git diff --check

Comment thread src/completion.rs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cursor

@rifuki rifuki Jun 8, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6a4663e. 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.

Verified with:

cargo check
cargo test --test completion test_context_completion
cargo test --test completion
cargo test

@rifuki rifuki force-pushed the fix/source-unit-directive-completions branch from 919c1ff to 6a4663e Compare June 8, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Completion leaks generic/global items in source-unit directive contexts

2 participants