Haskell-ide-engine: HIE reports invalid file uri on Windows

Created on 11 Oct 2017  路  29Comments  路  Source: haskell/haskell-ide-engine

See https://github.com/autozimu/LanguageClient-neovim/issues/144
Looks like diagnostics from ghcmod are using invalid file path separator.

windows need confirmation

All 29 comments

@alanz please take a look.

Can you try again with current HIE master?

@alanz Master stopped building on Win since 8b9b623 because of unix dep in hie-build-plugin-0.1.0.0
Latest buildable commit: 7f77e7e, issue still present there.

Where is the unix dep? Any idea what is bringing it in?

I have no idea right now.
It looks like haskell tooling doesn't have something to list full dependency tree of package (omg, why?), so the only viable option i see now is to analyze diff of broken commit and find introduced dependency manually.

@alanz found it.
In 8b9b623 you switched from alanz/cabal-helper 94b7ad to DanielG/cabal-helper 4af5dddb
Previous commit of DanielG/cabal-helper 4af5dddb - 4b3571a introduces unix package to use instead of time.

@alanz so i've used local repo of cabal-helper with 4b357a reverted, hie master built fine.
Still file uri is wrong:

17:26:23 DEBUG   [RPC-haskell] <= {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///C:\\Users\\Anrock\\Desktop\\test.hs","diagnostics":[{"severity":1,"range":{"start":{"line":5,"character":8},"end":{"line":5,"character":12}},"source":"ghcmod","message":"Parse error: naked expression at top level\nPerhaps you intended to use TemplateHaskell"}]}}

Ok, thanks.

Can you paste an edited version of what you would be expecting to see?

Can you paste an edited version of what you would be expecting to see?
You mean edited server response? Honestly i have no idea how LSP protocol works.

As far as i understood explanations of @autozimu in autozimu/LanguageClient-neovim#144 and reference urls he posted
offending path is in params.uri

file:///C:\\Users\\Anrock\\Desktop\\test.hs

and it should look like

file:///c:/Users/Anrock/Desktop/test.hs

just like hlint reports it.

any update here?

I lost track of this, tbh. Sorry.

I will see what I can do this weekend.

@alanz so i've managed to build HIE using master DanielG/cabal-helper on Windows (just changed git link and added semigroupoids-5.2.1 to extra-deps in stack.yaml, can make a PR).

Since latest Windows-buildable commit HIE paths had improved!
Was: file:///C:\\Users\\Anrock\\Desktop\\test.hs
Now: file:///c%3A/Users/Anrock/test.hs
Sadly, diagnostics in neovim still don't work :(
I guess that's because of c%3A instead of C:.

Is there somehow i can help? Like if you point me to place where paths are processed maybe i can hack it myself a little bit and make a ugly-but-working PR?

And my little investigation goes on. I've managed to find a place where windows paths are processed:
src/Language/Haskell/LSP/TH/DataTypesJSON.hs in https://gitlab.com/alanz/haskell-lsp.
Looks like this commit added %3a piece, so i replaced it back with : and removed toLower of drive letter. Hlint errors were fixed by that.
Ghc-mod ones still don't work:

01:14:39 INFO    [MainThread] textDocument/didChange
01:14:39 DEBUG   [MainThread] => {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///C:/Users/Anrock/test.hs","version":8},"contentChanges":[{"text":"data D = A | B\n\nf :: Sring -> String\nf = undefined\n"}]}}
01:14:39 DEBUG   [RPC-haskell] <= {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///C:/Users/Anrock/test.hs","diagnostics":[]}}
01:14:39 DEBUG   [MainThread] state.file:///C:/Users/Anrock/test.hs.diagnostics: [] => []
01:14:39 DEBUG   [MainThread] state.file:///C:/Users/Anrock/test.hs.line_diagnostics: {} => {}
01:14:39 DEBUG   [MainThread] state.file:///C:/Users/Anrock/test.hs.signs: [] => []
01:14:39 DEBUG   [RPC-haskell] <= {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///C:/Users/Anrock/AppData/Local/Temp/ghc-mod10861/test633426500.hs","diagnostics":[{"severity":1,"range":{"start":{"line":2,"character":5},"end":{"line":2,"character":10}},"source":"ghcmod","message":"Not in scope: type constructor or class `Sring'\nPerhaps you meant `String' (imported from Prelude)"}]}}
01:14:39 DEBUG   [RPC-haskell] <= {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///C:/Users/Anrock/test.hs","diagnostics":[]}}
01:14:39 DEBUG   [MainThread] state.file:///C:/Users/Anrock/AppData/Local/Temp/ghc-mod10861/test633426500.hs.diagnostics: [{'severity': 1, 'range': {'start': {'line': 2, 'character': 5}, 'end': {'line': 2, 'character': 10}}, 'source': 'ghcmod', 'message': "Not in scope: type constructor or class `Sring'\nPerhaps you meant `String' (imported from Prelude)"}] => [{'severity': 1, 'range': {'start': {'line': 2, 'character': 5}, 'end': {'line': 2, 'character': 10}}, 'source': 'ghcmod', 'message': "Not in scope: type constructor or class `Sring'\nPerhaps you meant `String' (imported from Prelude)"}]
01:14:39 DEBUG   [MainThread] state.file:///C:/Users/Anrock/AppData/Local/Temp/ghc-mod10861/test633426500.hs.line_diagnostics: {2: "[Error] Not in scope: type constructor or class `Sring'\nPerhaps you meant `String' (imported from Prelude)"} => {2: "[Error] Not in scope: type constructor or class `Sring'\nPerhaps you meant `String' (imported from Prelude)"}
01:14:39 DEBUG   [MainThread] state.file:///C:/Users/Anrock/test.hs.diagnostics: [] => []
01:14:39 DEBUG   [MainThread] state.file:///C:/Users/Anrock/test.hs.line_diagnostics: {} => {}
01:14:39 DEBUG   [MainThread] state.file:///C:/Users/Anrock/test.hs.signs: [] => []

Looks like HIE reports temporary file path instead of one being edited in nvim. Now i'm looking for a place wher file path is produced...

Little update.
I've traced temp path source to hie-ghc-mod/Haskell/Ide/GhcModPlugin.hs#setTypeCheckedModule. It cames from GM.getTypecheckedModuleGhc' (myLogger rfm) fp call, which returns a bunch of diagnostic messages for fp (file path, i guess). While fp is correct, diagnostics are returned with uri pointing to temporary file.
Now i'm going to investigate ghc-mod (oh god) to determine if getTypecheckedModuleGhc' does the right thing or not and what GM.mkRevRedirMapFunc does at all. From the name of it and it's enclosing function, mkdRevRedirMapFunc probably somehow related to revMap - mapping between ghc-mod temp files and actual files. And probably it doesn't work.

@alanz i'm kinda stuck.
I think rfm doesn't return mapped file and returns argument as is. And i can't find a way to check this - can't write to hie log from ghc-mod and can't find how to access getMMappedFiles in hie code. Any advice?

I am impressed at your progress with this. I will be updating hie shortly to use the newer cabal-helper, and will take a look at this.

But it is hard for me, not being on windows.

@alanz we can catch up on irc and do a live debugging session, for example

Thanks for your quick response, now it can build on windows!

I've spent the whole weekend on trying to setting up a decent hasekll developing environment on windows for learning the language but with no luck. This is the only thing I feel comfortable to work with. Great job!

But it is still giving the incorrect path in error messages?

@alanz yup, still reporting diagnostics for temporary ghc-mod file instead of actually edited.

As expected

I couldn't reproduce the bug with temporary files. I get a normal uri:

2017-12-04 08:45:52.2278125 [ThreadId 4] - <--2--{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///C:/Users/Andy/dev/haskell-ide-engine/src/Haskell/Ide/Engine/BasePlugin.hs","diagnostics":[{"severity":1,"range":{"start":{"line":28,"character":9},"end":{"line":28,"character":14}},"source":"ghcmod","message":"parse error on input `nName'"},{"severity":1,"range":{"start":{"line":28,"character":9},"end":{"line":28,"character":100000}},"code":"parser","source":"hlint","message":"Parse error: nName\n  baseDescriptor = PluginDescriptor\n    {\n>     plug nName = \"HIE Base\"\n    , pluginDesc = \"Commands for HIE itself\"\n    , pluginCommands =\n\n"}]}}[andy@arch ~]$

However, 2 issues had to be fixed:

  • the %3a bug in DataTypesJSON.hs as described by @Anrock
  • a newer cabal-helper had to be used as the old one choked on CFLib in Main.hs

I'm preparing PRs now

@nponeccop yay! Which cabal-helper (repo, commit) are you using?

See the PR. Also check whether you have build failures in %temp%\LanguageServer.log

Current status of this bug is that we wait for various fixes of @wz1000 to be merged, and then we'll see what to do with https://github.com/alanz/haskell-lsp/pull/63 which fixes this incorrect %3a escaping

@nponeccop could you please list PRs with 'various of @wz1000' so i can track progress on this?

The 'various fixes' (18 commits) have been already merged in https://github.com/haskell/haskell-ide-engine/pull/403

However the https://github.com/alanz/haskell-lsp/pull/63 is still not merged and neither @alanz nor @wz1000 have replied there.

As a workaround for now you can change stack.yaml to use haskell-lsp from that branch instead of from hackage.

@alanz @nponeccop haven't seen this issue in a while. I guess it can be closed.

I vote for closing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hansroland picture hansroland  路  4Comments

alanz picture alanz  路  3Comments

rvion picture rvion  路  3Comments

JorisBlanken picture JorisBlanken  路  4Comments

nponeccop picture nponeccop  路  4Comments