rikvdkleij / intellij-haskell

IntelliJ plugin for Haskell
https://rikvdkleij.github.io/intellij-haskell/
Apache License 2.0
1.31k stars 96 forks source link

Template Haskell, cannot locate file #644

Closed llattila closed 3 years ago

llattila commented 3 years ago

I'm creating a protobuf service with Haskell using the project: https://github.com/higherkindness/mu-haskell. Inside IntelliJ-Haskell, I get the following error:

error: Exception when trying to run compile-time code:
  predictor.proto: openFile: does not exist (No such file or directory)
  Code: grpc "PredictorSchema" id "predictor.proto"

On the command line stack build works as expected. File is located at:

sub-package: ...
sub-package: ...
sub-package/
   predictor.proto
   /src/Haskell-file.hs <--- this contains the grpc line failing

stack.yaml

If I put the whole local path to the file (/home/project/sub-package/predictor.proto), IntelliJ-Haskell recognizes it and removes the error. However, this is not an actual solution after it goes to our GIT. Are there any easy fixes to this issue?

rikvdkleij commented 3 years ago

Is this error during the initial build of the project or later? I mean, the plugin is using the REPL (GHCi) to validate the code.

llattila commented 3 years ago

I think it is later (this Template stuff goes over my head anyways and not sure how this compile magic works :D ) as it reacts very fast to the changes in the file location. It's almost immediate (like 1 second) if I change the file location whether the error appears or disappears. As such, I think it is the REPL validation and not the actual building process.

rikvdkleij commented 3 years ago

Sorry, then I don’t know a solution. If you know how to solve this with stack repl then I can maybe solve this issue in the plugin.

llattila commented 3 years ago

Does the IntelliJ-Haskell plugin call the :r command frequently or how does it handle the building? I can investigate the issue a bit and inform if I can get a more knowledgeable answer on the issue

rikvdkleij commented 3 years ago

It calls mainly :load. Thanks!

llattila commented 3 years ago

If I have understood correctly, the GHCi will use the base folder of the project. As such, when it is trying to locate the proto file, it is one folder deeper. However, stack build will use a different directory when building. Found some related discussions five years ago and the Stack developers mentioned, the problems come from the GHCi interface. I could ask from their support as well, whether there is a solution. For now, I have created a very non-hacky solution by creating a symbolic link in the base folder to my sub-package file which works locally :D

I could update this when I hear something from the Stack guys to see whether things have changed.

llattila commented 3 years ago

Got some good feedback from the guys at FPComplete. They suggested using the following to handle the issue:

https://hackage.haskell.org/package/file-embed-0.0.13.0/docs/Data-FileEmbed.html#v:makeRelativeToProject

This should allow one to properly handle files even if there are multiple packages.