Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lsp crashes when searching for symbols #53

Closed
tclesius opened this issue Aug 17, 2024 · 4 comments
Closed

Lsp crashes when searching for symbols #53

tclesius opened this issue Aug 17, 2024 · 4 comments

Comments

@tclesius
Copy link

tclesius commented Aug 17, 2024

Bug Description
The LSP server crashes when resolving the dyn symbol in the provided code snippet. The crash happens during symbol resolution, causing repeated server failures and eventual termination.

image

Code Example

import std::collections::map;
import std::io;

def MapFoo = HashMap(<String, String>);

fn void main()
{
    MapFoo foo;
    DString dyn;
    dyn.temp_init();
    dyn.
    dyn.appendf("%s,%s", "foo", "bar");
    String key = dyn.str_view();
    std::io::printfn(key);
    foo[key] = "test";

    HashMap(<String, String>) map;
    map["foo, bar"] = "test";
}

Steps to Reproduce

  1. Create a Project in WSL with c3c init and open the Project with VSCode code .
  2. Write the code as shown above in the main C3 file.
  3. Use Visual Studio Code with tonios2.c3-vscode plugin enabled.
  4. Trigger symbol search or auto-completion in the editor.

Expected Behavior
The LSP server should successfully resolve the symbol dyn and provide relevant code completions or symbol information.

Debug Output

....
2024/08/17 15:47:00.810  DEBUG [C3-LSP.parser] |..... Checking module "_home_tclesius_c3c_testout_src_": mode 2, symbol: DString
2024/08/17 15:47:00.810  DEBUG [C3-LSP.parser] |..... Checking module "http": mode 2, symbol: DString
2024/08/17 15:47:00.810  DEBUG [C3-LSP.parser] |..... Checking module "_home_tclesius_c3c_testout_src_": mode 2, symbol: DString
2024/08/17 15:47:00.810  DEBUG [C3-LSP.parser] |.... end searching symbols in module "std::io::file" file "_stdlib"
2024/08/17 15:47:00.810  DEBUG [C3-LSP.parser] |.. end searching symbols in module "std::collections::map" file "_stdlib"
panic: Could not resolve symbol: dyn

goroutine 12 [running]:
github.com/pherrymason/c3-lsp/internal/lsp/search.(*Search).resolve(0xc000826010, {0xdf8da8, 0xc000a8e500}, {0xc0009a4270, 0x25}, {0xc0009a42d0, 0x1f}, 0xc00019a930, {0xc000a125a0, 0x0, ...}, ...)
	github.com/pherrymason/c3-lsp/internal/lsp/search/find_parent.go:225 +0xae5
github.com/pherrymason/c3-lsp/internal/lsp/search.(*Search).findInParentSymbols(_, {{{0xc000a943a3, 0x3}, {{0xa, 0x4}, {0xa, 0x7}}, {0x0, 0x0, 0x0}, ...}, ...}, ...)
	github.com/pherrymason/c3-lsp/internal/lsp/search/find_parent.go:43 +0x1025
github.com/pherrymason/c3-lsp/internal/lsp/search.(*Search).findParentType(_, {{{0xc000a943a3, 0x3}, {{0xa, 0x4}, {0xa, 0x7}}, {0x0, 0x0, 0x0}, ...}, ...}, ...)
	github.com/pherrymason/c3-lsp/internal/lsp/search/search_completion_list.go:317 +0x7e
github.com/pherrymason/c3-lsp/internal/lsp/search.(*Search).BuildCompletionList(0xc000826010, {0xc0008c4120?, 0xbc1700?}, {0x87?, 0xc00003faf0?}, 0xc00019a930)
	github.com/pherrymason/c3-lsp/internal/lsp/search/search_completion_list.go:194 +0x692
github.com/pherrymason/c3-lsp/internal/lsp/handlers.(*Handlers).TextDocumentCompletion(0xc000826000, 0xc0000fa418?, 0xc0010022a0)
	github.com/pherrymason/c3-lsp/internal/lsp/handlers/TextDocumentCompletion.go:13 +0x4c
github.com/tliron/glsp/protocol_3_16.(*Handler).Handle(0xc0000ea600, 0xc0000a20f0)
	github.com/tliron/glsp@v0.2.3-0.20240511204206-c63625272e79/protocol_3_16/handler.go:372 +0x1768
github.com/tliron/glsp/server.(*Server).handle(0xc000044960, {0xdf67e0, 0xc00019a070}, 0xc0000fa1b0, 0xc0002000c0)
	github.com/tliron/glsp@v0.2.3-0.20240511204206-c63625272e79/server/handler.go:47 +0x28c
github.com/sourcegraph/jsonrpc2.(*HandlerWithErrorConfigurer).Handle(0xc00081ece0, {0xdf67e0, 0xc00019a070}, 0xc0000fa1b0, 0xc0002000c0)
	github.com/sourcegraph/jsonrpc2@v0.2.0/handler_with_error.go:21 +0x57
github.com/sourcegraph/jsonrpc2.(*Conn).readMessages(0xc0000fa1b0, {0xdf67e0, 0xc00019a070})
	github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:205 +0x2dd
created by github.com/sourcegraph/jsonrpc2.NewConn in goroutine 1
	github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:62 +0x1e6
[Error - 3:47:00 PM] The C3LSP server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 3:47:00 PM] Server process exited with code 2.

Desktop:

  • OS: Windows 10 64bit, WSL 2 Ubuntu,
  • Editor: VS Code running in WSL as a Server
  • Version: Latest
@tclesius tclesius changed the title Lsp crashes when searching symbols Lsp crashes when searching for symbols Aug 17, 2024
@tclesius
Copy link
Author

import std::io;
import std::collections::map;

def FooMap = HashMap(<String, String>);

fn void main()
{
    FooMap map;
    DString s = "test";
    map[s.] = "test";

    std::io::printf("test");
}

Debug output:

....
2024/08/17 16:45:09.398  DEBUG [C3-LSP.parser] |... Checking module "url": mode 2, symbol: DString
2024/08/17 16:45:09.398  DEBUG [C3-LSP.parser] |.. end searching symbols in module "std::io::path" file "_stdlib"
panic: Could not resolve symbol: s

goroutine 7 [running]:
github.com/pherrymason/c3-lsp/internal/lsp/search.(*Search).resolve(0xc00088f420, {0xdf8da8, 0xc0007192c0}, {0xc000918450, 0x25}, {0xc0009184b0, 0x1f}, 0xc0001a8930, {0xc000d0a5a0, 0x0, ...}, ...)
	github.com/pherrymason/c3-lsp/internal/lsp/search/find_parent.go:225 +0xae5
github.com/pherrymason/c3-lsp/internal/lsp/search.(*Search).findInParentSymbols(_, {{{0xc000bd2169, 0x1}, {{0x9, 0x8}, {0x9, 0x9}}, {0x0, 0x0, 0x0}, ...}, ...}, ...)
	github.com/pherrymason/c3-lsp/internal/lsp/search/find_parent.go:43 +0x1025
github.com/pherrymason/c3-lsp/internal/lsp/search.(*Search).findParentType(_, {{{0xc000bd2169, 0x1}, {{0x9, 0x8}, {0x9, 0x9}}, {0x0, 0x0, 0x0}, ...}, ...}, ...)
	github.com/pherrymason/c3-lsp/internal/lsp/search/search_completion_list.go:317 +0x7e
github.com/pherrymason/c3-lsp/internal/lsp/search.(*Search).BuildCompletionList(0xc00088f420, {0xc00013d0e0?, 0xbc1700?}, {0x87?, 0xc000bcdaf0?}, 0xc0001a8930)
	github.com/pherrymason/c3-lsp/internal/lsp/search/search_completion_list.go:194 +0x692
github.com/pherrymason/c3-lsp/internal/lsp/handlers.(*Handlers).TextDocumentCompletion(0xc00088f410, 0xc000188418?, 0xc000c77110)
	github.com/pherrymason/c3-lsp/internal/lsp/handlers/TextDocumentCompletion.go:13 +0x4c
github.com/tliron/glsp/protocol_3_16.(*Handler).Handle(0xc000176600, 0xc000cf4050)
	github.com/tliron/glsp@v0.2.3-0.20240511204206-c63625272e79/protocol_3_16/handler.go:372 +0x1768
github.com/tliron/glsp/server.(*Server).handle(0xc000114960, {0xdf67e0, 0xc0001a8070}, 0xc0001881b0, 0xc000114180)
	github.com/tliron/glsp@v0.2.3-0.20240511204206-c63625272e79/server/handler.go:47 +0x28c
github.com/sourcegraph/jsonrpc2.(*HandlerWithErrorConfigurer).Handle(0xc000881800, {0xdf67e0, 0xc0001a8070}, 0xc0001881b0, 0xc000114180)
	github.com/sourcegraph/jsonrpc2@v0.2.0/handler_with_error.go:21 +0x57
github.com/sourcegraph/jsonrpc2.(*Conn).readMessages(0xc0001881b0, {0xdf67e0, 0xc0001a8070})
	github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:205 +0x2dd
created by github.com/sourcegraph/jsonrpc2.NewConn in goroutine 1
	github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:62 +0x1e6
[Info  - 4:45:09 PM] Connection to server got closed. Server will restart.
true
[Error - 4:45:09 PM] Server process exited with code 2.
2024/08/17 16:45:09.407  DEBUG [C3-LSP.parser] Sending crash reports
2024/08/17 16:45:09.422   NOTE [C3-LSP] reading from stdin, writing to stdout
....

As seen above, attempting to autocomplete s. also results in a crash.

@tclesius
Copy link
Author

I think this is a duplicate of #29.

@pherrymason pherrymason reopened this Aug 17, 2024
@pherrymason
Copy link
Owner

pherrymason commented Aug 17, 2024

I'm not completely sure, I've just pushed a fix (#6d40684) to at least not to crash if symbol was not found.
However, I'm not completely sure why is not finding DString. I need to debug more.

@pherrymason
Copy link
Owner

Ok, I think I've found the issue with DString.

DString is a distinct, and currently the LSP is ignoring those definitions. Will close this an open a new Issue describing that.
Thank you for your report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants