Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Add autocompletion to module imports. #46

Merged
merged 24 commits into from
Feb 28, 2018

Conversation

laginha87
Copy link
Contributor

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

@laginha87 laginha87 changed the title 28 add autocompletion Add autocompletion to module imports. Feb 7, 2018
@@ -7,3 +7,7 @@ authors:
- Faustino Aguilar <http://faustinoaq.github.io>

license: MIT

targets:
Copy link
Contributor Author

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

@keplersj keplersj requested a review from faustinoaq February 7, 2018 19:40
@faustinoaq
Copy link
Member

This is awesome! @laginha87 Thank you so much!!! 😄

@faustinoaq
Copy link
Member

I gonna take some time to review this, I'll also push a fix for Travis CI (started on #44)

@faustinoaq
Copy link
Member

faustinoaq commented Feb 25, 2018

Hi @laginha87 I tested your PR and require completion works super nice 👍

vokoscreen-2018-02-25_00-58-51

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 def snippet because completion is Loading...

screenshot_20180225_010817

This PR is being awesome! 👏 🎉 😄

@faustinoaq
Copy link
Member

Oh! this works pretty nice with local modules as well 😄

vokoscreen-2018-02-25_01-31-34

@faustinoaq
Copy link
Member

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:

screenshot_20180225_015132

WDYT?

@laginha87
Copy link
Contributor Author

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.
I changed it to respond with an empty array of completion items when that happens, this way it includes the snippets and symbols from the extension.
I haven't looked at all of the spec for a language server but should snippets be part of it or should they come from the extension that connects to the language server ?

@laginha87
Copy link
Contributor Author

laginha87 commented Feb 25, 2018

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.

@faustinoaq
Copy link
Member

Hi @laginha87 I tried your last changes and looks like Loading... issue is fixed 👍

ezgif-4-585c247483

However, I modified your code a bit and seems like CancelParams isn't needed.

ezgif-4-e88804acb3

I haven't looked at all of the spec for a language server but should snippets be part of it or should they come from the extension that connects to the language server ?

The extension code that connect to LSP is pretty simple, just a few line of codes.
I think it can't manage that behavior.

@faustinoaq
Copy link
Member

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.

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 Loading... issue was still happening because it was raising a Completion error.

Fixed when it returns an empty array.

@faustinoaq
Copy link
Member

BTW, Please, sync the master branch on this PR, I can't see update button, I don't know why 😅

Copy link
Member

@faustinoaq faustinoaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks very nice, waiting for some more comments @kofno @bcardiff @keplersj 👀
Also Travis is failing now 😅
BTW, Thank you for adding code base for method and instance var completion 👍

This was referenced Feb 25, 2018
@laginha87 laginha87 force-pushed the 28-add-autocompletion branch from 5e705f2 to 5e2ba8a Compare February 25, 2018 19:44
@laginha87
Copy link
Contributor Author

I updated the branch with master and fixed the tests.
The cancel request not being handled I don't think it causes issues but if we don't handle it it'll raise an exception and show an error in the developer tools.

@@ -19,39 +19,39 @@ module Scry
text_document = TextDocument.new("uri", ["class Test; end"])
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

@faustinoaq faustinoaq left a 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?

Copy link
Contributor

@keplersj keplersj left a 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
Copy link
Contributor

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 😄 )

@laginha87
Copy link
Contributor Author

Thanks for all the feedback.
I applied the change to not use a regex.
Is this ready to be merged?

@faustinoaq
Copy link
Member

Is this ready to be merged?

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 faustinoaq merged commit 0a3627e into crystal-lang-tools:master Feb 28, 2018
@keplersj
Copy link
Contributor

@faustinoaq 👍. In truth I'd be okay with configuring something like semantic-release for scry.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants