aboutsummaryrefslogtreecommitdiff
path: root/src/server/document_links.odin
blob: 17113fffce4f8fb933b2d177b2a45ad32ba16ea2 (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
package server

import "core:odin/parser"
import "core:odin/ast"
import "core:odin/tokenizer"
import "core:fmt"
import "core:log"
import "core:strings"
import path "core:path/slashpath"
import "core:mem"
import "core:strconv"
import "core:path/filepath"
import "core:sort"
import "core:slice"
import "core:os"


import "shared:common"

get_document_links :: proc(document: ^Document) -> ([]DocumentLink, bool) {
	links := make([dynamic]DocumentLink, 0, context.temp_allocator)

	for imp in document.ast.imports {
		if len(imp.relpath.text) <= 1 {
			continue
		}

		e := strings.split(
			imp.relpath.text[1:len(imp.relpath.text) - 1],
			":",
			context.temp_allocator,
		)

		if len(e) != 2 {
			continue
		}

		if e[0] != "core" {
			continue
		}

		//Temporarly assuming non unicode
		node := ast.Node {
			pos = {
				offset = imp.relpath.pos.offset + 1,
				column = imp.relpath.pos.column + 1,
				line = imp.relpath.pos.line,
			},
			end = {
				offset = imp.relpath.pos.offset + len(imp.relpath.text) - 1,
				column = imp.relpath.pos.column + len(imp.relpath.text) - 1,
				line = imp.relpath.pos.line,
			},
		}

		range := common.get_token_range(node, string(document.text))

		link := DocumentLink {
			range   = range,
			target  = fmt.tprintf(
				"https://pkg.odin-lang.org/%v/%v",
				e[0],
				e[1],
			),
			tooltip = "Documentation",
		}

		append(&links, link)
	}

	return links[:], true
}