Comments (4)
There's no built-in way by checking the method definition straight. We'd need to keep track of which section we're currently inside. Something like this in pseudo code
class InlayHint < BaseRequest
def initialize(...)
@current_visibility = :public # Maybe use a Sorbet enum?
end
def visit_call(node) # not sure if it's call, command, fcall...
if this_thing_is_private_public_or_protected
@current_visibility = the_new_visibility
end
end
def visit_def(node)
add_hint_using_current_visibility
end
end
Two thoughts:
- I think we shouldn't add anything for public methods, since that's the default
- If it's possible, I think this inlay hint would look better on top of the method name (not on the left or right)
from ruby-lsp.
Ooo neat, thanks for the pointers!
I think we shouldn't add anything for public methods, since that's the default
Completely agree. That would be really messy.
If it's possible, I think this inlay hint would look better on top of the method name (not on the left or right)
Should be entirely possible. This hint in particular really runs the risk of looking messy, I agree that above is a good place to start. If I get a chance to hack on it, I'll be sure to propose a few options with screenshots for easy evaluation.
from ruby-lsp.
@vinistock I want to give this a try. I'll start by listing common cases that can use the hint.
But without type information, there aren't too many features we can implement with high accuracy.
-
Implicit
self
-
Implicit type information, like
rescue => e (Exception)
raise "error" (RuntimeError)
-
Method visibility
private # 100 lines (private) def foo end
-
Expanded namespace
- Not sure how practical it is without code evaluation
module Foo module Rails; end (Foo::)Rails
For new developers
These may be too intrusive and distracting for experienced developers. But they could help new devs understand Ruby.
-
Expand syntactical sugar like
&=
or|=
a |= b # (a = a | b)
-
Operator precedence
1 + 2 * 5 # (1 + (2 * 5))
-
Explain
%
literals%q(foobarbaz) # String "foobarbaz"
Things that'll be helpful if possible
-
Possible super source
class A def foo; end end class B < A def foo super # hint A end end
from ruby-lsp.
I dug into adding a hint for indicating method visibility but I kept hitting a wall in figuring out whether or not a def
node was private/protected/public.
Would that require enhancing syntax_tree a bit or is there some elegant way to determine a node's visibility that I've missed? Maybe I'm looking at it from the wrong perspective.
from ruby-lsp.
Related Issues (20)
- `Failed to activate Ruby environment: Discovered Ruby path but VS Code does not have permissions to execute it`
- LSP server failed to start: [info] (icn) Gem::Ext::BuildError: ERROR: Failed to build gem native extension. HOT 2
- No RuboCop doc links for extensions HOT 1
- vs code: asdf environment variables ignored
- `--yjit` added to ruby command when not supported (with asdf usage) HOT 1
- VSCode: "Pull diagnostics on save" setting is not working HOT 2
- Re-think the way we locate nodes as targets and how addons declare the ones they are interested in.
- ASDF fails to start when using legacy_version_file
- Run Rspec Test on CodeLens is quite slow HOT 1
- Unable to autocomplete constant inside namespace due to Prism error
- Duplicate test actions HOT 5
- Include comments when dispatching listener events
- Handle manually invoked completion HOT 3
- Add some diagnostic logging for ruby-lsp HOT 3
- Slow vscode HOT 2
- Move 'Using a Custom Gemfile' to main README
- Change approach for Prism fixtures HOT 7
- Error `SystemStackError` when ruby-lsp tries to index .crt file HOT 4
- Stack level too deep error on indexing project with docusign_esign gem dependency HOT 5
- Support Ruby on Rails detection based on Rails individual gems HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ruby-lsp.