crystal-lang-tools/scry

Issues with completion on some files

faustinoaq opened this issue ยท 15 comments

@laginha87 I knew I had some issues with auto-completion feature and I have found them, sometimes the completion is broken in projects with sub directories. And keep working only in the main project file.

In the example below, I tried scry master and tested completion on all files, (baz.cr, bar.cr and foo.cr) and no one works but only console.cr. No matter where I put them, completion just work on one file, the main file console.cr for the project console

vokoscreen-2018-04-09_15-39-07

Full logs here: https://gist.github.com/faustinoaq/65b39e810dc1e4a6a3456bb0286d48e6

BTW, There's no errors in that project and also I reloaded VSCode before trying to use auto-completion

Also, if you see the logs, scry is logging something like: Couldn't find type ..., Why? ๐Ÿ˜…

hmm that is weird, I'll look into it.
The couldn't find type is thrown when it can't find the type in the dependencies of the file you're on.

So, looks like some of my files are not being included in the auto-completion database because some strange reason ๐Ÿ˜…

screenshot_20180410_102641

@laginha87 I checked the logs and the file file:///home/main/Projects/console/src/console/baz.cr was included successfully in the dependency graph, although completion doesn't work in that file as you can see in my gif.

Seems there is something wrong with these lines:

graph.each.reject { |e| e == prelude_node.not_nil!.value }.each do |key, _|
graph[key].connections << prelude_node.not_nil!
end

@laginha87 Can you reproduce this issue? ๐Ÿ˜…

I did some test, this bugs seems to be related to the require system and sub directory structure of the project, (maybe names mismatch).

If a try a new clean crystal project crystal init app bar, then auto-completion only works on src/bar.cr:

screenshot_20180410_183804

but not on src/bar/version.cr

screenshot_20180410_183829

Surprisingly If a try an amber project, auto-completion feature work without problems in all files: (even in files outside src folder)

screenshot_20180410_183943

screenshot_20180410_184006

screenshot_20180410_184602

So, I really don't know what is happening here ๐Ÿ˜… I think we need to review this code:

@lookup_paths
.map { |e| File.join(File.expand_path(e), "**", "*.cr") }
.uniq
.flat_map { |d| Dir.glob(d) }
.each { |file| process_requires(file, graph) }
prelude_node = graph[/src\/prelude.cr$/]
Log.logger.debug("Finished building the dependancy graph got these nodes:#{graph.each.to_a.map(&.first)}")
return graph if prelude_node.nil?
graph.each.reject { |e| e == prelude_node.not_nil!.value }.each do |key, _|
graph[key].connections << prelude_node.not_nil!
end

Surprisingly If a try an amber project, auto-completion feature work without problems in all files

I checked again and seems in some files auto-completion doesn't work:

screenshot_20180410_185654

@laginha87 here are the scry logs for crystal init app bar

auto-completion inside src/bar/version.cr doesn't work

screenshot_20180410_183829

Sorry for so many comments and Thank you for your help! ๐Ÿ˜… ๐Ÿ‘

No worries, sorry I haven't had time to look at these yet.

Hi @laginha87 I guess I fixed something in #92

Std lib Completion for all crystal files is working now, even in untitled files ๐ŸŽ‰

screenshot_20180423_103742
screenshot_20180423_103945

Wow, I think #92 fixes this definitely, see my comment: #92 (comment)

It's very odd, cause in that case reload would have fixed issue (temporarily at least)

@laginha87 maybe this issue was caused by #59 and #91, so when the Missing hash key was fixed in #92 then this issue got fixed as well.