-
Notifications
You must be signed in to change notification settings - Fork 31
Conversation
Still want to had some more tests but wanted to have some input on the direction I took this. |
Hi @laginha87 Thank you for this PR 👍 I'm trying to test this on VSCode but I got an error:
|
😢 |
Hi @laginha87
No, I'm using a workspace in that example, look at titlebar, the workspace name is @laginha87 I tried sublime as well, and same error happens, maybe we're missing some json field? 😅 |
@faustinoaq I was preloading every crystal file under src/ your example doesn't have that changed it to preloading every cr file under the workspace root. |
Hi @laginha87, Thank you for yout last commit! Scry server is running now 🎉 althought completion doesn't work yet on vscode nor sublime I tried with/without a workspace and I got this: Variable was assigned a boolean (a = true; a.m)a = true; a.to_s
Variable was assigned an int (a = 1; a.m)b = 1; b.to_s
The var's type is declared in the method definition (ex: def(a: File); a.me)def foo(c : File)
c
end
foo(File.open("./foo.cr"))
The object where its called is a class. (ex: File.exp)File.exists?("./foo.cr")
The method is defined as a property/getter/setterclass Foo
property bar : Int32?
end
baz = Foo.new
baz.bar
BTW, I see you're using four spaces to indent crystal code
Crystal code guidelines says 2 spaces 😅 Try using |
I tried to setup BTW, |
@faustinoaq Thanks for trying this out. |
About the |
@laginha87 Thank you for all your effort! 👍 I tried creating a new crystal project using Seems that
Here is my latest debug logs (testing this completion feature) I approve this PR 😄 , although I think more people should try it. BTW, Scry completion is not working on sublime, I don't know why, sublime has other issues with scry though |
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.
Very nice PR, Just waiting for more reviews 👍
I did it! Scry completion is working in sublime as well! 🎉 ✨
// Settings in here override those in "LSP/LSP.sublime-settings",
{
"clients":
{
// Each new client must have the following structure.
"crystal":
{
// The command line required to run the server.
"command": ["/home/main/Projects/scry/scry"],
// Use: "Show Scope Name" from Sublime's Developer menu
"scopes": ["source.crystal", "source.cr"],
// Run: view.settings().get("syntax") in console
"syntaxes": ["Packages/Crystal/Crystal.tmLanguage"],
// See: https://github.com/Microsoft/language-server-protocol/issues/213
"languageId": "crystal",
"only_show_lsp_completions": true,
"log_payloads": true,
"show_diagnostics_phantoms": true,
// Sent to server once using workspace/didConfigurationChange notification
"settings": {
"problems":"syntax",
"implementations":false,
"hover":false,
"completion":false,
"mainFile":"",
"maxNumberOfProblems":100,
"processesLimit":3,
"compiler":"crystal",
"server":"/home/main/Projects/scry/scry",
"logLevel":"debug",
"bashOnWindows":false
},
// Sent once to server in initialize request
"initializationOptions": {
"capabilities": {
"workspace": {
"applyEdit": true
},
"textDocument": {
"synchronization": {
"didSave": true
},
"completion": {
"completionItem": {
"snippetSupport": true
}
}
}
}
}
}
}
} |
@keplersj @bmulvihill Can you review this?, I would like to get it merged 😅 |
@faustinoaq @laginha87 This is a big PR. One thing sticks out to me, a lot of the code here is building up a dependency graph Is that necessary? Are we able to just use some sort of main file or root path for the project? From there we can get all the It seems like maybe that is a simpler approach. Although I don't have all the context regarding this PR, and maybe that won't work for this. |
Hi @bmulvihill 😄 I think @laginha87 is trying to implement auto completion based on cracker by @TechMagister Cracker is using a similar mechanism, I don't know if is the best way, though |
@faustinoaq I took a look at cracker, I didn't notice any use of dependency graphs, unless I missed something. |
@bmulvihill you're right the dependancy graph stuff isn't in cracker. In cracker they only define a preload method and your integration with the editor handles what to preload. I added the dependancy graph cause I didn't like that the autocomplete suggestions could be inaccurate by providing completion hints for files that are not required by the file you're working on. I understand that this would be picked up by the compiler but since you can reopen classes it can lead to some strange behaviour the compiler just tells the method doesn't exist on the class you know you're requiring correctly. I was also worried with the memory footprint specially if you're in a project with a lot of libraries. The dependancy graph might have been a premature optimization and it can be handled later. If we just preload the files from the main root file we lose completion for files with no workspace and for any helper methods defined in the specs. |
@bmulvihill I can try it out without the graph to shorten the PR and it can be added later if it seems like a reasonable approach. I have done a lot more work around completion in scry so I split the work in smaller chunks so they'd be easier to review. |
@laginha87 Thank you for the explanation, like I said I definitely don't have all the context, I am just curious about the approach. Would some of the problems mentioned be solved by always updating the method DB every time we update a file? What I mean is we create the method DB when opening the project based on some root path/main file and then make updates to it as we update files via the DidChangeTextDocument notification. Or am I misunderstanding the issue? I was thinking whatever approach is used here eventually could also be used to solve Workspace symbols as well. |
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.
Looks okay to me. Looks like a good implementation. And of course once it's out there we can dogfood it and having an implementation like this starts making life easier
@bmulvihill those are all valid points.
and you're editing this:
The completion will suggest both And also thought this approach would be better to later store all this info in the filesystems for a faster boot up. Right now the solution isn't very dependant on the graph and I can easily remove it and we can add it later if there's an actual need for it. |
@laginha87 Ok cool, thanks again for explaining. I think it is good the way it is 👍 |
Seems this PR is enough approved, I'll merge it Please if you found some problem trying these new features open a new issue or a PR fixing it. Thank you so much for these contributions 😄 👏 ✨ |
This PR improves scry's autocompletion by adding method completion for some cases.
The strategy applied was inspired by https://github.com/techMagister/cracker/ where:
For now it only covers the following scenarios:
Also it doesn't cover: