ast-grep / ast-grep

⚡A CLI tool for code structural search, lint and rewriting. Written in Rust
https://ast-grep.github.io/
MIT License
7.3k stars 165 forks source link

[feature] LSP: inform user when rule is invalid #722

Open chrisgrieser opened 10 months ago

chrisgrieser commented 10 months ago

When you use ast-grep as LSP, you are not informed when the linting is not performed due to an invalid rule. Took me a while to come up with the idea to try ast-grep scan in the terminal, which revealed that an invalid rule was the cause:

> ast-grep scan
Error: Cannot parse rule {...}/short-var-names.yml
Help: The file is not a valid ast-grep rule. Please refer to doc and fix the error.
See also: https://ast-grep.github.io/guide/rule-config.html

✖ Caused by
╰▻ Fail to parse yaml as RuleConfig
╰▻ missing field `id` at line 11 column 1

I'd suggest displaying a diagnostic at line one with the info "invalid rule...", to inform the user why no linting is taking place.

HerringtonDarkholme commented 10 months ago

Thanks for the suggestion! It sounds like an LSP client feature to me. Are you using neovim?

chrisgrieser commented 10 months ago

yeah, I am.

Nonetheless, I think simply adding a diagnostic stating "config invalid" would already help a lot, and that could be done without any changes on lsp client side?

HerringtonDarkholme commented 10 months ago

The issue is that lsp only checks source code not config YAML. It may be worth adding editing support for rule completion/diagnostic in LSP.