Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Improved auto-completion : support utf-8 #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions worker/go_completer.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ function getOffset(doc, pos) {
if (i === pos.row)
return result + pos.column;

result += lines[i].length + 1;
result += lengthInUtf8(lines[i]) + 1;
}
}

function lengthInUtf8(str) {
var asciiLength = str.match(/[\u0000-\u007f]/g) ? str.match(/[\u0000-\u007f]/g).length : 0;
var multiByteLength = encodeURI(str.replace(/[\u0000-\u007f]/g)).match(/%/g) ? encodeURI(str.replace(/[\u0000-\u007f]/g, '')).match(/%/g).length : 0;
return asciiLength + multiByteLength;
}
handler.predictNextCompletion = function(doc, fullAst, pos, options, callback) {
if (!options.matches.length) {
// Normally we wouldn't complete here, maybe we can complete for the next char?
Expand Down Expand Up @@ -192,4 +196,4 @@ function ensureDaemon(callback) {
}
}

});
});