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

Formatting untitled files is broken #64

Closed
faustinoaq opened this issue Mar 11, 2018 · 5 comments
Closed

Formatting untitled files is broken #64

faustinoaq opened this issue Mar 11, 2018 · 5 comments
Assignees
Labels

Comments

@faustinoaq
Copy link
Member

faustinoaq commented Mar 11, 2018

Hi, I tried latest scry release (v0.7.1) and seems formatting untitled files (implemented on #54 ) is broken now:

I'm getting this message (relevant message):

D, [2018-03-11 08:57:22 -05:00 #2962] DEBUG -- : Content-Length: 276
D, [2018-03-11 08:57:22 -05:00 #2962] DEBUG -- : 
D, [2018-03-11 08:57:22 -05:00 #2962] DEBUG -- : {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"untitled:Untitled-1","version":3},"contentChanges":[{"text":"module Console\n    class ClassName\n      def initialize\n      end\n  \n      def method_name\n      end\n    end\n  end\n  "}]}}
D, [2018-03-11 08:57:22 -05:00 #2962] DEBUG -- : textDocument/didChange
D, [2018-03-11 08:57:22 -05:00 #2962] DEBUG -- : Content SEND: Content-Length: 780

{"jsonrpc":"2.0","error":{"code":-32001,"message":"Missing hash key: \"untitled:Untitled-1\"","data":["/usr/lib/crystal/hash.cr:0:9 in 'fetch'","/usr/lib/crystal/hash.cr:62:5 in '[]'","/home/main/Projects/scry/src/scry/workspace.cr:33:17 in 'update_file'","/home/main/Projects/scry/src/scry/context.cr:138:7 in 'dispatchNotification'","/home/main/Projects/scry/src/scry/context.cr:39:7 in 'dispatch'","/home/main/Projects/scry/src/scry.cr:23:19 in 'start'","/home/main/Projects/scry/src/scry.cr:40:1 in '__crystal_main'","/usr/lib/crystal/crystal/main.cr:11:3 in '_crystal_main'","/usr/lib/crystal/crystal/main.cr:112:5 in 'main_user_code'","/usr/lib/crystal/crystal/main.cr:101:7 in 'main'","/usr/lib/crystal/crystal/main.cr:135:3 in 'main'","__libc_start_main","_start","???"]}}

I tried to format this code:

screenshot_20180311_085902

I think the problem is somewhere here:

https://github.com/crystal-lang-tools/scry/blob/master/src/scry/workspace.cr#L26

or

https://github.com/crystal-lang-tools/scry/blob/master/src/scry/context.cr#L58

because Untitled files doesn't use a valid path.

/cc @laginha87

@faustinoaq
Copy link
Member Author

I tried to fix this using:

# workspace.cr
if file.untitled?
  @open_files[file.filename] = {file, Completion::MethodDB.new}
else
  file_dependencies = @dependency_graph[file.filename].descendants.map &.value
  method_db = Completion::MethodDB.generate(file_dependencies)
  @open_files[file.filename] = {file, method_db}
end

But scry gets frozen using a lot of CPU and Memory, a hidden loop somewhere? 😅

I guess we would need to modify context.cr as well

@bew
Copy link
Contributor

bew commented Mar 11, 2018

Related to #59 in a way

@laginha87
Copy link
Contributor

@faustinoaq I tried adding your bit of code and it worked well 👍
Saw no issues in cpu or memory

@faustinoaq
Copy link
Member Author

I tried adding your bit of code and it worked well, Saw no issues in cpu or memory

@laginha87 Oh, I tried my fix again on a clean machine and worked successfully, I gonna open a PR now 👍

But scry gets frozen using a lot of CPU and Memory, a hidden loop somewhere?

Looks like my issue about cpu and memory where because I was testing some other code 😅

@faustinoaq
Copy link
Member Author

Fixed definitively by #92

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

No branches or pull requests

3 participants