-
Notifications
You must be signed in to change notification settings - Fork 31
Add autocompletion to module imports. #46
Add autocompletion to module imports. #46
Conversation
@@ -7,3 +7,7 @@ authors: | |||
- Faustino Aguilar <http://faustinoaq.github.io> | |||
|
|||
license: MIT | |||
|
|||
targets: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this so scry can be built by doing shards build
This is awesome! @laginha87 Thank you so much!!! 😄 |
I gonna take some time to review this, I'll also push a fix for Travis CI (started on #44) |
6621ec0
to
13d1ddf
Compare
Hi @laginha87 I tested your PR and However, something in this PR is breaking other features like word and snippet completion. Maybe this happens because still isn't full autocompletion and currently just works for module imports. In this screenshot you can't use This PR is being awesome! 👏 🎉 😄 |
Maybe we can find a way to include symbols on auto-completion, like I did here Also, if no autocompletion is found, we can try to suggest words and snippets: WDYT? |
The issue was happening here I was raising an exception when I couldn't identify the kind of autocompletion to apply. The exception was uncaught and then vscode would wait for the response which would never show up. |
Another thing that may cause the Loading... issue is the lack of concurrency in scry. Because scry processes requests sequentially there are tasks that are run when you open a file that you to have to wait for before getting a response for autocompletion. I don't know how we can get around that, we could spawn a Fiber on every request but I think we'd need to change the way we wait for input cause it doesn't seem like it yields to other fibers. |
Hi @laginha87 I tried your last changes and looks like However, I modified your code a bit and seems like
The extension code that connect to LSP is pretty simple, just a few line of codes. |
Yeah, I thought that, so, I tried using concurrent channels: (I'll open a new PR about this) next_request = Channel(Nil).new
context = Context.new
loop do
spawn do
content = Request.new(STDIN).read
request = Message.new(content).parse
results = context.dispatch(request)
rescue ex
results = [ResponseMessage.new(ex)]
ensure
response = Response.new([results].flatten)
response.write(STDOUT)
next_request.send nil
end
select
when next_request.receive
Log.logger.info("Scry has processed a request!")
next
else
sleep 1
end
end And Fixed when it returns an empty array. |
BTW, Please, sync the master branch on this PR, I can't see update button, I don't know why 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5e705f2
to
5e2ba8a
Compare
… completion items and not arrays
I updated the branch with master and fixed the tests. |
@@ -19,39 +19,39 @@ module Scry | |||
text_document = TextDocument.new("uri", ["class Test; end"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason we are updating symbol specs in this PR? Seems unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the way response message https://github.com/crystal-lang-tools/scry/pull/46/files#diff-82346a49d1a2a5c31d9a3445d7a9127dR9 I had to add a single CompletionItem as a response for the completion resolver.
The symbol specs expect an array in the response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve this, someone else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just did a quick skim-through. No objections from me
|
||
def find | ||
case @import | ||
when RELATIVE_IMPORT_REGEX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when .starts_with? '.'
would be faster here I think (and less regex is almost always better 😄 )
Thanks for all the feedback. |
Yeah, I think it is ready, Thank you so much for this PR 😄 👍 @keplersj I'm working on concurrent rpc for scry, I think we should publish a new release after that, WDYT? |
@faustinoaq 👍. In truth I'd be okay with configuring something like semantic-release for scry. |
I set up the groundwork to add autocompletion to scry.
Autocompletion needs the files in memory and not the saved files so I had to add a bunch of code to handle that.
Since I'm not super familiar with writing visitors and stuff I though I'd add autocompletion to the require "" statements because scry's autcompletion can work at the same time as the vscode crystal extension.
Related to #28