feat: Add helpful hints for contract not found errors in LSP#2065
feat: Add helpful hints for contract not found errors in LSP#2065emmanuelist wants to merge 2 commits intostx-labs:mainfrom
Conversation
Enhanced error messages in both clarity-lsp and clarinet-cli LSP modules to provide contextual hints when developers encounter common Clarity errors: - "use of unresolved contract" - Suggests checking Clarinet.toml, contracts/ directory, and deployment order - "use of unresolved trait" - Suggests verifying trait definition, use-trait import, and deployment order - "contract not found"/"NoSuchContract" - Suggests checking Clarinet.toml registration, file existence, and exact naming - "use of unresolved function" - Suggests verifying function definition, naming, and public visibility Changes: - Modified components/clarity-lsp/src/utils/mod.rs: - Added enhance_error_message() helper function - Updated clarity_diagnostic_to_lsp_type() to use enhanced messages - Resolved TODO comment for contract not found hints - Modified components/clarinet-cli/src/lsp/mod.rs: - Added enhance_error_message() helper function - Updated clarity_diagnostic_to_tower_lsp_type() to use enhanced messages - Resolved TODO comment for contract not found hints This improvement helps developers quickly identify and resolve common issues when working with Clarity contracts in VS Code.
|
Hey @emmanuelist This is a step in the right direction. But maybe still not ideal. Regarding the messages: Regarding the implementation itself, I like the idea of having What do you think? |
Problem
When developers encounter contract-related errors in the Clarity LSP (Language Server Protocol), error messages are often cryptic and don't provide actionable guidance. Developers waste time debugging simple configuration issues like missing imports or incorrect Clarinet.toml entries.
Solution
This PR enhances error messages in both
clarity-lspandclarinet-cliLSP modules by adding contextual hints that help developers quickly identify and resolve common issues.Implementation
Added an
enhance_error_message()helper function that detects common error patterns and appends helpful hints:1. "use of unresolved contract"
2. "use of unresolved trait"
3. "contract not found" / "NoSuchContract"
4. "use of unresolved function"
Files Modified
components/clarity-lsp/src/utils/mod.rs- Addedenhance_error_message()helper and updatedclarity_diagnostic_to_lsp_type()components/clarinet-cli/src/lsp/mod.rs- Addedenhance_error_message()helper and updatedclarity_diagnostic_to_tower_lsp_type()Testing
clarity-lspandclarinet-clicompile successfully"use of unresolved contract","use of unresolved function")Resolves
components/clarity-lsp/src/utils/mod.rs:40- "add hint for contracts not found errors"components/clarinet-cli/src/lsp/mod.rs:76- "add hint for contracts not found errors"Example Output
Before:
After:
Impact
This enhancement improves developer experience by reducing debugging time and making error messages more actionable, especially beneficial for developers new to Clarity and Clarinet.
Type: Enhancement
Component: LSP, Developer Experience
Breaking Changes: None