haskell / haskell-ide-engine

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

HIE reports invalid file uri on Windows #329

Closed Anrock closed 6 years ago

Anrock commented 6 years ago

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

Anrock commented 6 years ago

@alanz please take a look.

alanz commented 6 years ago

Can you try again with current HIE master?

Anrock commented 6 years ago

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

alanz commented 6 years ago

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

Anrock commented 6 years ago

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.

Anrock commented 6 years ago

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

Anrock commented 6 years ago

@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"}]}}
alanz commented 6 years ago

Ok, thanks.

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

Anrock commented 6 years ago

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.

michael8090 commented 6 years ago

any update here?

alanz commented 6 years ago

I lost track of this, tbh. Sorry.

I will see what I can do this weekend.

Anrock commented 6 years ago

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

Anrock commented 6 years ago

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

Anrock commented 6 years ago

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.

Anrock commented 6 years ago

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

alanz commented 6 years ago

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.

Anrock commented 6 years ago

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

michael8090 commented 6 years ago

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!

alanz commented 6 years ago

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

Anrock commented 6 years ago

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

alanz commented 6 years ago

As expected

nponeccop commented 6 years ago

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:

I'm preparing PRs now

Anrock commented 6 years ago

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

nponeccop commented 6 years ago

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

nponeccop commented 6 years ago

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

Anrock commented 6 years ago

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

nponeccop commented 6 years ago

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.

Anrock commented 6 years ago

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

nponeccop commented 6 years ago

I vote for closing