0

When coding in scala in IntelliJ IDEA, sometimes will the IDE suggest to replace .size == 0 by .isEmpty. Some other times, when calling a printf, will the IDE check that the number of variadic arguments matches what's in the format and that they have the expected type...

Let's say I create a class/method, that could require editor-level replacement suggestions or argument checks, as you can with C# annotations make your classes do pretty prints in debugging sessions, could we add something (annotations?) so that the user of that class/method receives these replacement suggestions or has their arguments checked in their favorite editor (let's say IntelliJ IDEA, but that shouldn't be limited to that)?

Do custom annotations for custom editor-level suggestions or checks exist?

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
tomoyo255
  • 153
  • 1
  • 8
  • Maybe you want to write an Intellij Idea plugin https://plugins.jetbrains.com/docs/intellij/developing-plugins.html – Dmytro Mitin Nov 29 '22 at 13:15
  • https://www.jetbrains.com/mps/ – Dmytro Mitin Nov 29 '22 at 17:28
  • https://scalacenter.github.io/scalafix/ – Dmytro Mitin Nov 29 '22 at 17:29
  • http://www.scalastyle.org – Dmytro Mitin Nov 29 '22 at 23:28
  • About developing a new plugin, I was fearing such an answer because it means adding new check rules, which requires, indeed, new IDE-side code. It's only fair. Thanks for suggesting it. But, my query was to question this practice on more general terms. Being tied to an IDE isn't that good. I'd rather have rules enforced from the language level as annotations like @checkFormat def printf(format: String, args: Any*). A lesser solution could be to have IDE-specifically recognized annotations (with no effect when there's no IDE) with, indeed, in that case a plugin to support them. – tomoyo255 Nov 30 '22 at 16:36
  • About mps, I don't know if that answers my question, but I like the graphical implementation of DSLs and somewhat dreamt of something like that more 25 years ago. Thanks for having me shown that. – tomoyo255 Nov 30 '22 at 16:38
  • About scalafix, I'm a bit puzzled. I believe scalafix helps enforcing already existing IDE checks. My question was about asking how to implement new ones. And, additionally, how to add such checks as language features rather than IDE features. Thanks for having pointed me to that software anyway. – tomoyo255 Nov 30 '22 at 16:40
  • About scalastyle, with a quick glance I admit, I believe it's a bit like scalafix: enforcing existing rules. Not the question. Thanks for having pointed me to that software anyway. – tomoyo255 Nov 30 '22 at 16:43
  • *"About scalafix, I'm a bit puzzled. I believe scalafix helps enforcing already existing IDE checks"* No, Scalafix is for developing new rules too https://scalacenter.github.io/scalafix/docs/developers/setup.html It can modify any Scala AST in place or print some warning or even make code generation (pre-compile-time replacement for macros). – Dmytro Mitin Nov 30 '22 at 16:48
  • It's based on [Scalameta](https://scalameta.org/)/[Semanticdb](https://scalameta.org/docs/semanticdb/guide.html), so it's IDE-agnostic (orthogonal to choice of IDE). You can see helloworlds here https://stackoverflow.com/questions/62047436/is-there-a-way-to-prevent-usage-of-a-specific-function-provided-by-a-dependency https://stackoverflow.com/questions/63977834/scalafix-resolving-object-apply-method – Dmytro Mitin Nov 30 '22 at 16:50
  • I thank you for all of your suggestions. I hope that they'll lift the general debate on that matter: should checks be a magical thing of the IDE with predefined views on coding style (yet somewhat configurable), probably only working on the standard library, therefore needing additional IDE plugins for more checks, or should checks (at least some of them, not pertaining to general coding best practices) be implementable at the code level so that they're universal and extensible? – tomoyo255 Nov 30 '22 at 16:52
  • RE *About scalafix... Oh, good to know. The information is valuable. No question there. Thank you. – tomoyo255 Nov 30 '22 at 16:57
  • About IDE plugins in my previous comment. That works too for companion software. – tomoyo255 Nov 30 '22 at 16:58
  • For IntelliJ IDEA, version 2023.1 introduced [user-defined regex inspections](https://blog.jetbrains.com/idea/2023/01/intellij-idea-2023-1-eap-2#Customregexp-basedsearchandreplaceinspections) which has the same pros and cons as making an IDE plugin, but is arguably orders of magnitude easier to do And besides regex it can use IntelliJs own structural search/replace, although I don't think that's supported for Scala yet – necauqua Apr 28 '23 at 10:47

0 Answers0