Skip to content

Commit

Permalink
Fix module index by making sure to index also src/ and modules/ folde…
Browse files Browse the repository at this point in the history
…rs too (#138)
  • Loading branch information
get200 authored Nov 12, 2024
1 parent 6d9c64e commit 379e7fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/analyzer/psi/ModuleClause.v
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -74,6 +84,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(dir, 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
Expand Down
5 changes: 4 additions & 1 deletion src/server/documentation/provider.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 379e7fd

Please sign in to comment.