@@ -37,6 +37,8 @@ function get_text(doc::Document)
3737end
3838
3939function set_text! (doc:: Document , text)
40+ # TODO Remove this check eventually
41+ occursin (' \0 ' , text) && throw (LSInvalidFile (" Tried to set a text with an embedded NULL as the document content." ))
4042 doc. _content = text
4143 doc. _line_offsets = nothing
4244 doc. _line_offsets2 = nothing
@@ -127,7 +129,7 @@ function get_offset2(doc::Document, line::Integer, character::Integer)
127129 pos = nextind (text, pos)
128130 end
129131
130- return pos
132+ return pos
131133end
132134
133135# Note: to be removed
@@ -166,7 +168,7 @@ function get_line_offsets(doc::Document, force=false)
166168 doc. _line_offsets = Int[0 ]
167169 text = get_text (doc)
168170 ind = firstindex (text)
169- while ind <= lastindex (text)
171+ while ind <= lastindex (text)
170172 c = text[ind]
171173 nl = c == ' \n ' || c == ' \r '
172174 if c == ' \r ' && ind + 1 <= lastindex (text) && text[ind + 1 ] == ' \n '
@@ -175,7 +177,7 @@ function get_line_offsets(doc::Document, force=false)
175177 nl && push! (doc. _line_offsets, ind)
176178 ind = nextind (text, ind)
177179 end
178- end
180+ end
179181 return doc. _line_offsets
180182end
181183
@@ -184,7 +186,7 @@ function get_line_offsets2!(doc::Document, force=false)
184186 doc. _line_offsets2 = Int[1 ]
185187 text = get_text (doc)
186188 ind = firstindex (text)
187- while ind <= lastindex (text)
189+ while ind <= lastindex (text)
188190 c = text[ind]
189191 if c == ' \n ' || c == ' \r '
190192 if c == ' \r ' && ind + 1 <= lastindex (text) && text[ind + 1 ] == ' \n '
@@ -212,7 +214,7 @@ function get_line_of(line_offsets::Vector{Int}, offset::Integer)
212214 end
213215 line += 1
214216 end
215- end
217+ end
216218 return line, line_offsets[line]
217219end
218220
@@ -233,7 +235,7 @@ function get_position_at(doc::Document, offset::Integer)
233235 c = read (io, Char)
234236 character += 1
235237 if UInt32 (c) >= 0x010000
236- character += 1
238+ character += 1
237239 end
238240 end
239241 close (io)
0 commit comments