d-language-server / dls

A Language Server implementation for D
http://dls.dub.pm
106 stars 15 forks source link

DLS crashes on incomplete function definition #8

Closed krendil closed 5 years ago

krendil commented 6 years ago

When I open a file with the following contents:

public void newfunction()

I receive the following error in the Output pane:

core.exception.RangeError@C:\Users\appveyor\AppData\Local\dub\packages\libdparse-0.8.8\libdparse\src\dparse\parser.d(7511): Range violation
----------------
0x000000013F67876D
0x000000013F6784C6
0x000000013F670BCC
0x000000013F6628EC
0x000000013F661212
0x000000013F6616DC
0x000000013F4BDC11
0x000000013F4BF123
0x000000013F4BC188
0x000000013F4B1903
0x000000013F4B1633
0x000000013F3EB2C3
0x000000013F3F1057
0x000000013F3F2FB5
0x000000013F37140D
0x000000013F371019
0x000000013F66204D
0x000000013F661EFA
0x000000013F683218
0x0000000076EA59CD in BaseThreadInitThunk
0x000000007710383D in RtlUserThreadStart
[Info  - 9:22:01 PM] Connection to server got closed. Server will restart.
[Error - 9:22:01 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
    at Object.dispose (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-jsonrpc\lib\main.js:825:25)
    at Object.dispose (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-languageclient\lib\client.js:57:35)
    at LanguageClient.handleConnectionClosed (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-languageclient\lib\client.js:2036:42)
    at LanguageClient.handleConnectionClosed (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-languageclient\lib\main.js:153:15)
    at closeHandler (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-languageclient\lib\client.js:2023:18)
    at CallbackList.invoke (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-jsonrpc\lib\events.js:71:39)
    at Emitter.fire (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-jsonrpc\lib\events.js:135:36)
    at closeHandler (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-jsonrpc\lib\main.js:221:26)
    at CallbackList.invoke (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-jsonrpc\lib\events.js:71:39)
    at Emitter.fire (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-jsonrpc\lib\events.js:135:36)
    at StreamMessageWriter.AbstractMessageWriter.fireClose (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-jsonrpc\lib\messageWriter.js:57:27)
    at Socket.<anonymous> (C:\Users\Krendil\.vscode\extensions\laurenttreguier.vscode-dls-1.9.2\node_modules\vscode-jsonrpc\lib\messageWriter.js:79:63)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:554:12)

The error message says it occurs within libdparse, but it didn't fail when I tested libdparse in isolation (by putting the bad file in libdparse/test/bad_file and running the test suite), so I'm raising the issue here instead of at the libdparse repository.

I'm using VS Code 1.26.1 on Windows 7 x64, and DLS plugin 1.9.2.

Here is a copy of the file that causes the errors: badfile.zip

(Also, thanks for your hard work!)

krendil commented 6 years ago

Looks like this was a libdparse error after all, and it was fixed in commit 3830b60. Is it possible to update the libdparse dependency to v0.9.6 or later?

LaurentTreguier commented 6 years ago

Not necessarily, I tested v0.8.8 and it didn't seem to crash when putting badfile.d in the tests for me either, so I might be doing something wrong. I'll investigate when I get back on my workstation.

As for updating libdparse, I'd love to do it, but unfortunately I can't: dfmt still uses libdparse v0.8.x and hasn't been patched to work with the new contracts syntax. Until this is implemented, I can't update anything (except dub). I'd readily do it myself, but for now I don't know enough about dfmt and libdparse work...

LaurentTreguier commented 6 years ago

After a look at dfmt and libdparse, I've submitted a patch to each; I don't know if the dfmt patch is a correct way to do things and can be accepted, but at least things seem to be in motion for updating dfmt.

krendil commented 6 years ago

It turns out run_tests.sh in libdparse doesn't distinguish between parsing errors and parser crashes, so that's why it wasn't showing up in the test suite. If you run tester manually without suppressing the output, you should see the same RangeError stacktrace.

ghost commented 6 years ago

It's fixed in most recent dparse versions. There's been problems due to the additions related to DIP 1009 but they are fixed now. The crash should not occur anymore once DLS will use latest dparse.

LaurentTreguier commented 6 years ago

I'll need to see that dfmt can format UDA's on function parameters so that it can have a proper new release, and update all of dls' dependencies. From what I tested it seems like attributes on enum members were already formatted correctly (I might be wrong on that)

ghost commented 6 years ago

This and enum members attributes. I also think that this could work without change.

LaurentTreguier commented 5 years ago

This should be fixed by now, it doesn't crash for me when trying this, thanks to libdparse being upgraded a few times since the issue was first posted. (Please do re-open if you still experience this)