Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer if a variable or method is undefined #150

Open
raghavio opened this issue Dec 25, 2024 · 2 comments
Open

Infer if a variable or method is undefined #150

raghavio opened this issue Dec 25, 2024 · 2 comments

Comments

@raghavio
Copy link

A lot of times, due to typo or some refactoring, I end up having variables in my code that do not exist. It is after I run the code I get to know about it. No static analyzer/linter can pick this up because of how Ruby is. It could be defined anywhere. It could also be a method etc.

Because Robe has access to the Ruby VM, I was wondering if it is possible to infer and warn when a variable or method used in the code does not exist. I believe it should be possible because apparently RubyMine does something like this. It probably will be compute heavy though.

@raghavio raghavio changed the title Infer if a variable or method is undeclared Infer if a variable or method is undfined Dec 25, 2024
@raghavio raghavio changed the title Infer if a variable or method is undfined Infer if a variable or method is undefined Dec 25, 2024
@dgutov
Copy link
Owner

dgutov commented Dec 26, 2024

Hi!

This is a good suggestion. Alas, it's not a small change: the code doesn't have any kind of linter implementation at the moment, and it would need to be done in the server, I think, to have any chance at good performance.

It would probably be easier to approach the same problem from the other end, and highlight only the known local variables instead, using tree-sitter (here's an example of how this could be integrated: https://tree-sitter.github.io/tree-sitter/3-syntax-highlighting.html#local-variables, though this is not available in Emacs' treesit.el yet either). That's an approach for typos in variable names anyway.

As far as missing methods (or typos in method calls), runtime info could indeed help uniquely, though only for calls with the default receiver (meaning, methods on the same object). In many other cases, the object type is not always detectable, meaning the scan would have both false positives and false negatives.

@dgutov
Copy link
Owner

dgutov commented Dec 26, 2024

Any chance you have a screenshot of the similar functionality in RubyMine? It would help to compare.

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

No branches or pull requests

2 participants