diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-08 19:09:06 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-08 19:09:06 +0800 |
commit | b7217e6433587f7be77660f05f1b0257aeab02c8 (patch) | |
tree | 0ac8b233fa096dbd23854cd72a5cbddc2140f47f /server | |
parent | 9f425d8b8f734d954ad9c7524a00240302b3f037 (diff) | |
download | lua-language-server-b7217e6433587f7be77660f05f1b0257aeab02c8.zip |
修正bug
Diffstat (limited to 'server')
-rw-r--r-- | server/src/parser/lines.lua | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/server/src/parser/lines.lua b/server/src/parser/lines.lua index 2c7d62a6..88966bda 100644 --- a/server/src/parser/lines.lua +++ b/server/src/parser/lines.lua @@ -47,6 +47,7 @@ function mt:position(row, col, code) if row < 1 then return 1 end + code = code or self.code if row > #self then if code == 'utf8' then return utf8_len(self.buf) + 1 @@ -81,7 +82,8 @@ function mt:rowcol(pos, code) if pos < 1 then return 1, 1 end - if pos > #self.buf + 1 then + code = code or self.code + if pos >= #self.buf + 1 then local start = self[#self].start if code == 'utf8' then return #self, utf8_len(self.buf, start) + 1 @@ -92,6 +94,14 @@ function mt:rowcol(pos, code) local min = 1 local max = #self for _ = 1, 100 do + if max == min then + local start = self[min].start + if code == 'utf8' then + return min, utf8_len(self.buf, start, pos) + else + return min, pos - start + 1 + end + end local row = (max - min) // 2 + min local start = self[row].start if pos < start then @@ -105,7 +115,7 @@ function mt:rowcol(pos, code) return row, pos - start + 1 end elseif pos > next_start then - min = row + min = row + 1 else return row + 1, 1 end @@ -128,6 +138,10 @@ function mt:range(i) return self[i].start, self[i].finish end +function mt:set_code(code) + self.code = code +end + return function (self, buf) local lines, err = parser:match(buf) if not lines then |