vls icon indicating copy to clipboard operation
vls copied to clipboard

VLS autocompletion for other own modules

Open Sarctiann opened this issue 2 years ago • 5 comments

I have something like this:

root_folder/
  |
  |_ main.v
  |_ my_mod/
    |_ my_mov.v

main.v

module main

import my_mod

// these structs kinda a useless haha
struc Triangle {
    base int
    height int
}

fn (t Triangle) area() {
    return t.base * t.height / 2
}

// ...

fn main() {
    
    tri := Triangle{3, 5}
    sqr := Rectangle{4, 7}

    // Here I to expect get suggestions
    
    tri.//area -> fn (t Triangle ...
        //...

    // When I type:
    sqr.// __         __
        //   \ (o_o) /
        //       V
        //       |
        //     _/ \_
        // Apparently because it's in a different module
}

my_mod/my_mod.v

module my_mod

pub struct Rectangle {
    width int
    height int
}

pub fn (r Rectangle) area() {
    return r.width * r.height
}

// ... and so on... this functions(methods) must be suggested

Sarctiann avatar Apr 25 '22 12:04 Sarctiann

What will happen if you change Rectangle to

pub struct Rectangle {
pub:
    width int
    height int
}

pub fn (r Rectangle) area() {
    return r.width * r.height
}

Krotki avatar Apr 25 '22 17:04 Krotki

i tried both, but don't work. Actually I have as public in my code.. I forget write pub here. I'll correct that

Sarctiann avatar Apr 25 '22 19:04 Sarctiann

suppose i have:

module main

import test

fn main() {
    a := test.Test{4, 5} // this works fine, despite not exposing x and y
    
    a. //-> Here autocompletion suggestion
}

I've tried in Wondows, and seems to work parcially:

Case 1

module test

pub struct Test {
    // pub is commented to hide x and y, compiler builds the struct fine
    // pub:
        x int
        y int
}

pub fn (t Test) test1 () int {
    return 1
} 

// private
fn (t Test) test1 () int {
    return 1
} 

pub fn (t Test) test1 () int {
    return 1
} 

VLS show:

  • test1
  • missing test3

Case 2

module test

...

pub fn (t Test) test1 () int {
    return 1
} 

pub fn (t Test) test1 () int {
    return 1
} 

// private
fn (t Test) test1 () int {
    return 1
} 

VLS show:

  • test1
  • test2

as expected


Later I'll do more tests on Linux

Sarctiann avatar Apr 25 '22 22:04 Sarctiann

yes I was no crazy... In my Linux, doesn't work even if i declare all as public!

I tried it, with 3 different test project...

Then I restarted VLS few times and apparently worked. Because I had declared ALL as public VLS showed me x, y, test1, test2 and test3.

So then I changed the visibility of x, y, and test2. And VLS kept showing me all the staff... So I restarted VLS few more times and restart VSCode but the issue persists.

NOTE: if I try to use a.test2 (which is private), everything seems fine. until I save the file. there VLS shows me the error that test2 is private


In the other 2 projects VLS doesn't showed me nothing... 😢 I even tried change the name of files and folfer, but no...

!

Apparently, the issue is related to the way that I importing the module:

import test ... 
// show me ALL (private and public) 
import test { Test } 
... // shows me nothing

Sarctiann avatar Apr 26 '22 11:04 Sarctiann

@Sarctiann I have just revisited your codes, on the first example it shows fine: image

As for others https://github.com/vlang/vls/commit/34736e18c38c843d7ae5436e1614c91893c19dcc should fix it. (I have yet to fix the symbol import issue)

nedpals avatar Jul 26 '22 15:07 nedpals

Try https://blog.vosca.dev/meet-v-analyzer/ instead, now that it is released.

JalonSolov avatar Jul 03 '23 16:07 JalonSolov