pherrymason / c3-lsp

Language Server for C3 Language
https://pherrymason.github.io/c3-lsp/
GNU General Public License v3.0
78 stars 10 forks source link

Misidentifies field as std function #77

Closed Caleb-o closed 2 months ago

Caleb-o commented 2 months ago

Describe the bug Field is misidentified as a std lib function, since it has the same name.

Note: Print seems to have a space before x in its signature.

To Reproduce Steps to reproduce the behavior:

  1. Create a struct
  2. Create a field named print

Expected behavior Show the field information

Screenshots image

Desktop (please complete the following information):

pherrymason commented 2 months ago

@Caleb-o can you provide the full file content where this code is located? I cannot reproduce it in my tests.

Caleb-o commented 2 months ago

I just tried it again. It seems to be in specific cases of nested structures while importing a module:

// Needs to include std::io
import std::io;

struct Foo {
  // Needs to be an inner struct or union
  struct data {
    int print;
  }
}

fn void main() {
  // ...
}
pherrymason commented 2 months ago

Ok, anonymous structs inside structs are not being properly indexed, that's why. Will work on parsing it properly.

How do you write/read print?

Like this?

Foo obj;
obj.data.print = 3;
pherrymason commented 2 months ago

@Caleb-o , just pushed to maina fix to better handle these scenarios. In my tests, hover already displays the proper information.

However, autocompletion is not able to find members of that substruct yet. Working on it.

pherrymason commented 2 months ago

Fixed the autocomplete too.

Caleb-o commented 2 months ago

Ok, anonymous structs inside structs are not being properly indexed, that's why. Will work on parsing it properly.

How do you write/read print?

Like this?

Foo obj;
obj.data.print = 3;

Yeah, that's it

  Foo foo = { { 10 } };
  foo.data.print = 30;
  io::printfn("Print %s", foo.data.print);
Caleb-o commented 2 months ago

This seems to be working now, after pulling the latest changes

pherrymason commented 2 months ago

I'll close then. Feel free to reopen if you find something still not working.