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 and code completion does not work in test files #106

Open
tomialagbe opened this issue May 22, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@tomialagbe
Copy link

Describe the bug

Given a v project with these two files

// src/file_manager.v
pub struct FileManager {
}

pub fn (f FileManager) read_page() {}

// src/file_manager_test.v
fn test_read_page() {
	file_mgr := FileManager{}
	file_mgr.read_page()
}

Expected Behavior

  1. Completion for methods of struct FileManager should be shown
  2. Ctrl/Cmd + Click on a function name should go to the definition of the function.

Current Behavior

  1. There's no completion for the FileManager struct
  2. Cmd+Click does nothing

Reproduction Steps

  1. Create a v project v new <project_name>
  2. two files file_manager.v and file_manager_test.v
  3. copy this code into file_manager.v
// src/file_manager.v
pub struct FileManager {
}

pub fn (f FileManager) read_page() {}

  1. Copy this code into file_manager_test.v
// src/file_manager_test.v
fn test_read_page() {
	file_mgr := FileManager{}
	file_mgr.read_page()
}

Possible Solution

No response

Additional Information/Context

No response

Environment details (v doctor output)

V full version: V 0.4.6 604eb65.7a36b44
OS: macos, macOS, 14.0, 23A344
Processor: 10 cpus, 64bit, little endian, Apple M1 Pro

getwd: /Users/tomialagbe/dev
vexe: /Users/tomialagbe/v/v
vexe mtime: 2024-05-22 18:07:15

vroot: OK, value: /Users/tomialagbe/v
VMODULES: OK, value: /Users/tomialagbe/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.3 (Apple Git-146)
Git vroot status: weekly.2023.32-1929-g7a36b44c-dirty
.git/config present: true

CC version: Apple clang version 15.0.0 (clang-1500.3.9.4)
thirdparty/tcc status: thirdparty-macos-arm64 5c1d002f

Editor name

Vscode

v-analyzer Version

v-analyzer version: 0.0.4-beta.1.7e11a6f

VS Code Extension Version

v0.0.2

@tomialagbe tomialagbe added the bug Something isn't working label May 22, 2024
@spytheman
Copy link
Member

Hi. I think the problem is not directly related to v-analyzer, but to how V treats test files as internal and external ones.

Try changing file_manager_test.v to:

module main

fn test_read_page() {
        file_mgr := FileManager{}
        file_mgr.read_page()
}

The module main at the start is important, so that V will consider the test as an internal one (see the note for internal tests in https://github.com/vlang/v/blob/master/doc/docs.md#test-files).

Without it, the test file is considered to be an entirely separate program, and is compiled without having access to any of the symbols from the other files in src/ (i.e. you would have to import everything that you want to test in it, and you can not import the main module).

You can also try v test . in the src/ folder. It will pass for a _test.v file, that has module main at its top, and will fail, for one that lacks it:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants