summaryrefslogtreecommitdiff
path: root/test/tclient/tests/recursive-runner.lua
blob: e824f23a2b6bf4981a815f772ffb0efa6e38660f (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
local lclient   = require 'lclient'
local ws        = require 'workspace'
local await     = require 'await'
local config    = require 'config'
local vm        = require 'vm'
local guide     = require 'parser.guide'
local files     = require 'files'

---@async
lclient():start(function (client)
    client:registerFakers()
    client:initialize()

    config.set(nil, 'Lua.diagnostics.enable', false)

    ws.awaitReady()

    client:notify('textDocument/didOpen', {
        textDocument = {
            uri = 'file:///test.lua',
            languageId = 'lua',
            version = 0,
            text = [[
---@type number
local x

---@type number
local y

x = y

y = x
]]
        }
    })

    await.sleep(0.1)

    local hover1 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 1, character = 7 },
    })

    local hover2 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 8, character = 1 },
    })

    assert(hover1.contents.value:find 'number')
    assert(hover2.contents.value:find 'number')

    client:notify('textDocument/didOpen', {
        textDocument = {
            uri = 'file:///test.lua',
            languageId = 'lua',
            version = 1,
            text = [[
---@type number
local x

---@type number
local y

---@type number
local z

x = y
y = z
z = y
x = y
x = z
z = x
y = x
]]
        }
    })


    await.sleep(0.1)

    local hover1 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 9, character = 0 },
    })

    local hover2 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 10, character = 0 },
    })

    local hover3 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 11, character = 0 },
    })

    local hover4 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 12, character = 0 },
    })

    local hover5 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 13, character = 0 },
    })

    local hover6 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 14, character = 0 },
    })

    local hover7 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 15, character = 0 },
    })

    assert(hover1.contents.value:find 'number')
    assert(hover2.contents.value:find 'number')
    assert(hover3.contents.value:find 'number')
    assert(hover4.contents.value:find 'number')
    assert(hover5.contents.value:find 'number')
    assert(hover6.contents.value:find 'number')
    assert(hover7.contents.value:find 'number')

    client:notify('textDocument/didOpen', {
        textDocument = {
            uri = 'file:///test.lua',
            languageId = 'lua',
            version = 2,
            text = [[
---@meta

---@class vector3
---@operator add(vector3): vector3
---@operator sub(vector3): vector3
---@operator mul(vector3): number
---@operator mul(number):  vector3
---@operator div(number):  vector3
local mt

---@return vector3
function mt:normalize() end

---@param target vector3
function Walk(target)
    local moveSpeed = 1.0
    local deltalTime = 2.0

    ---@type vector3
    local curPos
    local targetDirVec = (target - curPos):normalize()
    local stepMove = targetDirVec * (moveSpeed * deltalTime)
    local nextPos = curPos + stepMove

    curPos = nextPos
end
]]
        }
    })

    local hover1 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 20, character = 11 },
    })
    assert(hover1.contents.value:find 'vector3')

    vm.clearNodeCache()
    local state = files.getState('file:///test.lua')
    assert(state)
    guide.eachSourceType(state.ast, 'call', function (src)
        vm.compileNode(src)
    end)

    local hover1 = client:awaitRequest('textDocument/hover', {
        textDocument = { uri = 'file:///test.lua' },
        position = { line = 20, character = 11 },
    })
    assert(hover1.contents.value:find 'vector3')

    config.set(nil, 'Lua.diagnostics.enable', true)
end)