aboutsummaryrefslogtreecommitdiff
path: root/src/server/workspace_symbols.odin
blob: abc6837af603db17e0bdc8b51cd8fe3cfbe00bb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package server


import "core:path/filepath"
import "core:os"
import "core:log"
import "core:fmt"

import "shared:common"

@(private)
walk_dir :: proc(
	info: os.File_Info,
	in_err: os.Errno,
	user_data: rawptr,
) -> (
	err: os.Errno,
	skip_dir: bool,
) {
	pkgs := cast(^[dynamic]string)user_data

	if info.is_dir {
		dir, _ := filepath.to_slash(info.fullpath, context.temp_allocator)
		append(pkgs, dir)
	}

	return 0, false
}

get_workspace_symbols :: proc(
	query: string,
) -> (
	workspace_symbols: []WorkspaceSymbol,
	ok: bool,
) {
	workspace := common.config.workspace_folders[0]
	uri := common.parse_uri(workspace.uri, context.temp_allocator) or_return
	pkgs := make([dynamic]string, 0, context.temp_allocator)
	symbols := make([dynamic]WorkspaceSymbol, 0, 100, context.temp_allocator)

	filepath.walk(uri.path, walk_dir, &pkgs)

	for pkg in pkgs {
		matches, err := filepath.glob(
			fmt.tprintf("%v/*.odin", pkg),
			context.temp_allocator,
		)

		if len(matches) == 0 {
			continue
		}

		try_build_package(pkg)

		if results, ok := fuzzy_search(query, {pkg}); ok {
			for result in results {
				symbol := WorkspaceSymbol {
					name = result.symbol.name,
					location = {
						range = result.symbol.range,
						uri = result.symbol.uri,
					},
					kind = symbol_kind_to_type(result.symbol.type),
				}

				append(&symbols, symbol)
			}
		}
	}


	return symbols[:], true
}