Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rvion opened this issue Jul 13, 2016 · 40 comments
Open

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

rvion opened this issue Jul 13, 2016 · 40 comments
Labels

Comments

@rvion
Copy link

rvion commented Jul 13, 2016

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
Copy link
Author

rvion commented Jul 13, 2016

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
Copy link
Author

rvion commented Jul 13, 2016

@nwolverson this problem appears to be related to #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
Copy link
Author

rvion commented Jul 13, 2016

Hmm...... after #102 (comment), 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
Copy link
Owner

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
Copy link
Author

rvion commented Jul 13, 2016

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)

@nwolverson
Copy link
Owner

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
Copy link
Author

rvion commented Jul 13, 2016

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
Copy link
Author

rvion commented Jul 13, 2016

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

@rvion
Copy link
Author

rvion commented Jul 13, 2016

( 📝 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
Copy link
Author

rvion commented Jul 13, 2016

🔴 @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
Copy link
Author

rvion commented Jul 13, 2016

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

@kritzcreek
Copy link
Contributor

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
Copy link
Author

rvion commented Jul 13, 2016

@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
Copy link
Author

rvion commented Jul 14, 2016

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 nwolverson added the bug label Jul 14, 2016
@nwolverson
Copy link
Owner

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

@nwolverson
Copy link
Owner

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

@rvion
Copy link
Author

rvion commented Jul 14, 2016

@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
Copy link

starper commented Aug 4, 2016

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
Copy link
Owner

@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
Copy link

starper commented Aug 5, 2016

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

@nwolverson
Copy link
Owner

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

@starper
Copy link

starper commented Aug 5, 2016

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

@rvion
Copy link
Author

rvion commented Aug 5, 2016

@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
Copy link
Owner

@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
Copy link
Author

rvion commented Aug 5, 2016

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

@rvion
Copy link
Author

rvion commented Aug 5, 2016

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

@nwolverson
Copy link
Owner

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
Copy link

starper commented Aug 5, 2016

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
Copy link
Author

rvion commented Aug 5, 2016

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
Copy link

starper commented Aug 15, 2016

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
Copy link

starper commented Oct 6, 2016

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

@nwolverson
Copy link
Owner

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

@starper
Copy link

starper commented Oct 7, 2016

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

@nwolverson
Copy link
Owner

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
Copy link

starper commented Oct 7, 2016

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
Copy link
Owner

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
Copy link

starper commented Oct 7, 2016

It works, thanks.

@starper
Copy link

starper commented Dec 13, 2016

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
Copy link
Contributor

kritzcreek commented Dec 13, 2016

@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
Copy link

starper commented Dec 13, 2016

@kritzcreek yes, I'm on windows 10.

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

No branches or pull requests

4 participants