atom-ide-purescript icon indicating copy to clipboard operation
atom-ide-purescript copied to clipboard

[bug] non-main modules sometimes do not update

Open rvion opened this issue 7 years ago • 40 comments

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 avatar Jul 13 '16 17:07 rvion

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 avatar Jul 13 '16 17:07 rvion

@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 avatar Jul 13 '16 18:07 rvion

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)

rvion avatar Jul 13 '16 18:07 rvion

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.

nwolverson avatar Jul 13 '16 18:07 nwolverson

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

  • pulp --watch build --to test.js (launched manyally)
  • pscid (launched manyally)
  • a psc-ide-server (launched by atom)

rvion avatar Jul 13 '16 18:07 rvion

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).

nwolverson avatar Jul 13 '16 18:07 nwolverson

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 avatar Jul 13 '16 18:07 rvion

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

rvion avatar Jul 13 '16 18:07 rvion

( 📝 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 avatar Jul 13 '16 18:07 rvion

🔴 @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 avatar Jul 13 '16 19:07 rvion

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

rvion avatar Jul 13 '16 19:07 rvion

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?

kritzcreek avatar Jul 13 '16 22:07 kritzcreek

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


case 1:

  • 🚫 nopscid
  • 🚫 no pulp --watch build --to test.js
  • ✔️ atom
  1. as mentioned above, just create a new file Eee.purs containing something like
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:

  • ✔️ pscid
  • ✔️ pulp --watch build --to test.js
  • ✔️ just atom

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 avatar Jul 13 '16 22:07 rvion

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

rvion avatar Jul 14 '16 15:07 rvion

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

nwolverson avatar Jul 14 '16 20:07 nwolverson

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

  • In Atom, create Eee.purs
  • Paste in module content above
  • Save
  • Switch to Main.purs

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).

nwolverson avatar Jul 14 '16 22:07 nwolverson

@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

rvion avatar Jul 14 '16 22:07 rvion

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.

starper avatar Aug 04 '16 13:08 starper

@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?

nwolverson avatar Aug 04 '16 21:08 nwolverson

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):

  • Open atom
  • Create new file A.purs (file is opened in a new tab, ide is started, empty output folder is created, .psc-ide-port file is created)
  • Write this lines in my A.purs file
module A where

import Prelude
  • Save it (now I have an error as expected, because project is not built yet)
  • Build a project with ctrl-o b (using pulp)
  • Error is gone
  • Create a B.purs file with this lines
module B where

import Prelude
import Control.Monad.Eff (Eff)

bar :: forall e. Eff e Unit
bar = pure unit
  • Save it
  • Go to module A and edit it
module A where

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

foo :: forall e. Eff e Unit
foo = bar
  • Save it
  • Go to module B and remove this lines
bar :: forall e. Eff e Unit
bar = pure unit
  • Save it
  • Go to module A and save it (Error: nothing happens it builds with no issues)
  • Go to module B again and add new lines
baz :: forall e. Eff e Unit
baz = pure unit
  • Save it
  • Go to module A and edit it like this
module A where

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

foo :: forall e. Eff e Unit
foo = baz
  • Save it (Error: now I have a Cannot import value baz from module B error)
  • Build it with ctrl-o b (error is gone, no issues now)
  • Save it again (Error: Cannot import value baz from module B error is back)
  • Close atom (.psc-ide-port file is removed)
  • Open it again (Error: it opens with previous sassion, tabs with files A.purs and B.purs are open, ide is not working)
  • Open some other .purs file (now I can see the message that ide is working)
  • Go back to module A and save it (no issues now)
  • Close atom (Error (I guess): .psc-ide-port is not removed)
  • Open atom again (Error: same as before ide is not started)
  • Open some .purs file (Error: now message says that server is started on two different ports and there are two instances of it running)

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

starper avatar Aug 05 '16 07:08 starper

Thanks for the detailed steps!

I'm trying to follow this, at the step

  • Go to module A and save it (nothing happens it builds with no issues)

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

nwolverson avatar Aug 05 '16 08:08 nwolverson

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

starper avatar Aug 05 '16 09:08 starper

@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 :)

rvion avatar Aug 05 '16 09:08 rvion

@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

nwolverson avatar Aug 05 '16 10:08 nwolverson

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

rvion avatar Aug 05 '16 12:08 rvion

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

rvion avatar Aug 05 '16 12:08 rvion

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...)

nwolverson avatar Aug 05 '16 13:08 nwolverson

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

starper avatar Aug 05 '16 13:08 starper

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)

rvion avatar Aug 05 '16 15:08 rvion

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 avatar Aug 15 '16 16:08 starper

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

starper avatar Oct 06 '16 21:10 starper

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

nwolverson avatar Oct 07 '16 19:10 nwolverson

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

starper avatar Oct 07 '16 19:10 starper

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.

nwolverson avatar Oct 07 '16 20:10 nwolverson

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.

starper avatar Oct 07 '16 20:10 starper

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)

nwolverson avatar Oct 07 '16 21:10 nwolverson

It works, thanks.

starper avatar Oct 07 '16 21:10 starper

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.

starper avatar Dec 13 '16 00:12 starper

@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.

kritzcreek avatar Dec 13 '16 00:12 kritzcreek

@kRITZCREEK yes, I'm on windows 10.

starper avatar Dec 13 '16 02:12 starper