dgethings / lsp-cisco-ios

Language Server for Cisco IOS
3 stars 0 forks source link

LSP Crashing in VSCode #2

Closed EMoonArchiTech closed 3 weeks ago

EMoonArchiTech commented 2 months ago

Hello! Happy to be the first bug report! :)

For reference, I've implemented this lsp server into VSCode. I haven't committed the code anywhere or uploaded the extension but it's more or less working.

Last test I did was about a month ago and it did everything it should have without any issues, but now after pulling the most recent commits I'm getting a few crashes.

This is the content of the file I was testing at the time:

enable password 15 user 9 abc123
enable secret 15 9 abc123

While selecting/highlighting the second row from secret to the end, I got the following crash:

[Info  - 11:20:00 AM] Connection to server got closed. Server will restart.
true
[Error - 11:20:00 AM] Server process exited with code 2.
panic: runtime error: index out of range [0] with length 0

goroutine 19 [running]:
github.com/dgethings/lsp-cisco-ios/lsp/textdocument.selectedWord({0xc0000d0600?, 0xc000022c90?}, 0x1, 0xe)
    C:/Users/XXXXX/Programming/lsp-cisco-ios/lsp/textdocument/hover.go:51 +0x609
github.com/dgethings/lsp-cisco-ios/lsp/textdocument.Hover(0xc000098120?, 0xc0000aa640)
    C:/Users/XXXXX/Programming/lsp-cisco-ios/lsp/textdocument/hover.go:17 +0x108
github.com/tliron/glsp/protocol_3_16.(*Handler).Handle(0xeb9b00, 0xc0000b8fc0)
    C:/Users/XXXXX/go/pkg/mod/github.com/tliron/glsp@v0.2.2/protocol_3_16/handler.go:392 +0xb62
github.com/tliron/glsp/server.(*Server).handle(0xc0000860c0, {0xc7bc08, 0xf3edc0}, 0xc0000ba090, 0xc000086420)
    C:/Users/XXXXX/go/pkg/mod/github.com/tliron/glsp@v0.2.2/server/handle.go:46 +0x276
github.com/sourcegraph/jsonrpc2.(*HandlerWithErrorConfigurer).Handle(0xc00009c160, {0xc7bc08, 0xf3edc0}, 0xc0000ba090, 0xc000086420)
    C:/Users/XXXXX/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/handler_with_error.go:21 +0x57
github.com/sourcegraph/jsonrpc2.(*Conn).readMessages(0xc0000ba090, {0xc7bc08, 0xf3edc0})
    C:/Users/XXXXX/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:205 +0x2dd
created by github.com/sourcegraph/jsonrpc2.NewConn in goroutine 1
    C:/Users/XXXXX/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:62 +0x1e6
[Error - 11:20:07 AM] The Cisco IOS Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 11:20:07 AM] Server process exited with code 2.

And then after restarting I got this second crash after putting my cursor at the end of the second line.

panic: runtime error: index out of range [25] with length 25

goroutine 8 [running]:
github.com/dgethings/lsp-cisco-ios/lsp/textdocument.selectedWord({0xc00000ea00?, 0xc000022c90?}, 0x1, 0x19)
    C:/Users/XXXXX/Programming/lsp-cisco-ios/lsp/textdocument/hover.go:28 +0x60e
github.com/dgethings/lsp-cisco-ios/lsp/textdocument.Hover(0xc000152090?, 0xc00005f2a0)
    C:/Users/XXXXX/Programming/lsp-cisco-ios/lsp/textdocument/hover.go:17 +0x108
github.com/tliron/glsp/protocol_3_16.(*Handler).Handle(0xeb9b00, 0xc000069480)
    C:/Users/XXXXX/go/pkg/mod/github.com/tliron/glsp@v0.2.2/protocol_3_16/handler.go:392 +0xb62
github.com/tliron/glsp/server.(*Server).handle(0xc000032240, {0xc7bc08, 0xf3edc0}, 0xc00011c240, 0xc0000326c0)
    C:/Users/XXXXX/go/pkg/mod/github.com/tliron/glsp@v0.2.2/server/handle.go:46 +0x276
github.com/sourcegraph/jsonrpc2.(*HandlerWithErrorConfigurer).Handle(0xc000028360, {0xc7bc08, 0xf3edc0}, 0xc00011c240, 0xc0000326c0)
    C:/Users/XXXXX/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/handler_with_error.go:21 +0x57
github.com/sourcegraph/jsonrpc2.(*Conn).readMessages(0xc00011c240, {0xc7bc08, 0xf3edc0})
    C:/Users/XXXXX/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:205 +0x2dd
created by github.com/sourcegraph/jsonrpc2.NewConn in goroutine 1
    C:/Users/XXXXX/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:62 +0x1e6
[Info  - 11:22:14 AM] Connection to server got closed. Server will restart.
true
[Error - 11:22:14 AM] Server process exited with code 2.

I hope this isn't just some issue with my own setup, but hope this is helpful in some way :) I'll be following along with this cool project either way!

dgethings commented 1 month ago

wow! Apologies for the delayed reply. I seriously didn't expect anyone else to try and use this yet!

It looks like you've found a bug or two in the selectedWord function. It's purpose is to find the word surrounding the cursor. I'll have to do some research to understand what's going on here. I'll start with your description of how you found the problem and see if I can recreate it.

Still utterly stunned anyone is looking at this. Thanks for the bug report. Please be patient while I work on this. I don't get much free time to work on this project.

dgethings commented 1 month ago

@EMoonArchiTech if you could share the VSCode ext code that would help with my troubleshooting

dgethings commented 1 month ago

ok, I think I am able to replicate the bug. At least I can certainly get it to crash when trying to bring up the docs for some of the keywords. I'm adding unit tests to the helper functions as I think that's where the problem is. I've also found some bugs with the scraper. I'll create a new issue for that.

EMoonArchiTech commented 1 month ago

I'll upload the extension soon but it's not super complicated, 98% of it is from microsoft's LSP sample extension with some modifications to get it to work with this project :)

I actually found the project by googling "cisco ios lsp server" while getting frustrated at editing a bunch of switch configs that I'm deploying for a client :P I think it's a very cool idea and have plenty of thoughts for features or functions. I mainly program at work in python but have been looking for a reason to learn GO, no promises about any commits though :) Completely understand not having a lot of time available and ditto.

If you're looking for inspiration there are two vscode ios extensions that are fairly limited but have some useful features. There's also sublime text's network tech extension that has a lot of really cool features. Not all of which would be able to be implemented purely in an LSP, but cool nonetheless.

dgethings commented 2 weeks ago

Thanks @EMoonArchiTech. I'm happy for any contributions, suggestions, feature requests. I'm hoping to make config management easier. To me the current editor tooling is terrible. I'm hoping to fix it.

I've fixed the crash. But I notice that the autocomplete includes some non-config commands. I've created a new issue to resolve that.

EMoonArchiTech commented 1 week ago

I'm in the complete same mind :) If i hadn't found this project I probably would have tried (and failed!) to do it myself.

I've ran into some other (personal) issues that haven't let me get more into GO but at the very least I'm here cheering from the sidelines and happy to assist with testing!