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

Go to definition doesn't work for functions with doc-strings #91

Closed
alexveden opened this issue Dec 31, 2024 · 7 comments · Fixed by #99
Closed

Go to definition doesn't work for functions with doc-strings #91

alexveden opened this issue Dec 31, 2024 · 7 comments · Fixed by #99

Comments

@alexveden
Copy link

Describe the bug
Go to definition doesn't jump to function in user project space if it has doc string before definition.

To Reproduce
Steps to reproduce the behavior:

// foo.c3
module foo;
 
fn int add(int a, int b){
    return a + b;
}

<*
This is doc (BUG: prevents jump to definition from main.c3)
*>
fn int sub(int a, int b){
    return a - b;
}

//main.c3
module c3_advent;
import std::core::mem;
import foo;

fn int main(String[] args)
{
        // TODO: place cursot at `add` and goto definition (it works)
	int result = foo::add(2, 3);  
        // BUG: place cursot at `sub` and goto definition (doesn't work)
	int r2 = foo::sub(3, 2);

	io::printf("Hello, World! 2+3=%d\n", result);

	return 0;
}

Peek 2024-12-31 12-41

Desktop (please complete the following information):

  • OS: Linux
  • Editor Both VSCode and NeoVim

Additional context
Add any other context about the problem here.

@pherrymason
Copy link
Owner

pherrymason commented Jan 4, 2025

I suspect the culprit are that comment format, which might not be properly parsed by the embeded treesitter inside LSP.
Next LSP version is reworking completely how code is analysed and will include the updated treesitter grammar, but I don't know when it will be finished.

Meanwhile, i could just update the grammar and release a new patch version

@PgBiel
Copy link
Contributor

PgBiel commented Jan 22, 2025

Meanwhile, i could just update the grammar and release a new patch version

This would be very much welcome! I've faced a similar issue but with function autocomplete.

Is there anything we can do to help? I've submitted a similar PR to the C3 zed extension recently (AineeJames/c3-zed#2).

Notably, I updated the grammar to commit c3lang/tree-sitter-c3@10a78fb (a few commits after release 0.2.3) as it seemed to have some relevant improvements related to <* docstring *> parsing.

@pherrymason
Copy link
Owner

If you feel comfortable with go, one should go this route:

  1. Change TREE_SITTER_COMMIT in Makefile to point to the last commit in tree sitter repository
  2. Run make build-parser to rebuild c code for the parser.
  3. Run tests and check what part of server/pkg/parser broke/stop working.

Once tests are passing again, it should be ready.
That being said, I will try and see how many tests break.

@PgBiel
Copy link
Contributor

PgBiel commented Jan 23, 2025

(I had posted something earlier, but turns out I missed an error along the way, so now I got the correct results!)

Indeed, it seems that the following tests fail. Unfortunately, I'm not proficient at Go so I'm not sure I'd be able to make them pass (and/or the exact steps for that), but I'll record them here for posterity. Let me know if you manage to take a stab at it.

Failing tests

?       github.com/pherrymason/c3-lsp/cmd/lsp   [no test files]
?       github.com/pherrymason/c3-lsp/cmd/stdlib_indexer        [no test files]
?       github.com/pherrymason/c3-lsp/internal/c3c      [no test files]
?       github.com/pherrymason/c3-lsp/internal/lsp/context      [no test files]
?       github.com/pherrymason/c3-lsp/internal/lsp/cst  [no test files]
0 : type ::  int :: has errors:  false
---base_type_name int
1 : ident ::  variable :: has errors:  false
2 : = ::  = :: has errors:  false
3 : integer_literal ::  0 :: has errors:  false
4 : ; ::  ; :: has errors:  false
0 : type ::  int :: has errors:  false
---base_type_name int
1 : ident ::  hello :: has errors:  false
2 : = ::  = :: has errors:  false
3 : integer_literal ::  3 :: has errors:  false
4 : ; ::  ; :: has errors:  false
0 : type ::  int :: has errors:  false
---base_type_name int
1 : ident ::  dog :: has errors:  false
2 : , ::  , :: has errors:  false
3 : ident ::  cat :: has errors:  false
4 : , ::  , :: has errors:  false
5 : ident ::  elephant :: has errors:  false
6 : ; ::  ; :: has errors:  false
---base_type_name int
---base_type_name int
---type_ident String
---base_type_name bool
---base_type_name char
--- FAIL: TestConvertToAST_enum_decl_with_associated_params (0.00s)
    convert_declarations_test.go:371: 
                Error Trace:    ./server/internal/lsp/ast/convert_declarations_test.go:371
                Error:          Not equal: 
                                expected: ast.EnumDecl{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x1}, EndPos:ast.Position{Line:0x4, Column:0x2}, Attributes:[]string(nil)}, Name:"State", BaseType:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0xe}, EndPos:ast.Position{Line:0x1, Column:0x11}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0xe}, EndPos:ast.Position{Line:0x1, Column:0x11}, Attributes:[]string(nil)}, Name:"int", Path:""}, Pointer:0x0, Optional:false, BuiltIn:true, Generics:[]ast.TypeInfo(nil)}, Properties:[]ast.EnumProperty{ast.EnumProperty{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x13}, EndPos:ast.Position{Line:0x1, Column:0x1e}, Attributes:[]string(nil)}, Type:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x13}, EndPos:ast.Position{Line:0x1, Column:0x19}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x13}, EndPos:ast.Position{Line:0x1, Column:0x19}, Attributes:[]string(nil)}, Name:"String", Path:""}, Pointer:0x0, Optional:false, BuiltIn:false, Generics:[]ast.TypeInfo(nil)}, Name:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x1a}, EndPos:ast.Position{Line:0x1, Column:0x1e}, Attributes:[]string(nil)}, Name:"desc", Path:""}}, ast.EnumProperty{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x20}, EndPos:ast.Position{Line:0x1, Column:0x2b}, Attributes:[]string(nil)}, Type:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x20}, EndPos:ast.Position{Line:0x1, Column:0x24}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x20}, EndPos:ast.Position{Line:0x1, Column:0x24}, Attributes:[]string(nil)}, Name:"bool", Path:""}, Pointer:0x0, Optional:false, BuiltIn:true, Generics:[]ast.TypeInfo(nil)}, Name:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x25}, EndPos:ast.Position{Line:0x1, Column:0x2b}, Attributes:[]string(nil)}, Name:"active", Path:""}}, ast.EnumProperty{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x2d}, EndPos:ast.Position{Line:0x1, Column:0x34}, Attributes:[]string(nil)}, Type:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x2d}, EndPos:ast.Position{Line:0x1, Column:0x31}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x2d}, EndPos:ast.Position{Line:0x1, Column:0x31}, Attributes:[]string(nil)}, Name:"char", Path:""}, Pointer:0x0, Optional:false, BuiltIn:true, Generics:[]ast.TypeInfo(nil)}, Name:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x32}, EndPos:ast.Position{Line:0x1, Column:0x34}, Attributes:[]string(nil)}, Name:"ke", Path:""}}}, Members:[]ast.EnumMember{ast.EnumMember{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x2, Column:0x2}, EndPos:ast.Position{Line:0x2, Column:0x29}, Attributes:[]string(nil)}, Name:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x2, Column:0x2}, EndPos:ast.Position{Line:0x2, Column:0x9}, Attributes:[]string(nil)}, Name:"PENDING", Path:""}, Value:ast.CompositeLiteral{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x0, Column:0x0}, EndPos:ast.Position{Line:0x0, Column:0x0}, Attributes:[]string(nil)}, Values:[]ast.Expression{ast.Literal{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x0, Column:0x0}, EndPos:ast.Position{Line:0x0, Column:0x0}, Attributes:[]string(nil)}, Value:"\"pending start\""}, ast.BoolLiteral{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x0, Column:0x0}, EndPos:ast.Position{Line:0x0, Column:0x0}, Attributes:[]string(nil)}, Value:false}, ast.Literal{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x0, Column:0x0}, EndPos:ast.Position{Line:0x0, Column:0x0}, Attributes:[]string(nil)}, Value:"'c'"}}}}, ast.EnumMember{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x3, Column:0x2}, EndPos:ast.Position{Line:0x3, Column:0x22}, Attributes:[]string(nil)}, Name:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x3, Column:0x2}, EndPos:ast.Position{Line:0x3, Column:0x9}, Attributes:[]string(nil)}, Name:"RUNNING", Path:""}, Value:ast.CompositeLiteral{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x0, Column:0x0}, EndPos:ast.Position{Line:0x0, Column:0x0}, Attributes:[]string(nil)}, Values:[]ast.Expression{ast.Literal{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x0, Column:0x0}, EndPos:ast.Position{Line:0x0, Column:0x0}, Attributes:[]string(nil)}, Value:"\"running\""}, ast.BoolLiteral{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x0, Column:0x0}, EndPos:ast.Position{Line:0x0, Column:0x0}, Attributes:[]string(nil)}, Value:true}, ast.Literal{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x0, Column:0x0}, EndPos:ast.Position{Line:0x0, Column:0x0}, Attributes:[]string(nil)}, Value:"'e'"}}}}}}
                                actual  : ast.EnumDecl{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x1}, EndPos:ast.Position{Line:0x4, Column:0x2}, Attributes:[]string(nil)}, Name:"State", BaseType:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0xe}, EndPos:ast.Position{Line:0x1, Column:0x11}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0xe}, EndPos:ast.Position{Line:0x1, Column:0x11}, Attributes:[]string(nil)}, Name:"int", Path:""}, Pointer:0x0, Optional:false, BuiltIn:true, Generics:[]ast.TypeInfo(nil)}, Properties:[]ast.EnumProperty{ast.EnumProperty{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x13}, EndPos:ast.Position{Line:0x1, Column:0x1e}, Attributes:[]string(nil)}, Type:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x13}, EndPos:ast.Position{Line:0x1, Column:0x19}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x13}, EndPos:ast.Position{Line:0x1, Column:0x19}, Attributes:[]string(nil)}, Name:"String", Path:""}, Pointer:0x0, Optional:false, BuiltIn:false, Generics:[]ast.TypeInfo(nil)}, Name:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x1a}, EndPos:ast.Position{Line:0x1, Column:0x1e}, Attributes:[]string(nil)}, Name:"desc", Path:""}}, ast.EnumProperty{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x20}, EndPos:ast.Position{Line:0x1, Column:0x2b}, Attributes:[]string(nil)}, Type:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x20}, EndPos:ast.Position{Line:0x1, Column:0x24}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x20}, EndPos:ast.Position{Line:0x1, Column:0x24}, Attributes:[]string(nil)}, Name:"bool", Path:""}, Pointer:0x0, Optional:false, BuiltIn:true, Generics:[]ast.TypeInfo(nil)}, Name:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x25}, EndPos:ast.Position{Line:0x1, Column:0x2b}, Attributes:[]string(nil)}, Name:"active", Path:""}}, ast.EnumProperty{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x2d}, EndPos:ast.Position{Line:0x1, Column:0x34}, Attributes:[]string(nil)}, Type:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x2d}, EndPos:ast.Position{Line:0x1, Column:0x31}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x2d}, EndPos:ast.Position{Line:0x1, Column:0x31}, Attributes:[]string(nil)}, Name:"char", Path:""}, Pointer:0x0, Optional:false, BuiltIn:true, Generics:[]ast.TypeInfo(nil)}, Name:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x1, Column:0x32}, EndPos:ast.Position{Line:0x1, Column:0x34}, Attributes:[]string(nil)}, Name:"ke", Path:""}}}, Members:[]ast.EnumMember{ast.EnumMember{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x2, Column:0x2}, EndPos:ast.Position{Line:0x2, Column:0x29}, Attributes:[]string(nil)}, Name:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x2, Column:0x2}, EndPos:ast.Position{Line:0x2, Column:0x9}, Attributes:[]string(nil)}, Name:"PENDING", Path:""}, Value:ast.CompositeLiteral{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x0, Column:0x0}, EndPos:ast.Position{Line:0x0, Column:0x0}, Attributes:[]string(nil)}, Values:[]ast.Expression(nil)}}, ast.EnumMember{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x3, Column:0x2}, EndPos:ast.Position{Line:0x3, Column:0x22}, Attributes:[]string(nil)}, Name:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x3, Column:0x2}, EndPos:ast.Position{Line:0x3, Column:0x9}, Attributes:[]string(nil)}, Name:"RUNNING", Path:""}, Value:ast.CompositeLiteral{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x0, Column:0x0}, EndPos:ast.Position{Line:0x0, Column:0x0}, Attributes:[]string(nil)}, Values:[]ast.Expression(nil)}}}}
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -271,46 +271,3 @@
                                     },
                                -    Values: ([]ast.Expression) (len=3) {
                                -     (ast.Literal) {
                                -      ASTNodeBase: (ast.ASTNodeBase) {
                                -       StartPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       EndPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       Attributes: ([]string) <nil>
                                -      },
                                -      Value: (string) (len=15) "\"pending start\""
                                -     },
                                -     (ast.BoolLiteral) {
                                -      ASTNodeBase: (ast.ASTNodeBase) {
                                -       StartPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       EndPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       Attributes: ([]string) <nil>
                                -      },
                                -      Value: (bool) false
                                -     },
                                -     (ast.Literal) {
                                -      ASTNodeBase: (ast.ASTNodeBase) {
                                -       StartPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       EndPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       Attributes: ([]string) <nil>
                                -      },
                                -      Value: (string) (len=3) "'c'"
                                -     }
                                -    }
                                +    Values: ([]ast.Expression) <nil>
                                    }
                                @@ -356,46 +313,3 @@
                                     },
                                -    Values: ([]ast.Expression) (len=3) {
                                -     (ast.Literal) {
                                -      ASTNodeBase: (ast.ASTNodeBase) {
                                -       StartPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       EndPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       Attributes: ([]string) <nil>
                                -      },
                                -      Value: (string) (len=9) "\"running\""
                                -     },
                                -     (ast.BoolLiteral) {
                                -      ASTNodeBase: (ast.ASTNodeBase) {
                                -       StartPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       EndPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       Attributes: ([]string) <nil>
                                -      },
                                -      Value: (bool) true
                                -     },
                                -     (ast.Literal) {
                                -      ASTNodeBase: (ast.ASTNodeBase) {
                                -       StartPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       EndPos: (ast.Position) {
                                -        Line: (uint) 0,
                                -        Column: (uint) 0
                                -       },
                                -       Attributes: ([]string) <nil>
                                -      },
                                -      Value: (string) (len=3) "'e'"
                                -     }
                                -    }
                                +    Values: ([]ast.Expression) <nil>
                                    }
                Test:           TestConvertToAST_enum_decl_with_associated_params
1 - int data;
---base_type_name int
2 - char key;
---base_type_name char
3 - raylib::Camera camera;
---module_type_ident raylib::Camera
1 - int data;
---base_type_name int
2 - char key;
---base_type_name char
3 - raylib::Camera camera;
---module_type_ident raylib::Camera
---type_ident UInt16
1 - bitstruct : Register16 @overlap {
                        Register16 bc : 0..15;
                        Register b : 8..15;
                        Register c : 0..7;
                }
---type_ident Register16
2 - Register16 sp;
---type_ident Register16
3 - Register16 pc;
---type_ident Register16
--- FAIL: TestConvertToAST_struct_decl_with_anonymous_bitstructs (0.00s)
    convert_declarations_test.go:473: 
                Error Trace:    ./server/internal/lsp/ast/convert_declarations_test.go:473
                Error:          Not equal: 
                                expected: 5
                                actual  : 2
                Test:           TestConvertToAST_struct_decl_with_anonymous_bitstructs
    convert_declarations_test.go:475: 
                Error Trace:    ./server/internal/lsp/ast/convert_declarations_test.go:475
                Error:          Not equal: 
                                expected: ast.StructMemberDecl{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x4, Column:0x3}, EndPos:ast.Position{Line:0x4, Column:0x19}, Attributes:[]string(nil)}, Names:[]ast.Identifier{ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x4, Column:0xe}, EndPos:ast.Position{Line:0x4, Column:0x10}, Attributes:[]string(nil)}, Name:"bc", Path:""}}, Type:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x4, Column:0x3}, EndPos:ast.Position{Line:0x4, Column:0xd}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x4, Column:0x3}, EndPos:ast.Position{Line:0x4, Column:0xd}, Attributes:[]string(nil)}, Name:"Register16", Path:""}, Pointer:0x0, Optional:false, BuiltIn:false, Generics:[]ast.TypeInfo(nil)}, BitRange:option.Option[[2]uint]{value:[2]uint{0x0, 0xf}, isFull:true}, IsInlined:false}
                                actual  : ast.StructMemberDecl{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x8, Column:0x2}, EndPos:ast.Position{Line:0x8, Column:0x10}, Attributes:[]string(nil)}, Names:[]ast.Identifier{ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x8, Column:0xd}, EndPos:ast.Position{Line:0x8, Column:0xf}, Attributes:[]string(nil)}, Name:"sp", Path:""}}, Type:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x8, Column:0x2}, EndPos:ast.Position{Line:0x8, Column:0xc}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x8, Column:0x2}, EndPos:ast.Position{Line:0x8, Column:0xc}, Attributes:[]string(nil)}, Name:"Register16", Path:""}, Pointer:0x0, Optional:false, BuiltIn:false, Generics:[]ast.TypeInfo(nil)}, BitRange:option.Option[[2]uint]{value:[2]uint{0x0, 0x0}, isFull:false}, IsInlined:false}
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -3,8 +3,8 @@
                                   StartPos: (ast.Position) {
                                -   Line: (uint) 4,
                                -   Column: (uint) 3
                                +   Line: (uint) 8,
                                +   Column: (uint) 2
                                   },
                                   EndPos: (ast.Position) {
                                -   Line: (uint) 4,
                                -   Column: (uint) 25
                                +   Line: (uint) 8,
                                +   Column: (uint) 16
                                   },
                                @@ -16,8 +16,8 @@
                                     StartPos: (ast.Position) {
                                -     Line: (uint) 4,
                                -     Column: (uint) 14
                                +     Line: (uint) 8,
                                +     Column: (uint) 13
                                     },
                                     EndPos: (ast.Position) {
                                -     Line: (uint) 4,
                                -     Column: (uint) 16
                                +     Line: (uint) 8,
                                +     Column: (uint) 15
                                     },
                                @@ -25,3 +25,3 @@
                                    },
                                -   Name: (string) (len=2) "bc",
                                +   Name: (string) (len=2) "sp",
                                    Path: (string) ""
                                @@ -32,8 +32,8 @@
                                    StartPos: (ast.Position) {
                                -    Line: (uint) 4,
                                -    Column: (uint) 3
                                +    Line: (uint) 8,
                                +    Column: (uint) 2
                                    },
                                    EndPos: (ast.Position) {
                                -    Line: (uint) 4,
                                -    Column: (uint) 13
                                +    Line: (uint) 8,
                                +    Column: (uint) 12
                                    },
                                @@ -45,8 +45,8 @@
                                     StartPos: (ast.Position) {
                                -     Line: (uint) 4,
                                -     Column: (uint) 3
                                +     Line: (uint) 8,
                                +     Column: (uint) 2
                                     },
                                     EndPos: (ast.Position) {
                                -     Line: (uint) 4,
                                -     Column: (uint) 13
                                +     Line: (uint) 8,
                                +     Column: (uint) 12
                                     },
                                @@ -65,5 +65,5 @@
                                    (uint) 0,
                                -   (uint) 15
                                +   (uint) 0
                                   },
                                -  isFull: (bool) true
                                +  isFull: (bool) false
                                  },
                Test:           TestConvertToAST_struct_decl_with_anonymous_bitstructs
    convert_declarations_test.go:497: 
                Error Trace:    ./server/internal/lsp/ast/convert_declarations_test.go:497
                Error:          Not equal: 
                                expected: ast.StructMemberDecl{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x5, Column:0x3}, EndPos:ast.Position{Line:0x5, Column:0x16}, Attributes:[]string(nil)}, Names:[]ast.Identifier{ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x5, Column:0xc}, EndPos:ast.Position{Line:0x5, Column:0xd}, Attributes:[]string(nil)}, Name:"b", Path:""}}, Type:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x5, Column:0x3}, EndPos:ast.Position{Line:0x5, Column:0xb}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x5, Column:0x3}, EndPos:ast.Position{Line:0x5, Column:0xb}, Attributes:[]string(nil)}, Name:"Register", Path:""}, Pointer:0x0, Optional:false, BuiltIn:false, Generics:[]ast.TypeInfo(nil)}, BitRange:option.Option[[2]uint]{value:[2]uint{0x8, 0xf}, isFull:true}, IsInlined:false}
                                actual  : ast.StructMemberDecl{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x9, Column:0x2}, EndPos:ast.Position{Line:0x9, Column:0x10}, Attributes:[]string(nil)}, Names:[]ast.Identifier{ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x9, Column:0xd}, EndPos:ast.Position{Line:0x9, Column:0xf}, Attributes:[]string(nil)}, Name:"pc", Path:""}}, Type:ast.TypeInfo{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x9, Column:0x2}, EndPos:ast.Position{Line:0x9, Column:0xc}, Attributes:[]string(nil)}, ResolveStatus:0, Identifier:ast.Identifier{ASTNodeBase:ast.ASTNodeBase{StartPos:ast.Position{Line:0x9, Column:0x2}, EndPos:ast.Position{Line:0x9, Column:0xc}, Attributes:[]string(nil)}, Name:"Register16", Path:""}, Pointer:0x0, Optional:false, BuiltIn:false, Generics:[]ast.TypeInfo(nil)}, BitRange:option.Option[[2]uint]{value:[2]uint{0x0, 0x0}, isFull:false}, IsInlined:false}
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -3,8 +3,8 @@
                                   StartPos: (ast.Position) {
                                -   Line: (uint) 5,
                                -   Column: (uint) 3
                                +   Line: (uint) 9,
                                +   Column: (uint) 2
                                   },
                                   EndPos: (ast.Position) {
                                -   Line: (uint) 5,
                                -   Column: (uint) 22
                                +   Line: (uint) 9,
                                +   Column: (uint) 16
                                   },
                                @@ -16,8 +16,8 @@
                                     StartPos: (ast.Position) {
                                -     Line: (uint) 5,
                                -     Column: (uint) 12
                                +     Line: (uint) 9,
                                +     Column: (uint) 13
                                     },
                                     EndPos: (ast.Position) {
                                -     Line: (uint) 5,
                                -     Column: (uint) 13
                                +     Line: (uint) 9,
                                +     Column: (uint) 15
                                     },
                                @@ -25,3 +25,3 @@
                                    },
                                -   Name: (string) (len=1) "b",
                                +   Name: (string) (len=2) "pc",
                                    Path: (string) ""
                                @@ -32,8 +32,8 @@
                                    StartPos: (ast.Position) {
                                -    Line: (uint) 5,
                                -    Column: (uint) 3
                                +    Line: (uint) 9,
                                +    Column: (uint) 2
                                    },
                                    EndPos: (ast.Position) {
                                -    Line: (uint) 5,
                                -    Column: (uint) 11
                                +    Line: (uint) 9,
                                +    Column: (uint) 12
                                    },
                                @@ -45,8 +45,8 @@
                                     StartPos: (ast.Position) {
                                -     Line: (uint) 5,
                                -     Column: (uint) 3
                                +     Line: (uint) 9,
                                +     Column: (uint) 2
                                     },
                                     EndPos: (ast.Position) {
                                -     Line: (uint) 5,
                                -     Column: (uint) 11
                                +     Line: (uint) 9,
                                +     Column: (uint) 12
                                     },
                                @@ -54,3 +54,3 @@
                                    },
                                -   Name: (string) (len=8) "Register",
                                +   Name: (string) (len=10) "Register16",
                                    Path: (string) ""
                                @@ -64,6 +64,6 @@
                                   value: ([2]uint) (len=2) {
                                -   (uint) 8,
                                -   (uint) 15
                                +   (uint) 0,
                                +   (uint) 0
                                   },
                                -  isFull: (bool) true
                                +  isFull: (bool) false
                                  },
                Test:           TestConvertToAST_struct_decl_with_anonymous_bitstructs
panic: runtime error: index out of range [2] with length 2 [recovered]
        panic: runtime error: index out of range [2] with length 2

goroutine 18 [running]:
testing.tRunner.func1.2({0x6517c0, 0xc000021170})
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1635 +0x35e
panic({0x6517c0?, 0xc000021170?})
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/runtime/panic.go:785 +0x132
github.com/pherrymason/c3-lsp/internal/lsp/ast.TestConvertToAST_struct_decl_with_anonymous_bitstructs(0xc0000ef860)
        ./server/internal/lsp/ast/convert_declarations_test.go:538 +0x2199
testing.tRunner(0xc0000ef860, 0x692258)
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1743 +0x390
FAIL    github.com/pherrymason/c3-lsp/internal/lsp/ast  0.007s
?       github.com/pherrymason/c3-lsp/internal/lsp/protocol     [no test files]
ok      github.com/pherrymason/c3-lsp/internal/lsp/project_state        0.010s
?       github.com/pherrymason/c3-lsp/internal/lsp/server       [no test files]
?       github.com/pherrymason/c3-lsp/internal/lsp/stdlib       [no test files]
?       github.com/pherrymason/c3-lsp/pkg/c3    [no test files]
?       github.com/pherrymason/c3-lsp/pkg/cast  [no test files]
?       github.com/pherrymason/c3-lsp/pkg/data  [no test files]
?       github.com/pherrymason/c3-lsp/pkg/option        [no test files]
--- FAIL: TestLanguage_findClosestSymbolDeclaration_enums (0.01s)
    --- FAIL: TestLanguage_findClosestSymbolDeclaration_enums/Should_find_local_enumerator_definition_associated_value (0.00s)
        search_closest_declaration_test.go:352: 
                Error Trace:    ./server/internal/lsp/search/search_closest_declaration_test.go:352
                Error:          Should be false
                Test:           TestLanguage_findClosestSymbolDeclaration_enums/Should_find_local_enumerator_definition_associated_value
                Messages:       Element not found
panic: cannot get from None type [recovered]
        panic: cannot get from None type

goroutine 121 [running]:
testing.tRunner.func1.2({0xbc2460, 0xe7ce70})
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1635 +0x35e
panic({0xbc2460?, 0xe7ce70?})
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/runtime/panic.go:785 +0x132
github.com/pherrymason/c3-lsp/pkg/option.Option[...].Get(...)
        ./server/pkg/option/option.go:25
github.com/pherrymason/c3-lsp/internal/lsp/search.TestLanguage_findClosestSymbolDeclaration_enums.func4(0xc00026a9c0)
        ./server/internal/lsp/search/search_closest_declaration_test.go:353 +0x33a
testing.tRunner(0xc00026a9c0, 0xc000278420)
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 117
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1743 +0x390
FAIL    github.com/pherrymason/c3-lsp/internal/lsp/search       0.198s
ok      github.com/pherrymason/c3-lsp/internal/lsp/search_params        0.003s
ok      github.com/pherrymason/c3-lsp/internal/lsp/symbol_trie  (cached)
ok      github.com/pherrymason/c3-lsp/pkg/document      0.003s
ok      github.com/pherrymason/c3-lsp/pkg/document/sourcecode   (cached)
ok      github.com/pherrymason/c3-lsp/pkg/fs    (cached)
?       github.com/pherrymason/c3-lsp/pkg/utils [no test files]
--- FAIL: TestParse_struct_with_anonymous_bitstructs (0.00s)
    parse_structs_test.go:201: 
                Error Trace:    ./server/pkg/parser/parse_structs_test.go:201
                Error:          Not equal: 
                                expected: 8
                                actual  : 2
                Test:           TestParse_struct_with_anonymous_bitstructs
    parse_structs_test.go:209: 
                Error Trace:    ./server/pkg/parser/parse_structs_test.go:209
                Error:          Not equal: 
                                expected: "bc"
                                actual  : "sp"
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -bc
                                +sp
                Test:           TestParse_struct_with_anonymous_bitstructs
panic: cannot get from None type [recovered]
        panic: cannot get from None type

goroutine 26 [running]:
testing.tRunner.func1.2({0x652060, 0x716c50})
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1635 +0x35e
panic({0x652060?, 0x716c50?})
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/runtime/panic.go:785 +0x132
github.com/pherrymason/c3-lsp/pkg/option.Option[...].Get(...)
        ./server/pkg/option/option.go:25
github.com/pherrymason/c3-lsp/pkg/symbols.StructMember.GetBitRange(...)
        ./server/pkg/symbols/struct.go:120
github.com/pherrymason/c3-lsp/pkg/parser.TestParse_struct_with_anonymous_bitstructs(0xc00015d520)
        ./server/pkg/parser/parse_structs_test.go:213 +0xbc7
testing.tRunner(0xc00015d520, 0x6d5528)
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
        /nix/store/0b6vsy4fa4i4qpk1011hi6251nwdg5y8-go-1.23.4/share/go/src/testing/testing.go:1743 +0x390
FAIL    github.com/pherrymason/c3-lsp/pkg/parser        0.020s
ok      github.com/pherrymason/c3-lsp/pkg/symbols       (cached)
ok      github.com/pherrymason/c3-lsp/pkg/symbols_table (cached)
FAIL

@PgBiel
Copy link
Contributor

PgBiel commented Jan 23, 2025

Okay, I had a bit of spare time so I took a stab at it, and I managed to make all parser tests pass at least. This involved removing some tests (like pre-0.6 enums) which no longer parse.

However, AST tests are failing because enum members in the form NAME = arg now have arg as any $._expr, not just literals (and, for example, NAME = {1, 2, 3} has {1, 2, 3} as an expression of type "initializer_list"), and it appears that the AST converter doesn't have a simple convert_expr function available, so I stopped here, as that seems to be a larger endeavor.

You can check out my progress at main...PgBiel:c3-lsp:bump-tree-sitter-0.2.3

Let me know if you have any suggestions, or if you'd like to pick it up from here.

EDIT: Notably, I couldn't make the test you introduced at e628c5a pass unless I added a semicolon, since otherwise it's just an error node now I think, i.e. it doesn't parse.

@pherrymason
Copy link
Owner

Great! I will take a look and see how hard it is to adapt. That helps me a lot!

@pherrymason
Copy link
Owner

pherrymason commented Jan 23, 2025

Some improvements on your changes:

  • tests failing in convert_declarations_test.go are not important now. They are work in progress and more complete in the branch search_on_astB. So add t.Skip() in the beggining of them (only on the ones failing)
  • The test you mention in your EDIT, change assert.True(t, ok) by assert.False(t, ok) (parse_struct_test.go line 263).
  • In search_closest_declaration_test.go, on line 337. Change source to:
   enum WindowStatus : int (int counter) {
				OPEN = 1, 
				BACKGROUND = 2, 
				MINIMIZED = 3 
			}
			fn void main() {
				int status = WindowStatus.BACKGROUND.counter;
			}

It had old enum syntax in pre 0.6

With these changes, it passed all tests for me. Please note I could not try it yet.
Feel free to apply these changes and do a PR!

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

Successfully merging a pull request may close this issue.

3 participants