UNPKG

vim-language-server

Version:
1,322 lines (1,244 loc) 713 kB
/******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 68: /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { /* colors.js Copyright (c) 2010 Marak Squires Alexis Sellier (cloudhead) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ var isHeadless = false; if (typeof module !== 'undefined') { isHeadless = true; } if (!isHeadless) { var exports = {}; var module = {}; var colors = exports; exports.mode = "browser"; } else { exports.mode = "console"; } // // Prototypes the string object to have additional method calls that add terminal colors // var addProperty = function (color, func) { exports[color] = function (str) { return func.apply(str); }; String.prototype.__defineGetter__(color, func); }; function stylize(str, style) { var styles; if (exports.mode === 'console') { styles = { //styles 'bold' : ['\x1B[1m', '\x1B[22m'], 'italic' : ['\x1B[3m', '\x1B[23m'], 'underline' : ['\x1B[4m', '\x1B[24m'], 'inverse' : ['\x1B[7m', '\x1B[27m'], 'strikethrough' : ['\x1B[9m', '\x1B[29m'], //text colors //grayscale 'white' : ['\x1B[37m', '\x1B[39m'], 'grey' : ['\x1B[90m', '\x1B[39m'], 'black' : ['\x1B[30m', '\x1B[39m'], //colors 'blue' : ['\x1B[34m', '\x1B[39m'], 'cyan' : ['\x1B[36m', '\x1B[39m'], 'green' : ['\x1B[32m', '\x1B[39m'], 'magenta' : ['\x1B[35m', '\x1B[39m'], 'red' : ['\x1B[31m', '\x1B[39m'], 'yellow' : ['\x1B[33m', '\x1B[39m'], //background colors //grayscale 'whiteBG' : ['\x1B[47m', '\x1B[49m'], 'greyBG' : ['\x1B[49;5;8m', '\x1B[49m'], 'blackBG' : ['\x1B[40m', '\x1B[49m'], //colors 'blueBG' : ['\x1B[44m', '\x1B[49m'], 'cyanBG' : ['\x1B[46m', '\x1B[49m'], 'greenBG' : ['\x1B[42m', '\x1B[49m'], 'magentaBG' : ['\x1B[45m', '\x1B[49m'], 'redBG' : ['\x1B[41m', '\x1B[49m'], 'yellowBG' : ['\x1B[43m', '\x1B[49m'] }; } else if (exports.mode === 'browser') { styles = { //styles 'bold' : ['<b>', '</b>'], 'italic' : ['<i>', '</i>'], 'underline' : ['<u>', '</u>'], 'inverse' : ['<span style="background-color:black;color:white;">', '</span>'], 'strikethrough' : ['<del>', '</del>'], //text colors //grayscale 'white' : ['<span style="color:white;">', '</span>'], 'grey' : ['<span style="color:gray;">', '</span>'], 'black' : ['<span style="color:black;">', '</span>'], //colors 'blue' : ['<span style="color:blue;">', '</span>'], 'cyan' : ['<span style="color:cyan;">', '</span>'], 'green' : ['<span style="color:green;">', '</span>'], 'magenta' : ['<span style="color:magenta;">', '</span>'], 'red' : ['<span style="color:red;">', '</span>'], 'yellow' : ['<span style="color:yellow;">', '</span>'], //background colors //grayscale 'whiteBG' : ['<span style="background-color:white;">', '</span>'], 'greyBG' : ['<span style="background-color:gray;">', '</span>'], 'blackBG' : ['<span style="background-color:black;">', '</span>'], //colors 'blueBG' : ['<span style="background-color:blue;">', '</span>'], 'cyanBG' : ['<span style="background-color:cyan;">', '</span>'], 'greenBG' : ['<span style="background-color:green;">', '</span>'], 'magentaBG' : ['<span style="background-color:magenta;">', '</span>'], 'redBG' : ['<span style="background-color:red;">', '</span>'], 'yellowBG' : ['<span style="background-color:yellow;">', '</span>'] }; } else if (exports.mode === 'none') { return str + ''; } else { console.log('unsupported mode, try "browser", "console" or "none"'); } return styles[style][0] + str + styles[style][1]; } function applyTheme(theme) { // // Remark: This is a list of methods that exist // on String that you should not overwrite. // var stringPrototypeBlacklist = [ '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt', 'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight' ]; Object.keys(theme).forEach(function (prop) { if (stringPrototypeBlacklist.indexOf(prop) !== -1) { console.log('warn: '.red + ('String.prototype' + prop).magenta + ' is probably something you don\'t want to override. Ignoring style name'); } else { if (typeof(theme[prop]) === 'string') { addProperty(prop, function () { return exports[theme[prop]](this); }); } else { addProperty(prop, function () { var ret = this; for (var t = 0; t < theme[prop].length; t++) { ret = exports[theme[prop][t]](ret); } return ret; }); } } }); } // // Iterate through all default styles and colors // var x = ['bold', 'underline', 'strikethrough', 'italic', 'inverse', 'grey', 'black', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta', 'greyBG', 'blackBG', 'yellowBG', 'redBG', 'greenBG', 'blueBG', 'whiteBG', 'cyanBG', 'magentaBG']; x.forEach(function (style) { // __defineGetter__ at the least works in more browsers // http://robertnyman.com/javascript/javascript-getters-setters.html // Object.defineProperty only works in Chrome addProperty(style, function () { return stylize(this, style); }); }); function sequencer(map) { return function () { if (!isHeadless) { return this.replace(/( )/, '$1'); } var exploded = this.split(""), i = 0; exploded = exploded.map(map); return exploded.join(""); }; } var rainbowMap = (function () { var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta']; //RoY G BiV return function (letter, i, exploded) { if (letter === " ") { return letter; } else { return stylize(letter, rainbowColors[i++ % rainbowColors.length]); } }; })(); exports.themes = {}; exports.addSequencer = function (name, map) { addProperty(name, sequencer(map)); }; exports.addSequencer('rainbow', rainbowMap); exports.addSequencer('zebra', function (letter, i, exploded) { return i % 2 === 0 ? letter : letter.inverse; }); exports.setTheme = function (theme) { if (typeof theme === 'string') { try { exports.themes[theme] = __webpack_require__(69)(theme); applyTheme(exports.themes[theme]); return exports.themes[theme]; } catch (err) { console.log(err); return err; } } else { applyTheme(theme); } }; addProperty('stripColors', function () { return ("" + this).replace(/\x1B\[\d+m/g, ''); }); // please no function zalgo(text, options) { var soul = { "up" : [ '̍', '̎', '̄', '̅', '̿', '̑', '̆', '̐', '͒', '͗', '͑', '̇', '̈', '̊', '͂', '̓', '̈', '͊', '͋', '͌', '̃', '̂', '̌', '͐', '̀', '́', '̋', '̏', '̒', '̓', '̔', '̽', '̉', 'ͣ', 'ͤ', 'ͥ', 'ͦ', 'ͧ', 'ͨ', 'ͩ', 'ͪ', 'ͫ', 'ͬ', 'ͭ', 'ͮ', 'ͯ', '̾', '͛', '͆', '̚' ], "down" : [ '̖', '̗', '̘', '̙', '̜', '̝', '̞', '̟', '̠', '̤', '̥', '̦', '̩', '̪', '̫', '̬', '̭', '̮', '̯', '̰', '̱', '̲', '̳', '̹', '̺', '̻', '̼', 'ͅ', '͇', '͈', '͉', '͍', '͎', '͓', '͔', '͕', '͖', '͙', '͚', '̣' ], "mid" : [ '̕', '̛', '̀', '́', '͘', '̡', '̢', '̧', '̨', '̴', '̵', '̶', '͜', '͝', '͞', '͟', '͠', '͢', '̸', '̷', '͡', ' ҉' ] }, all = [].concat(soul.up, soul.down, soul.mid), zalgo = {}; function randomNumber(range) { var r = Math.floor(Math.random() * range); return r; } function is_char(character) { var bool = false; all.filter(function (i) { bool = (i === character); }); return bool; } function heComes(text, options) { var result = '', counts, l; options = options || {}; options["up"] = options["up"] || true; options["mid"] = options["mid"] || true; options["down"] = options["down"] || true; options["size"] = options["size"] || "maxi"; text = text.split(''); for (l in text) { if (is_char(l)) { continue; } result = result + text[l]; counts = {"up" : 0, "down" : 0, "mid" : 0}; switch (options.size) { case 'mini': counts.up = randomNumber(8); counts.min = randomNumber(2); counts.down = randomNumber(8); break; case 'maxi': counts.up = randomNumber(16) + 3; counts.min = randomNumber(4) + 1; counts.down = randomNumber(64) + 3; break; default: counts.up = randomNumber(8) + 1; counts.mid = randomNumber(6) / 2; counts.down = randomNumber(8) + 1; break; } var arr = ["up", "mid", "down"]; for (var d in arr) { var index = arr[d]; for (var i = 0 ; i <= counts[index]; i++) { if (options[index]) { result = result + soul[index][randomNumber(soul[index].length)]; } } } } return result; } return heComes(text); } // don't summon zalgo addProperty('zalgo', function () { return zalgo(this); }); /***/ }), /***/ 69: /***/ ((module) => { function webpackEmptyContext(req) { var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } webpackEmptyContext.keys = () => ([]); webpackEmptyContext.resolve = webpackEmptyContext; webpackEmptyContext.id = 69; module.exports = webpackEmptyContext; /***/ }), /***/ 67: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { var fs = __webpack_require__(60), Path = __webpack_require__(23), util = __webpack_require__(10), colors = __webpack_require__(68), EE = __webpack_require__(70).EventEmitter, fsExists = fs.exists ? fs.exists : Path.exists, fsExistsSync = fs.existsSync ? fs.existsSync : Path.existsSync; module.exports = function(dir, iterator, options, callback){ return FindUp(dir, iterator, options, callback); }; function FindUp(dir, iterator, options, callback){ if (!(this instanceof FindUp)) { return new FindUp(dir, iterator, options, callback); } if(typeof options === 'function'){ callback = options; options = {}; } options = options || {}; EE.call(this); this.found = false; this.stopPlease = false; var self = this; if(typeof iterator === 'string'){ var file = iterator; iterator = function(dir, cb){ return fsExists(Path.join(dir, file), cb); }; } if(callback) { this.on('found', function(dir){ if(options.verbose) console.log(('found '+ dir ).green); callback(null, dir); self.stop(); }); this.on('end', function(){ if(options.verbose) console.log('end'.grey); if(!self.found) callback(new Error('not found')); }); this.on('error', function(err){ if(options.verbose) console.log('error'.red, err); callback(err); }); } this._find(dir, iterator, options, callback); } util.inherits(FindUp, EE); FindUp.prototype._find = function(dir, iterator, options, callback){ var self = this; iterator(dir, function(exists){ if(options.verbose) console.log(('traverse '+ dir).grey); if(exists) { self.found = true; self.emit('found', dir); } var parentDir = Path.join(dir, '..'); if (self.stopPlease) return self.emit('end'); if (dir === parentDir) return self.emit('end'); if(dir.indexOf('../../') !== -1 ) return self.emit('error', new Error(dir + ' is not correct.')); self._find(parentDir, iterator, options, callback); }); }; FindUp.prototype.stop = function(){ this.stopPlease = true; }; module.exports.FindUp = FindUp; module.exports.sync = function(dir, iteratorSync){ if(typeof iteratorSync === 'string'){ var file = iteratorSync; iteratorSync = function(dir){ return fsExistsSync(Path.join(dir, file)); }; } var initialDir = dir; while(dir !== Path.join(dir, '..')){ if(dir.indexOf('../../') !== -1 ) throw new Error(initialDir + ' is not correct.'); if(iteratorSync(dir)) return dir; dir = Path.join(dir, '..'); } throw new Error('not found'); }; /***/ }), /***/ 64: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.projectRootPatterns = exports.sortTexts = void 0; exports.sortTexts = { one: "00001", two: "00002", three: "00003", four: "00004", }; exports.projectRootPatterns = [".git", "autoload", "plugin"]; /***/ }), /***/ 72: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.notIdentifierPattern = exports.expandPattern = exports.featurePattern = exports.commandPattern = exports.notFunctionPattern = exports.optionPattern = exports.builtinVariablePattern = exports.funcArgIdentifierPattern = exports.localIdentifierPattern = exports.scriptIdentifierPattern = exports.normalIdentifierPattern = exports.globalIdentifierPattern = exports.autocmdPattern = exports.highlightValuePattern = exports.highlightPattern = exports.highlightLinkPattern = exports.mapCommandPattern = exports.colorschemePattern = exports.wordNextPattern = exports.wordPrePattern = exports.builtinFunctionPattern = exports.keywordPattern = exports.commentPattern = exports.errorLinePattern = void 0; exports.errorLinePattern = /[^:]+:\s*(.+?):\s*line\s*([0-9]+)\s*col\s*([0-9]+)/; exports.commentPattern = /^[ \t]*("|')/; exports.keywordPattern = /[\w#&$<>.:]/; exports.builtinFunctionPattern = /^((<SID>|\b(v|g|b|s|l|a):)?[\w#&]+)[ \t]*\([^)]*\)/; exports.wordPrePattern = /^.*?(((<SID>|\b(v|g|b|s|l|a):)?[\w#&$.]+)|(<SID>|<SID|<SI|<S|<|\b(v|g|b|s|l|a):))$/; exports.wordNextPattern = /^((SID>|ID>|D>|>|<SID>|\b(v|g|b|s|l|a):)?[\w#&$.]+|(:[\w#&$.]+)).*?(\r\n|\r|\n)?$/; exports.colorschemePattern = /\bcolorscheme[ \t]+\w*$/; exports.mapCommandPattern = /^([ \t]*(\[ \t]*)?)\w*map[ \t]+/; exports.highlightLinkPattern = /^[ \t]*(hi|highlight)[ \t]+link([ \t]+[^ \t]+)*[ \t]*$/; exports.highlightPattern = /^[ \t]*(hi|highlight)([ \t]+[^ \t]+)*[ \t]*$/; exports.highlightValuePattern = /^[ \t]*(hi|highlight)([ \t]+[^ \t]+)*[ \t]+([^ \t=]+)=[^ \t=]*$/; exports.autocmdPattern = /^[ \t]*(au|autocmd)!?[ \t]+([^ \t,]+,)*[^ \t,]*$/; exports.globalIdentifierPattern = /^((g|b):\w+(\.\w+)*|(\w+#)+\w*)$/; exports.normalIdentifierPattern = /^([a-zA-Z_]\w*(\.\w+)*)$/; exports.scriptIdentifierPattern = /^((s:|<SID>)\w+(\.\w+)*)$/; exports.localIdentifierPattern = /^(l:\w+(\.\w+)*)$/; exports.funcArgIdentifierPattern = /^(a:\w+(\.\w+)*)$/; exports.builtinVariablePattern = [ /\bv:\w*$/, ]; exports.optionPattern = [ /(^|[ \t]+)&\w*$/, /(^|[ \t]+)set(l|local|g|global)?[ \t]+\w+$/, ]; exports.notFunctionPattern = [ /^[ \t]*\\$/, /^[ \t]*\w+$/, /^[ \t]*"/, /(let|set|colorscheme)[ \t][^ \t]*$/, /[^([,\\ \t\w#>]\w*$/, /^[ \t]*(hi|highlight)([ \t]+link)?([ \t]+[^ \t]+)*[ \t]*$/, exports.autocmdPattern, ]; exports.commandPattern = [ /(^|[ \t]):\w+$/, /^[ \t]*\w+$/, /:?silent!?[ \t]\w+/, ]; exports.featurePattern = [ /\bhas\([ \t]*["']\w*/, ]; exports.expandPattern = [ /\bexpand\(['"]<\w*$/, /\bexpand\([ \t]*['"]\w*$/, ]; exports.notIdentifierPattern = [ exports.commentPattern, /("|'):\w*$/, /^[ \t]*\\$/, /^[ \t]*call[ \t]+[^ \t()]*$/, /('|"|#|&|\$|<)\w*$/, ]; /***/ }), /***/ 66: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __spreadArray = (this && this.__spreadArray) || function (to, from) { for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i]; return to; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _a; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.delay = exports.getRealPath = exports.isSymbolLink = exports.removeSnippets = exports.handleParse = exports.getWordFromPosition = exports.markupSnippets = exports.findProjectRoot = exports.pcb = exports.executeFile = exports.isSomeMatchPattern = void 0; var child_process_1 = __webpack_require__(61); var findup_1 = __importDefault(__webpack_require__(67)); var fs_1 = __importDefault(__webpack_require__(60)); var path_1 = __importDefault(__webpack_require__(23)); var vscode_languageserver_1 = __webpack_require__(2); var vimparser_1 = __webpack_require__(71); var patterns_1 = __webpack_require__(72); var config_1 = __importDefault(__webpack_require__(73)); // FIXME vimlparser missing update builtin_commands if (vimparser_1.VimLParser.prototype) { (_a = vimparser_1.VimLParser.prototype.builtin_commands) === null || _a === void 0 ? void 0 : _a.push({ name: 'balt', minlen: 4, flags: 'NEEDARG|FILE1|EDITCMD|TRLBAR|CMDWIN', parser: 'parse_cmd_common' }); } function isSomeMatchPattern(patterns, line) { return patterns.some(function (p) { return p.test(line); }); } exports.isSomeMatchPattern = isSomeMatchPattern; function executeFile(input, command, args, option) { return new Promise(function (resolve, reject) { var stdout = ""; var stderr = ""; var error; var isPassAsText = false; args = (args || []).map(function (arg) { if (/%text/.test(arg)) { isPassAsText = true; return arg.replace(/%text/g, input.toString()); } return arg; }); var cp = child_process_1.spawn(command, args, option); cp.stdout.on("data", function (data) { stdout += data; }); cp.stderr.on("data", function (data) { stderr += data; }); cp.on("error", function (err) { error = err; reject(error); }); cp.on("close", function (code) { if (!error) { resolve({ code: code, stdout: stdout, stderr: stderr }); } }); // error will occur when cp get error if (!isPassAsText) { input.pipe(cp.stdin).on("error", function () { return; }); } }); } exports.executeFile = executeFile; // cover cb type async function to promise function pcb(cb) { return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return new Promise(function (resolve) { cb.apply(void 0, __spreadArray(__spreadArray([], args), [function () { var params = []; for (var _i = 0; _i < arguments.length; _i++) { params[_i] = arguments[_i]; } resolve(params); }])); }); }; } exports.pcb = pcb; // find work dirname by root patterns function findProjectRoot(filePath, rootPatterns) { return __awaiter(this, void 0, void 0, function () { var dirname, patterns, dirCandidate, _i, patterns_2, pattern, _a, err, dir; return __generator(this, function (_b) { switch (_b.label) { case 0: dirname = path_1.default.dirname(filePath); patterns = [].concat(rootPatterns); dirCandidate = ""; _i = 0, patterns_2 = patterns; _b.label = 1; case 1: if (!(_i < patterns_2.length)) return [3 /*break*/, 4]; pattern = patterns_2[_i]; return [4 /*yield*/, pcb(findup_1.default)(dirname, pattern)]; case 2: _a = _b.sent(), err = _a[0], dir = _a[1]; if (!err && dir && dir !== "/" && dir.length > dirCandidate.length) { dirCandidate = dir; } _b.label = 3; case 3: _i++; return [3 /*break*/, 1]; case 4: if (dirCandidate.length) { return [2 /*return*/, dirCandidate]; } return [2 /*return*/, dirname]; } }); }); } exports.findProjectRoot = findProjectRoot; function markupSnippets(snippets) { return [ "```vim", snippets.replace(/\$\{[0-9]+(:([^}]+))?\}/g, "$2"), "```", ].join("\n"); } exports.markupSnippets = markupSnippets; function getWordFromPosition(doc, position) { if (!doc) { return; } // invalid character which less than 0 if (position.character < 0) { return; } var character = doc.getText(vscode_languageserver_1.Range.create(vscode_languageserver_1.Position.create(position.line, position.character), vscode_languageserver_1.Position.create(position.line, position.character + 1))); // not keyword position if (!character || !patterns_1.keywordPattern.test(character)) { return; } var currentLine = doc.getText(vscode_languageserver_1.Range.create(vscode_languageserver_1.Position.create(position.line, 0), vscode_languageserver_1.Position.create(position.line + 1, 0))); // comment line if (patterns_1.commentPattern.test(currentLine)) { return; } var preSegment = currentLine.slice(0, position.character); var nextSegment = currentLine.slice(position.character); var wordLeft = preSegment.match(patterns_1.wordPrePattern); var wordRight = nextSegment.match(patterns_1.wordNextPattern); var word = "" + (wordLeft && wordLeft[1] || "") + (wordRight && wordRight[1] || ""); return { word: word, left: wordLeft && wordLeft[1] || "", right: wordRight && wordRight[1] || "", wordLeft: wordLeft && wordLeft[1] ? preSegment.replace(new RegExp(wordLeft[1] + "$"), word) : "" + preSegment + word, wordRight: wordRight && wordRight[1] ? nextSegment.replace(new RegExp("^" + wordRight[1]), word) : "" + word + nextSegment, }; } exports.getWordFromPosition = getWordFromPosition; // parse vim buffer function handleParse(textDoc) { return __awaiter(this, void 0, void 0, function () { var text, tokens, node; return __generator(this, function (_a) { text = textDoc instanceof Object ? textDoc.getText() : textDoc; tokens = new vimparser_1.StringReader(text.split(/\r\n|\r|\n/)); try { node = new vimparser_1.VimLParser(config_1.default.isNeovim).parse(tokens); return [2 /*return*/, [node, ""]]; } catch (error) { return [2 /*return*/, [null, error]]; } return [2 /*return*/]; }); }); } exports.handleParse = handleParse; // remove snippets of completionItem function removeSnippets(completionItems) { if (completionItems === void 0) { completionItems = []; } return completionItems.map(function (item) { if (item.insertTextFormat === vscode_languageserver_1.InsertTextFormat.Snippet) { return __assign(__assign({}, item), { insertText: item.label, insertTextFormat: vscode_languageserver_1.InsertTextFormat.PlainText }); } return item; }); } exports.removeSnippets = removeSnippets; var isSymbolLink = function (filePath) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve) { fs_1.default.lstat(filePath, function (err, stats) { resolve({ err: err, stats: stats && stats.isSymbolicLink(), }); }); })]; }); }); }; exports.isSymbolLink = isSymbolLink; var getRealPath = function (filePath) { return __awaiter(void 0, void 0, void 0, function () { var _a, err, stats; return __generator(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, exports.isSymbolLink(filePath)]; case 1: _a = _b.sent(), err = _a.err, stats = _a.stats; if (!err && stats) { return [2 /*return*/, new Promise(function (resolve) { fs_1.default.realpath(filePath, function (error, realPath) { if (error) { return resolve(filePath); } resolve(realPath); }); })]; } return [2 /*return*/, filePath]; } }); }); }; exports.getRealPath = getRealPath; var delay = function (ms) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, new Promise(function (res) { setTimeout(function () { res(); }, ms); })]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; exports.delay = delay; /***/ }), /***/ 391: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", ({ value: true })); /* * vim builtin completion items * * 1. functions * 2. options * 3. variables * 4. commands * 5. has features * 6. expand Keyword */ var fs_1 = __webpack_require__(60); var path_1 = __webpack_require__(23); var vscode_languageserver_1 = __webpack_require__(2); var constant_1 = __webpack_require__(64); var util_1 = __webpack_require__(66); var EVAL_PATH = "/doc/eval.txt"; var OPTIONS_PATH = "/doc/options.txt"; var INDEX_PATH = "/doc/index.txt"; var API_PATH = "/doc/api.txt"; var AUTOCMD_PATH = "/doc/autocmd.txt"; var POPUP_PATH = "/doc/popup.txt"; var CHANNEL_PATH = "/doc/channel.txt"; var TEXTPROP_PATH = "/doc/textprop.txt"; var TERMINAL_PATH = "/doc/terminal.txt"; var TESTING_PATH = "/doc/testing.txt"; var Server = /** @class */ (function () { function Server(config) { this.config = config; // completion items this.vimPredefinedVariablesItems = []; this.vimOptionItems = []; this.vimBuiltinFunctionItems = []; this.vimCommandItems = []; this.vimFeatureItems = []; this.vimExpandKeywordItems = []; this.vimAutocmdItems = []; // documents this.vimBuiltFunctionDocuments = {}; this.vimOptionDocuments = {}; this.vimPredefinedVariableDocuments = {}; this.vimCommandDocuments = {}; this.vimFeatureDocuments = {}; this.expandKeywordDocuments = {}; // signature help this.vimBuiltFunctionSignatureHelp = {}; // raw docs this.text = {}; } Server.prototype.build = function () { return __awaiter(this, void 0, void 0, function () { var vimruntime, paths, index, p, _a, err, data; return __generator(this, function (_b) { switch (_b.label) { case 0: vimruntime = this.config.vimruntime; if (!vimruntime) return [3 /*break*/, 5]; paths = [ EVAL_PATH, OPTIONS_PATH, INDEX_PATH, API_PATH, AUTOCMD_PATH, POPUP_PATH, CHANNEL_PATH, TEXTPROP_PATH, TERMINAL_PATH, TESTING_PATH, ]; index = 0; _b.label = 1; case 1: if (!(index < paths.length)) return [3 /*break*/, 4]; p = path_1.join(vimruntime, paths[index]); return [4 /*yield*/, util_1.pcb(fs_1.readFile)(p, "utf-8")]; case 2: _a = _b.sent(), err = _a[0], data = _a[1]; if (err) { // tslint:disable-next-line: no-console console.error("[vimls]: read " + p + " error: " + err.message); } this.text[paths[index]] = (data && data.toString().split("\n")) || []; _b.label = 3; case 3: index++; return [3 /*break*/, 1]; case 4: this.resolveVimPredefinedVariables(); this.resolveVimOptions(); this.resolveBuiltinFunctions(); this.resolveBuiltinFunctionsDocument(); this.resolveBuiltinVimPopupFunctionsDocument(); this.resolveBuiltinVimChannelFunctionsDocument(); this.resolveBuiltinVimJobFunctionsDocument(); this.resolveBuiltinVimTextpropFunctionsDocument(); this.resolveBuiltinVimTerminalFunctionsDocument(); this.resolveBuiltinVimTestingFunctionsDocument(); this.resolveBuiltinNvimFunctions(); this.resolveExpandKeywords(); this.resolveVimCommands(); this.resolveVimFeatures(); this.resolveVimAutocmds(); _b.label = 5; case 5: return [2 /*return*/]; } }); }); }; Server.prototype.serialize = function () { var str = JSON.stringify({ completionItems: { commands: this.vimCommandItems, functions: this.vimBuiltinFunctionItems, variables: this.vimPredefinedVariablesItems, options: this.vimOptionItems, features: this.vimFeatureItems, expandKeywords: this.vimExpandKeywordItems, autocmds: this.vimAutocmdItems, }, signatureHelp: this.vimBuiltFunctionSignatureHelp, documents: { commands: this.vimCommandDocuments, functions: this.vimBuiltFunctionDocuments, variables: this.vimPredefinedVariableDocuments, options: this.vimOptionDocuments, features: this.vimFeatureDocuments, expandKeywords: this.expandKeywordDocuments, }, }, null, 2); fs_1.writeFileSync("./src/docs/builtin-docs.json", str, "utf-8"); }; Server.prototype.formatFunctionSnippets = function (fname, snippets) { if (snippets === "") { return fname + "(${0})"; } var idx = 0; if (/^\[.+\]/.test(snippets)) { return fname + "(${1})${0}"; } var str = snippets.split("[")[0].trim().replace(/\{?(\w+)\}?/g, function (m, g1) { return "${" + (idx += 1) + ":" + g1 + "}"; }); return fname + "(" + str + ")${0}"; }; // get vim predefined variables from vim document eval.txt Server.prototype.resolveVimPredefinedVariables = function () { var evalText = this.text[EVAL_PATH] || []; var isMatchLine = false; var completionItem; for (var _i = 0, evalText_1 = evalText; _i < evalText_1.length; _i++) { var line = evalText_1[_i]; if (!isMatchLine) { if (/\*vim-variable\*/.test(line)) { isMatchLine = true; } continue; } else { var m = line.match(/^(v:[^ \t]+)[ \t]+([^ ].*)$/); if (m) { if (completionItem) { this.vimPredefinedVariablesItems.push(completionItem); this.vimPredefinedVariableDocuments[completionItem.label].pop(); completionItem = undefined; } var label = m[1]; completionItem = { label: label, kind: vscode_languageserver_1.CompletionItemKind.Variable, sortText: constant_1.sortTexts.four, insertText: label.slice(2), insertTextFormat: vscode_languageserver_1.InsertTextFormat.PlainText, }; if (!this.vimPredefinedVariableDocuments[label]) { this.vimPredefinedVariableDocuments[label] = []; } this.vimPredefinedVariableDocuments[label].push(m[2]); } else if (/^\s*$/.test(line) && completionItem) { this.vimPredefinedVariablesItems.push(completionItem); completionItem = undefined; } else if (completionItem) { this.vimPredefinedVariableDocuments[completionItem.label].push(line); } else if (/===============/.test(line)) { break; } } } }; // get vim options from vim document options.txt Server.prototype.resolveVimOptions = function () { var optionsText = this.text[OPTIONS_PATH] || []; var isMatchLine = false; var completionItem; for (var _i = 0, optionsText_1 = optionsText; _i < optionsText_1.length; _i++) { var line = optionsText_1[_i]; if (!isMatchLine) { if (/\*'aleph'\*/.test(line)) { isMatchLine = true; } continue; } else { var m = line.match(/^'([^']+)'[ \t]+('[^']+')?[ \t]+([^ \t].*)$/); if (m) { var label = m[1]; completionItem = { label: label, kind: vscode_languageserver_1.CompletionItemKind.Property, detail: m[3].trim().split(/[ \t]/)[0], documentation: "", sortText: "00004", insertText: m[1], insertTextFormat: vscode_languageserver_1.InsertTextFormat.PlainText, }; if (!this.vimOptionDocuments[label]) { this.vimOptionDocuments[label] = []; } this.vimOptionDocuments[label].push(m[3]); } else if (/^\s*$/.test(line) && completionItem) { this.vimOptionItems.push(completionItem); completionItem = undefined; } else if (completionItem) { this.vimOptionDocuments[completionItem.label].push(line); } } } }; // get vim builtin function from document eval.txt Server.prototype.resolveBuiltinFunctions = function () { var evalText = this.text[EVAL_PATH] || []; var isMatchLine = false; var completionItem; for (var _i = 0, evalText_2 = evalText; _i < evalText_2.length; _i++) { var line = evalText_2[_i]; if (!isMatchLine) { if (/\*functions\*/.test(line)) { isMatchLine = true; } continue; } else { var m = line.match(/^((\w+)\(([^)]*)\))[ \t]*([^ \t].*)?$/); if (m) { if (completionItem) { this.vimBuiltinFunctionItems.push(completionItem); } var label = m[2]; completionItem = { label: label, kind: vscode_languageserver_1.CompletionItemKind.Function, detail: (m[4] || "").split(/[ \t]/)[0], sortText: "00004", insertText: this.formatFunctionSnippets(m[2], m[3]), insertTextFormat: vscode_languageserver_1.InsertTextFormat.Snippet, }; this.vimBuiltFunctionSignatureHelp[label] = [ m[3], (m[4] || "").split(/[ \t]/)[0], ]; } else if (/^[ \t]*$/.test(line)) { if (completionItem) { this.vimBuiltinFunctionItems.push(completionItem); completionItem = undefined; break; } } else if (completionItem) { if (completionItem.detail === "") { completionItem.detail = line.trim().split(/[ \t]/)[0]; if (this.vimBuiltFunctionSignatureHelp[completionItem.label]) { this.vimBuiltFunctionSignatureHelp[completionItem.label][1] = line.trim().split(/[ \t]/)[0]; } } } } } }; Server.prototype.resolveBuiltinFunctionsDocument = function () { var evalText = this.text[EVAL_PATH] || []; var isMatchLine = false; var label = ""; for (var idx = 0; idx < evalText.length; idx++) { var line = evalText[idx]; if (!isMatchLine) { if (/\*abs\(\)\*/.test(line)) { isMatchLine = true; idx -= 1; } continue; } else { var m = line.match(/^((\w+)\(([^)]*)\))[ \t]*([^ \t].*)?$/); if (m) { if (label) { this.vimBuiltFunctionDocuments[label].pop(); } label = m[2]; if (!this.vimBuiltFunctionDocuments[label]) { this.vimBuiltFunctionDocuments[label] = []; } } else if (/^[ \t]*\*string-match\*[ \t]*$/.test(line)) { if (label) { this.vimBuiltFunctionDocuments[label].pop(); } break; } else if (label) { this.vimBuiltFunctionDocuments[label].push(line); } } } }; Server.prototype.resolveBuiltinVimPopupFunctionsDocument = function () { var popupText = this.text[POPUP_PATH] || []; var isMatchLine = false; var label = ""; for (var idx = 0; idx < popupText.length; idx++) { var line = popupText[idx]; if (!isMatchLine) { if (/^DETAILS\s+\*popup-function-details\*/.test(line)) { isMatchLine = true; idx += 1; } continue; } else { var m = line.match(/^((\w+)\(([^)]*)\))[ \t]*([^ \t].*)?$/); if (m) { if (label) { this.vimBuiltFunctionDocuments[label].pop(); } label = m[2]; if (!this.vimBuiltFunctionDocuments[label]) { this.vimBuiltFunctionDocuments[label] = []; } } else if (/^=+$/.test(line)) { if (label) { this.vimBuiltFunctionDocuments[label].pop(); } break; } else if (label) { this.vimBuiltFunctionDocuments[label].push(line); } } } }; Server.prototype.resolveBuiltinVimChannelFunctionsDocument = function () { var channelText = this.text[CHANNEL_PATH] || []; var isMatchLine = false; var label = ""; for (var idx = 0; idx < channelText.length; idx++) { var line = channelText[idx]; if (!isMatchLine) { if (/^8\.\sChannel\sfunctions\sdetails\s+\*channel-functions-details\*/.test(line)) { isMatchLine = true; idx += 1; } continue; } else { var m = line.match(/^((\w+)\(([^)]*)\))[ \t]*([^ \t].*)?$/); if (m) { if (label) { this.vimBuiltFunctionDocuments[label].pop(); } label = m[2]; if (!this.vimBuiltFunctionDocuments[label]) { this.vimBuiltFunctionDocuments[label] = []; } } else if (/^=+$/.test(line)) { if (label) { this.vimBuiltFunctionDocuments[label].pop(); } break; } else if (label) { this.vimBuiltFunctionDocuments[label].push(line); } } } }; Server.prototype.resolveBuiltinVimJobFunctionsDocument = function () { var channelText = this.text[CHANNEL_PATH] || []; var isMatchLine = false; var label = ""; for (var idx = 0; idx < channelText.length; idx++) { var line = channelText[idx]; if (!isMatchLine) { if (/^11\.\sJob\sfunctions\s+\*job-functions-details\*/.test(line)) { isMatchLine = true; idx += 1; } continue; } else { var m = line.match(/^((\w+)\(([^)]*)\))[ \t]*([^ \t].*)?$/); if (m) { if (label) { this.vimBuiltFunctionDocuments[label].pop(); } label = m[2]; if (!this.vimBuiltFunctionDocuments[label]) { this.vimBuiltFunctionDocuments[label] = []; } } else if (/^=+$/.test(line)) { if (label) {