haskell / haskell-ide-engine

The engine for haskell ide-integration. Not an IDE
BSD 3-Clause "New" or "Revised" License
2.38k stars 213 forks source link

[Win10] Diagnostics are shown only for a split-second #560

Closed Anrock closed 6 years ago

Anrock commented 6 years ago

Full hie log HIE Version 0.2.0.0, Git revision 4e900d53c401c0d3b6f69c6bbddc9ab6c6834d0d (dirty) (1338 commits) x86_64 ghc-8.2.2

I guess here is the issue:

2018-05-10 23:13:36.6195978 [ThreadId 4] - <--2--{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///C%3A/Users/Anrock/Nextcloud/Projects/nand2tetris/projects/hack-translator/Main.hs","diagnostics":[{"severity":1,"range":{"start":{"line":14,"character":61},"end":{"line":14,"character":68}},"source":"ghcmod","message":"Variable not in scope: outName :: FilePath"}]}}
2018-05-10 23:13:36.6195978 [ThreadId 4] - <--2--{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///C:/Users/Anrock/Nextcloud/Projects/nand2tetris/projects/hack-translator/Main.hs","diagnostics":[]}}

Diagnostics are shown due to first message and then almost immediately cleared by second message. Not sure if there any more info needed?

Anrock commented 6 years ago

git bisect shows that 884d1e6ba3308ff1beb6d17dbebdf2b222cea7a4 is first broken commit.

Anrock commented 6 years ago

Not sure why, but it's working again at 2f9f683

Anrock commented 6 years ago

Nope, for some reason first diagnostic upon launch stayed until being fixed. And then it was all the same.

Anrock commented 6 years ago

I have a deja vu, this looks very similar to #329

This is once again an issue somewhere around setTypeCheckedModule function. ((diags', errs), mtm) <- GM.getTypecheckedModuleGhc' (myLogger rfm) fp returns diagnostics for file://C%3A/blabla and next line let diags = Map.insertWith Set.union uri Set.empty diags' inserts empty diagnostics for file://C:/blabla into diagnostics map.

Anrock commented 6 years ago

Probably https://github.com/alanz/haskell-lsp/pull/76 is related. At least it touches semicolon encoding for Windows drives.

Anrock commented 6 years ago

Looks like canonicalizing uri before trying to insert fixes the issue. Not sure if it's a proper solution.

diff --git a/src/Haskell/Ide/Engine/Plugin/GhcMod.hs b/src/Haskell/Ide/Engine/Plugin/GhcMod.
hs
index b5d42b3..ea62f06 100644
--- a/src/Haskell/Ide/Engine/Plugin/GhcMod.hs
+++ b/src/Haskell/Ide/Engine/Plugin/GhcMod.hs
@@ -157,7 +157,8 @@ setTypecheckedModule uri =
     debugm $ "setTypecheckedModule: file mapping state is: " ++ show fileMap
     rfm <- GM.mkRevRedirMapFunc
     ((diags', errs), mtm) <- GM.getTypecheckedModuleGhc' (myLogger rfm) fp
-    let diags = Map.insertWith Set.union uri Set.empty diags'
+    canonUri <- canonicalizeUri uri
+    let diags = Map.insertWith Set.union canonUri Set.empty diags'
     case mtm of
       Nothing -> do
         debugm $ "setTypecheckedModule: Didn't get typechecked module for: " ++ show fp