From df6b4ab9fbd8fb37653dabef66b603c8497a9e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=85=8B?= <1023052645@qq.com> Date: Mon, 14 Oct 2024 23:27:39 +0800 Subject: [PATCH 1/2] fix module index when the file is in the 'src' folder --- src/analyzer/psi/ModuleClause.v | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/analyzer/psi/ModuleClause.v b/src/analyzer/psi/ModuleClause.v index 731c0b55..08ef95fe 100644 --- a/src/analyzer/psi/ModuleClause.v +++ b/src/analyzer/psi/ModuleClause.v @@ -74,6 +74,12 @@ pub fn module_qualified_name(file &PsiFile, indexing_root string) string { module_names = module_names[..module_names.len - 1].clone() } + if module_names.len >= 2 && module_names[module_names.len - 1] == 'src' + && module_names[module_names.len - 2] == module_name + && os.is_file(os.join_path(indexing_root, module_names[0..module_names.len - 1].join(os.path_separator), 'v.mod')) { + module_names = module_names[..module_names.len - 2].clone() + } + qualifier := module_names.join('.') if qualifier == '' { return module_name From 088df2834635656ea6e6db7dba3bffd295908c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=85=8B?= <1023052645@qq.com> Date: Mon, 11 Nov 2024 23:14:20 +0800 Subject: [PATCH 2/2] fix module index --- src/analyzer/psi/ModuleClause.v | 12 +++++++++++- src/server/documentation/provider.v | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/analyzer/psi/ModuleClause.v b/src/analyzer/psi/ModuleClause.v index 08ef95fe..f21304d4 100644 --- a/src/analyzer/psi/ModuleClause.v +++ b/src/analyzer/psi/ModuleClause.v @@ -50,6 +50,16 @@ pub fn module_qualified_name(file &PsiFile, indexing_root string) string { root_dirs << src_dir } + root_modules_dir := os.join_path(indexing_root, 'modules') + if os.exists(root_modules_dir) { + root_dirs << root_modules_dir + } + + src_modules_dir := os.join_path(indexing_root, 'src', 'modules') + if os.exists(src_modules_dir) { + root_dirs << src_modules_dir + } + containing_dir := os.dir(file.path) mut module_names := []string{} @@ -76,7 +86,7 @@ pub fn module_qualified_name(file &PsiFile, indexing_root string) string { if module_names.len >= 2 && module_names[module_names.len - 1] == 'src' && module_names[module_names.len - 2] == module_name - && os.is_file(os.join_path(indexing_root, module_names[0..module_names.len - 1].join(os.path_separator), 'v.mod')) { + && os.is_file(os.join_path(dir, module_names[0..module_names.len - 1].join(os.path_separator), 'v.mod')) { module_names = module_names[..module_names.len - 2].clone() } diff --git a/src/server/documentation/provider.v b/src/server/documentation/provider.v index 08a46d84..d52d533d 100644 --- a/src/server/documentation/provider.v +++ b/src/server/documentation/provider.v @@ -113,7 +113,10 @@ fn (mut p Provider) import_spec_documentation(element psi.ImportSpec) ? { p.sb.write_string('```') dir := element.resolve_directory() - readme_path := os.join_path(dir, 'README.md') + mut readme_path := os.join_path(dir, 'README.md') + if !os.exists(readme_path) && os.file_name(dir) == 'src' { + readme_path = os.join_path(os.dir(dir), 'README.md') + } if os.exists(readme_path) { p.write_separator() mut content := os.read_file(readme_path) or { return }