Skip to content

Commit da4ddec

Browse files
committed
#398 fix didChange at eof
1 parent bf8a629 commit da4ddec

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

script/files.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ function m.offset(uri, position, isFinish)
538538
local start = guide.lineRange(lines, row)
539539
local offset
540540
if start <= 0 or start > #text then
541-
offset = #text + 1
541+
offset = math.maxinteger
542542
else
543543
offset = utf8.offset(text, position.character + 1, start) or #text
544544
end
@@ -572,7 +572,7 @@ function m.offsetOfWord(uri, position)
572572
local start = guide.lineRange(lines, row)
573573
local offset
574574
if start <= 0 or start > #text then
575-
offset = #text + 1
575+
offset = math.maxinteger
576576
else
577577
offset = utf8.offset(text, position.character + 1, start) or #text
578578
end

test.lua

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ local function main()
6161
--config.config.intelliSense.searchDepth = 5
6262
loadDocMetas()
6363

64+
test 'basic'
6465
test 'references'
6566
test 'definition'
6667
test 'type_inference'

test/basic/init.lua

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
local files = require 'files'
2+
3+
local text = [[
4+
5+
6+
function Test(self)
7+
8+
end
9+
]]
10+
files.setText('', text)
11+
12+
local changes = {
13+
[1] = {
14+
range = {
15+
["end"] = {
16+
character = 0,
17+
line = 5,
18+
},
19+
start = {
20+
character = 0,
21+
line = 5,
22+
},
23+
},
24+
rangeLength = 0,
25+
text = "\
26+
",
27+
},
28+
[2] = {
29+
range = {
30+
["end"] = {
31+
character = 0,
32+
line = 6,
33+
},
34+
start = {
35+
character = 0,
36+
line = 6,
37+
},
38+
},
39+
rangeLength = 0,
40+
text = "a",
41+
},
42+
[3] = {
43+
range = {
44+
["end"] = {
45+
character = 1,
46+
line = 6,
47+
},
48+
start = {
49+
character = 1,
50+
line = 6,
51+
},
52+
},
53+
rangeLength = 0,
54+
text = "s",
55+
},
56+
[4] = {
57+
range = {
58+
["end"] = {
59+
character = 2,
60+
line = 6,
61+
},
62+
start = {
63+
character = 2,
64+
line = 6,
65+
},
66+
},
67+
rangeLength = 0,
68+
text = "s",
69+
},
70+
[5] = {
71+
range = {
72+
["end"] = {
73+
character = 3,
74+
line = 6,
75+
},
76+
start = {
77+
character = 3,
78+
line = 6,
79+
},
80+
},
81+
rangeLength = 0,
82+
text = "e",
83+
},
84+
[6] = {
85+
range = {
86+
["end"] = {
87+
character = 4,
88+
line = 6,
89+
},
90+
start = {
91+
character = 4,
92+
line = 6,
93+
},
94+
},
95+
rangeLength = 0,
96+
text = "r",
97+
},
98+
}
99+
100+
for _, change in ipairs(changes) do
101+
if change.range then
102+
local start, finish = files.unrange('', change.range)
103+
text = text:sub(1, start - 1) .. change.text .. text:sub(finish)
104+
else
105+
text = change.text
106+
end
107+
end
108+
109+
assert(text == [[
110+
111+
112+
function Test(self)
113+
114+
end
115+
116+
asser]])

0 commit comments

Comments
 (0)