MCPcopy Index your code
hub / github.com/Macuyiko/minecraft-python / wordDistance

Function wordDistance

ServerEditorWeb/ace/ext-language_tools.js:1714–1733  ·  view source on GitHub ↗
(doc, pos)

Source from the content-addressed store, hash-verified

1712 return textBefore.split(splitRegex).length - 1;
1713 }
1714 function wordDistance(doc, pos) {
1715 var prefixPos = getWordIndex(doc, pos);
1716 var words = doc.getValue().split(splitRegex);
1717 var wordScores = Object.create(null);
1718
1719 var currentWord = words[prefixPos];
1720
1721 words.forEach(function(word, idx) {
1722 if (!word || word === currentWord) return;
1723
1724 var distance = Math.abs(prefixPos - idx);
1725 var score = words.length - distance;
1726 if (wordScores[word]) {
1727 wordScores[word] = Math.max(score, wordScores[word]);
1728 } else {
1729 wordScores[word] = score;
1730 }
1731 });
1732 return wordScores;
1733 }
1734
1735 exports.getCompletions = function(editor, session, pos, prefix, callback) {
1736 var wordScore = wordDistance(session, pos, prefix);

Callers 1

Calls 2

getWordIndexFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected