nwolverson / atom-ide-purescript

Atom package for PureScript build, completion, etc support
https://atom.io/packages/ide-purescript
MIT License
115 stars 17 forks source link

[bug] non-main modules sometimes do not update #101

Open rvion opened 8 years ago

rvion commented 8 years ago

I've been using the ide a lot today, and there is one bug 🐛 I can't figure out.

my Main module import an Input module.

When I write something wrong on my Input module and save the file, no error is shown.

image

image

🔴 no error shown

When I go back to my Main module and hit save, suddenly, the bottom toolbar tells me an error is detected:

image

and indeed, when I go back to my Input module, I see the error:

image

(I'm not 100% sure, but it may have been working a few hours ago. As of now, the bug is present, and restarting the ide server doesn't solve it)

rvion commented 8 years ago

same the other way around: when I fix the error in Input.purs, I need to go to back to Main.purs and save Main for the fix to be detected.

regarding PSCID:

📝 In the same time, the pscid works instantly. I don't need to switch back to Main module for pscid to see the Input module now contains an error

rvion commented 8 years ago

@nwolverson this problem appears to be related to https://github.com/nwolverson/atom-ide-purescript/issues/95

indeed, the file that triggers typechecking upon save has tooltips, but the other hasn't.

How can I help you on this one ?

rvion commented 8 years ago

Hmm...... after https://github.com/nwolverson/atom-ide-purescript/issues/102#issuecomment-232434994, I enabled fast rebuild, quitted Atom (Cmd-Q), restarted it, and now, it seems to be working fine, and both modules correctly typecheck upon save ! ❤️

image

⚠️ (It may just be a coincidence, since I also rebooted my laptop)

nwolverson commented 8 years ago

Seems like you hit some odd case with something in the particular file. If you can reproduce again reliably it might be interesting to see if you were able to share the project.

You're on psc 0.9.2 I think? What you wrote above seems to indicate an issue writing externs with the full compilation but not psc-ide.

rvion commented 8 years ago

if I can reproduce it reproductibly, I'll make a proper report and share a test project, sure !

I'm on psc 0.9.2, yes, on mac el capitan, using atom 1.9.0-beta0

In both my Main and Input module, I was doing some FFI.

It could also be a race condition since I have in the same time running

nwolverson commented 8 years ago

If you can reproduce the effect - even if it just happens rather than understanding the precise steps - the thing to look at would be output/Module.Name/externs.json - is it valid JSON (or corrupted on writing somehow) and if you take a copy does it match what you get normally (when things work).

rvion commented 8 years ago

I just tried one last time without fast-rebuild not to miss a good occasion to see if I had a reproductible test case, but the bug seems to be gone for now even without fast-rebuild. I guess "restarting my laptop" fixed it for now. I'll report any more findings if I encounter the bug.

rvion commented 8 years ago

got it, I'll pay attention to those things from now on

rvion commented 8 years ago

( 📝 edit: see the next message, I also reproduced with fast-rebuild, and wrote down steps leading to the problem)


Got the bug again without falst-rebuild:

the non reloading module is Debug.purs:

Debug.purs:

module Debug where

import Prelude
import Control.Monad.Eff (Eff)
import DOM (DOM)

foreign import p :: forall a eff. a -> Eff (dom :: DOM | eff) Unit

ss
plop
sss
s

Debug.js

"use strict";

exports.p = function(a){return function(){console.log(a)}};

when I save Debug.purs, the pulp --watch build --to test.js process says:

* Source tree changed; restarting:
* Building project in /Users/rvion/dev/psc-b
Error found:
at /Users/rvion/dev/psc-b/src/Debug.purs line 12, column 1 - line 12, column 1

  Unable to parse module:
  unexpected end of input
  expecting binder or indentation

See https://github.com/purescript/purescript/wiki/Error-Code-ErrorParsingModule for more information,
or to contribute content related to this error.

* ERROR: Subcommand terminated with exit code 1

and output/Debug/externs.json contains:

{"efVersion":"0.9.2","efModuleName":["Debug"],"efExports":[{"ValueRef":{"Ident":"p"}}],"efImports":[{"eiModule":["Prim"],"eiImportType":{"Implicit":[]},"eiImportedAs":null},{"eiModule":["Prelude"],"eiImportType":{"Implicit":[]},"eiImportedAs":null},{"eiModule":["Control","Monad","Eff"],"eiImportType":{"Explicit":[{"PositionedDeclarationRef":[{"start":[4,27],"name":"/Users/rvion/dev/psc-b/src/Debug.purs","end":[4,30]},[],{"TypeRef":["Eff",[]]}]}]},"eiImportedAs":null},{"eiModule":["DOM"],"eiImportType":{"Explicit":[{"PositionedDeclarationRef":[{"start":[5,13],"name":"/Users/rvion/dev/psc-b/src/Debug.purs","end":[5,16]},[],{"TypeRef":["DOM",[]]}]}]},"eiImportedAs":null}],"efFixities":[],"efTypeFixities":[],"efDeclarations":[{"EDValue":{"edValueName":{"Ident":"p"},"edValueType":{"tag":"ForAll","contents":["eff",{"tag":"ForAll","contents":["a",{"tag":"TypeApp","contents":[{"tag":"TypeApp","contents":[{"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"tag":"TypeVar","contents":"a"}]},{"tag":"TypeApp","contents":[{"tag":"TypeApp","contents":[{"tag":"TypeConstructor","contents":[["Control","Monad","Eff"],"Eff"]},{"tag":"RCons","contents":["dom",{"tag":"TypeConstructor","contents":[["DOM"],"DOM"]},{"tag":"TypeVar","contents":"eff"}]}]},{"tag":"TypeConstructor","contents":[["Data","Unit"],"Unit"]}]}]},null]},null]}}}]}

formated, it gives :

{
  "efVersion": "0.9.2",
  "efModuleName": [
    "Debug"
  ],
  "efExports": [
    {
      "ValueRef": {
        "Ident": "p"
      }
    }
  ],
  "efImports": [
    {
      "eiModule": [
        "Prim"
      ],
      "eiImportType": {
        "Implicit": []
      },
      "eiImportedAs": null
    },
    {
      "eiModule": [
        "Prelude"
      ],
      "eiImportType": {
        "Implicit": []
      },
      "eiImportedAs": null
    },
    {
      "eiModule": [
        "Control",
        "Monad",
        "Eff"
      ],
      "eiImportType": {
        "Explicit": [
          {
            "PositionedDeclarationRef": [
              {
                "start": [
                  4,
                  27
                ],
                "name": "/Users/rvion/dev/psc-b/src/Debug.purs",
                "end": [
                  4,
                  30
                ]
              },
              [],
              {
                "TypeRef": [
                  "Eff",
                  []
                ]
              }
            ]
          }
        ]
      },
      "eiImportedAs": null
    },
    {
      "eiModule": [
        "DOM"
      ],
      "eiImportType": {
        "Explicit": [
          {
            "PositionedDeclarationRef": [
              {
                "start": [
                  5,
                  13
                ],
                "name": "/Users/rvion/dev/psc-b/src/Debug.purs",
                "end": [
                  5,
                  16
                ]
              },
              [],
              {
                "TypeRef": [
                  "DOM",
                  []
                ]
              }
            ]
          }
        ]
      },
      "eiImportedAs": null
    }
  ],
  "efFixities": [],
  "efTypeFixities": [],
  "efDeclarations": [
    {
      "EDValue": {
        "edValueName": {
          "Ident": "p"
        },
        "edValueType": {
          "tag": "ForAll",
          "contents": [
            "eff",
            {
              "tag": "ForAll",
              "contents": [
                "a",
                {
                  "tag": "TypeApp",
                  "contents": [
                    {
                      "tag": "TypeApp",
                      "contents": [
                        {
                          "tag": "TypeConstructor",
                          "contents": [
                            [
                              "Prim"
                            ],
                            "Function"
                          ]
                        },
                        {
                          "tag": "TypeVar",
                          "contents": "a"
                        }
                      ]
                    },
                    {
                      "tag": "TypeApp",
                      "contents": [
                        {
                          "tag": "TypeApp",
                          "contents": [
                            {
                              "tag": "TypeConstructor",
                              "contents": [
                                [
                                  "Control",
                                  "Monad",
                                  "Eff"
                                ],
                                "Eff"
                              ]
                            },
                            {
                              "tag": "RCons",
                              "contents": [
                                "dom",
                                {
                                  "tag": "TypeConstructor",
                                  "contents": [
                                    [
                                      "DOM"
                                    ],
                                    "DOM"
                                  ]
                                },
                                {
                                  "tag": "TypeVar",
                                  "contents": "eff"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "tag": "TypeConstructor",
                          "contents": [
                            [
                              "Data",
                              "Unit"
                            ],
                            "Unit"
                          ]
                        }
                      ]
                    }
                  ]
                },
                null
              ]
            },
            null
          ]
        }
      }
    }
  ]
}

I'll now enable fast rebuild, and see if the problem pops up in the next hours

rvion commented 8 years ago

🔴 @nwolverson Ok, so I have been able to "reproduce" the problem with fast-rebuild too, and the buggy module doesn't even use FFI

Here is the steps I just did to go from "working sate" to "buggy state":

  1. I had a project compiling
  2. I decided to move some types and data decl from module A to a new module B, for refactoring purpose
  3. I copied the types dans data decls, put them in a new file, added "module B where" at the top, and saved the file as src/B.purs
  4. I added "import B" in module A
  5. 🔶 first anomaly: instead of having erros related to missing imports in B.purs (prelude, Eff, etc.), I only got erros about A not being able to import B, as if B didn't exist.
  6. I fixed import problems, following pscid output instead of relying on atom
  7. after B is fixed, on atom, module A accept to import B, and the projects appears green
  8. 🔴 BUT.. B doesn't typecheck anymore, and when I write buggy stuff in B, it doens't do anything until I hit save in A or in an other module importing B.
rvion commented 8 years ago

and if I quit completely Atom (cmd-Q) and restart it, the problem is temporarily fixed

kritzcreek commented 8 years ago

A cannot know about B until it compiled successfully at least once. We need the externs files loaded inside the server.

I have a feeling that multiple servers writing and watching the same output/ folder might create trouble.

Can you recreate the issue without pscid running?

rvion commented 8 years ago

@kRITZCREEK @nwolverson ok, so I can now replicate the bug all the time.


case 1:

module Eee where

ok :: Int
ok = 3
  1. try to import it from an existing module currently working in atom

🔴 -> it doesn't work. the newly created module is never loaded

restarting the ide-server doesn't work. The only way for ide-atom to be aware of the newly created Eee.purs is to restart Atom completely


case 2:

1.idem: create a new file Eee.purs containing

module Eee where

ok :: Int
ok = 3
  1. try to import it from an existing module currently working in atom

🔶 it fails for the first few seconds, until pulp --watch build --to test.js write stuff in output folder, creating a mixed state. Then, atom still does nothing when Eee.purs is saved, but when on an other module working fine and importing Eee, it correclty sees Eee, and will report errors coming from it (it there is).

Again, restarting the ide-server doesn't do anything, and the only way to get Atom fully aware of the newly created Eee.purs is to restart Atom completely


case 3:

🔴 when I delete a file (let's say C.purs), It still appears in the autocompletion list from other modules


system infos:

$ uname -a
Darwin rvions-MBP 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

$ psc-ide-client --version
0.9.2

$ psc-ide-server --version
0.9.2

$ psc --version
0.9.2

$ pscid --version
1.10.0

atom: 1.9.0-beta0

rvion commented 8 years ago

after one more day of purescript hacking, I can confirm the reproductibility, both with and without fast-loading. (atom + atom-ide-purescript) have a problem with newly created modules, but restarting atom completely solves it until next module addition

nwolverson commented 8 years ago

Case 3 is #105. For the others will try to reproduce, sounds like new files aren't being watched properly.

nwolverson commented 8 years ago

Case 1 seems to work fine for me, maybe I'm missing something.

At this point I can trigger completion from Eee (typing ok in Main.purs), or add and use an import, and build successfully (by saving Main.purs).

rvion commented 8 years ago

@nwolverson forgot to add the last step showing the bug in case 1 x)

now, go in Eee, and write something silly, like

module Eee where

ok :: Int
ok = 3

d 

then hit save: no error message 🔴 (at least on my side)

if I go back to Main with the module Eee still containing the silly code, and hit save, then I'll see the errors from Eee. But while I'm editing Eee, I can write whatever, hit save, and it doesn't reload

starper commented 8 years ago

I have the same problem. Ide doesn't see changes in other modules after fast rebuild. For example if I have modules A and B and module A imports module B, then if I add a function in module B or write something that causes an error, module A doesn't see it. And it happens not from time to time, but all the time. The only workaround is to reopen atom. There is another bug that I found - Ide starts only when you open a file. If you start atom with previous session, then nothing happens.

nwolverson commented 8 years ago

@rvion Just tried this again and still can't reproduce (your new file/Eee issue). Is this still an issue for you? Possibly some recent changes make something work slightly differently.

@starper Not sure if I follow. For sure if I save file B (and it successfully builds) then the changes are reflected in A. If B fails to build, then the previous successful build will be the "last status" until you go fix it (as rebuild operates on a single-file basis). Can you provide some detailed steps to reproduce?

starper commented 8 years ago

Sorry about that "write something that causes an error" thing, I haven't use purescript for month and a half and for some reason I thought that module A could see if imported module B has an error before. My bad. But anyway, there are still two issues left.

Here are my steps (I'll perform a step, then write it down, then perform the next one and so on):

module A where

import Prelude
module B where

import Prelude
import Control.Monad.Eff (Eff)

bar :: forall e. Eff e Unit
bar = pure unit
module A where

import Prelude
import B (bar)
import Control.Monad.Eff (Eff)

foo :: forall e. Eff e Unit
foo = bar
bar :: forall e. Eff e Unit
bar = pure unit
baz :: forall e. Eff e Unit
baz = pure unit
module A where

import Prelude
import B (baz)
import Control.Monad.Eff (Eff)

foo :: forall e. Eff e Unit
foo = baz

So I end up with those two issues that I described before - module A does not see changes in module B and ide does not work until you open some .purs file. Plus an issue with two instances of server running at the same time. I hope it'll help. BTW I use windows 10, atom 1.9.4, purescript 0.9.3 and atom-ide-purescript 0.14.6

nwolverson commented 8 years ago

Thanks for the detailed steps!

I'm trying to follow this, at the step

I do not see that this is the case. I get the correct complaint about bar in

import B (bar)

If this built it would be wrong (can you maybe edit the above post to highlight parts that you believe to be in error?) So everything up until closing atom for the 1st time, works as expected for me. (I'll continue to investigate as I have different versions)

I can reproduce nothing starting when you restart the session, opened #120 (but think this is an Atom regression).

When you say "open some other .purs file" - is that a file within the same project or elsewhere? A separate psc-ide-server will be started if it is in another project

starper commented 8 years ago

.purs file is in the same project, like Main for example. Post is updated.

rvion commented 8 years ago

@nwolverson It is still happening but I need to check if I correctly updated the plugin. my issue is the same as @starper. I found workarounds, so I cal live with it for now :)

nwolverson commented 8 years ago

@starper still can't see anything like the 1st issue, where A.purs builds when it should not. I started with a fresh project created from pulp init, same versions you listed, and followed your steps, this is what I see:

norepro-101

I did notice there is a race condition #121 on starting the package after re-opening the window. I'll ask you to re-test when that is fixed

rvion commented 8 years ago

I'll retest too, since what you show above doesn't work for me

rvion commented 8 years ago

@nwolverson can you tell me what tool you're using use to record screen as gif ?

nwolverson commented 8 years ago

That's LICEcap

(I bet there's one difference that nobody thought to notice that's causing the discrepancy but hard to track down the variables...)

starper commented 8 years ago

Ok, so I was wrong saying that it happens all the time, it's not. Sometimes it works. I tried to find some kind of pattern, because it feels like it happens quite random, but all I can see for now is that it works at first, but then at some point it stops. So you have to mess around with it a little, adding, changing and removing functions until this bug appears. This time I was "lucky" and it failed at the very beginning... tmp

rvion commented 8 years ago

Thanks for the link :)

I noticed that I don't create files the same way you do. I create new files with ctrl-n, followed by ctrl-s, matbe it doesn't trigger events the exact same way? (Cant't test atm, not at home)

starper commented 8 years ago

What I've noticed is that ide sees changes in js files. For example if you have

foreign import fooImpl :: Eff e Unit

but have no fooImpl in js file, there will be an error, but when you add fooImpl, then error is gone. Maybe it'll be helpful :)

starper commented 8 years ago

Maybe something like restart on save option can make it work? (as a temporary workaround)

nwolverson commented 8 years ago

@starper to what end? You should be able to achieve this effect in your init script if that's something you find useful

starper commented 8 years ago

@nwolverson So that people who have this issue do not have to restart editor every time this bug appears. What init script?

nwolverson commented 8 years ago

I think if you have to restart your editor repeatedly like that, something is badly wrong, and it would be better to track it down. I never was able to reproduce this, so it won't be fixed otherwise.

So this still happens. Does the "restart psc-ide-server" command work for you?

Init script is your atom init script, you could for example listen to file saves and run a command.

starper commented 8 years ago

It seems that it is psc-ide-server issue, so restarting it should work, but I can't find any command to do it, so I just restart editor. I guess restart on save option is overkill for this issue, but some keybinding for restarting server would be great.

I just use Atom as editor, I never looked inside of it, so I have very little understanding about what's going on in there.

nwolverson commented 8 years ago

There is a command "Ide Purescript: Restart Psc Ide" you can find in the command palette, the PureScript package submenu. The actual command is ide-purescript:restart-psc-ide which can also be bound to a key (check your key bindings - ~/.atom/keymap.cson)

starper commented 8 years ago

It works, thanks.

starper commented 7 years ago

With the latest purescript-v0.10.3 release everything is back to normal for me. I tried my best to reproduce this error, but everything works just fine now. If @rvion has no errors too, then I guess you can close this issue.

kritzcreek commented 7 years ago

@starper are you on windows by chance? in 0.10.3 the server now uses a polling mechanism as the default on windows.

If someone else is seeing the same failures on other OS's I'd suggest we add a setting to this plugin to enable the polling behavior. See the --polling option https://github.com/purescript/purescript/tree/4c792a12e3e624794be5a775f39434b88a51557c/psc-ide-server.

starper commented 7 years ago

@kRITZCREEK yes, I'm on windows 10.