Skip to content

Commit

Permalink
Merge pull request #864 from soutaro/hover-node-type
Browse files Browse the repository at this point in the history
Let hover show the type of method call node
  • Loading branch information
soutaro committed Jul 11, 2023
2 parents c8f5213 + 0bd7d45 commit 38ea2a1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/steep/server/lsp_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ def format_hover_content(content)

case call
when TypeInference::MethodCall::Typed
io.puts <<~MD
```rbs
#{call.actual_method_type.type.return_type}
```
----
MD

method_types = call.method_decls.map(&:method_type)

if call.is_a?(TypeInference::MethodCall::Special)
method_types = [
call.actual_method_type.with(
Expand Down Expand Up @@ -250,6 +259,10 @@ def format_completion_docs(item)
end

io.string
when Services::CompletionProvider::KeywordArgumentItem
<<~MD
**Keyword argument**: `#{item.identifier}`
MD
end
end

Expand Down
25 changes: 25 additions & 0 deletions test/server/lsp_formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def foo: [A] (A) -> Array[A]

comment = Server::LSPFormatter.format_hover_content(content)
assert_equal <<~MD, comment
```rbs
::Array[::Integer]
```
----
**Method type**:
```rbs
[A] (A) -> ::Array[A]
Expand Down Expand Up @@ -90,6 +95,11 @@ def __foo__: () -> void

comment = Server::LSPFormatter.format_hover_content(content)
assert_equal <<~MD, comment
```rbs
void
```
----
**Method type**:
```rbs
() -> void
Expand Down Expand Up @@ -125,6 +135,11 @@ def foo: [A] (A) -> Array[A]

comment = Server::LSPFormatter.format_hover_content(content)
assert_equal <<~MD, comment
```rbs
::Array[::Integer]
```
----
**Method type**:
```rbs
[A] (A) -> ::Array[A]
Expand Down Expand Up @@ -166,6 +181,11 @@ def foo: () -> Symbol

comment = Server::LSPFormatter.format_hover_content(content)
assert_equal <<~MD, comment
```rbs
(::Integer | ::String | ::Symbol)
```
----
**Method type**:
```rbs
() -> ::Integer
Expand Down Expand Up @@ -206,6 +226,11 @@ def test_ruby_hover_method_call__special

comment = Server::LSPFormatter.format_hover_content(content)
assert_equal <<~MD.chomp, comment
```rbs
::Array[::Integer]
```
----
**💡 Custom typing rule applies**
----
Expand Down

0 comments on commit 38ea2a1

Please sign in to comment.