-(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
-/******/ // The module cache
-/******/ var installedModules = {};
-/******/
-/******/ // The require function
-/******/ function __webpack_require__(moduleId) {
-/******/
-/******/ // Check if module is in cache
-/******/ if(installedModules[moduleId]) {
-/******/ return installedModules[moduleId].exports;
-/******/ }
-/******/ // Create a new module (and put it into the cache)
-/******/ var module = installedModules[moduleId] = {
-/******/ i: moduleId,
-/******/ l: false,
-/******/ exports: {}
-/******/ };
-/******/
-/******/ // Execute the module function
-/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
-/******/
-/******/ // Flag the module as loaded
-/******/ module.l = true;
-/******/
-/******/ // Return the exports of the module
-/******/ return module.exports;
-/******/ }
-/******/
-/******/
-/******/ // expose the modules object (__webpack_modules__)
-/******/ __webpack_require__.m = modules;
-/******/
-/******/ // expose the module cache
-/******/ __webpack_require__.c = installedModules;
-/******/
-/******/ // define getter function for harmony exports
-/******/ __webpack_require__.d = function(exports, name, getter) {
-/******/ if(!__webpack_require__.o(exports, name)) {
-/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
-/******/ }
-/******/ };
-/******/
-/******/ // define __esModule on exports
-/******/ __webpack_require__.r = function(exports) {
-/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
-/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
-/******/ }
-/******/ Object.defineProperty(exports, '__esModule', { value: true });
-/******/ };
-/******/
-/******/ // create a fake namespace object
-/******/ // mode & 1: value is a module id, require it
-/******/ // mode & 2: merge all properties of value into the ns
-/******/ // mode & 4: return value when already ns object
-/******/ // mode & 8|1: behave like require
-/******/ __webpack_require__.t = function(value, mode) {
-/******/ if(mode & 1) value = __webpack_require__(value);
-/******/ if(mode & 8) return value;
-/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
-/******/ var ns = Object.create(null);
-/******/ __webpack_require__.r(ns);
-/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
-/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
-/******/ return ns;
-/******/ };
-/******/
-/******/ // getDefaultExport function for compatibility with non-harmony modules
-/******/ __webpack_require__.n = function(module) {
-/******/ var getter = module && module.__esModule ?
-/******/ function getDefault() { return module['default']; } :
-/******/ function getModuleExports() { return module; };
-/******/ __webpack_require__.d(getter, 'a', getter);
-/******/ return getter;
-/******/ };
-/******/
-/******/ // Object.prototype.hasOwnProperty.call
-/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
-/******/
-/******/ // __webpack_public_path__
-/******/ __webpack_require__.p = "";
-/******/
-/******/
-/******/ // Load entry module and return exports
-/******/ return __webpack_require__(__webpack_require__.s = 0);
-/******/ })
-/************************************************************************/
-/******/ ([
+(function(e, a) { for(var i in a) e[i] = a[i]; if(a.__esModule) Object.defineProperty(e, "__esModule", { value: true }); }(exports,
+/******/ (() => { // webpackBootstrap
+/******/ "use strict";
+/******/ var __webpack_modules__ = ([
/* 0 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
-"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
-Object.defineProperty(exports, "__esModule", { value: true });
+Object.defineProperty(exports, "__esModule", ({ value: true }));
+exports.activate = void 0;
/******************************************************************
MIT License http://www.opensource.org/licenses/mit-license.php
Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
*******************************************************************/
const coc_nvim_1 = __webpack_require__(1);
-const os_1 = __importDefault(__webpack_require__(2));
-const fs_1 = __importDefault(__webpack_require__(3));
+const fs_1 = __importDefault(__webpack_require__(2));
+const os_1 = __importDefault(__webpack_require__(3));
const path_1 = __importDefault(__webpack_require__(4));
const util_1 = __importDefault(__webpack_require__(5));
const vscode_languageserver_types_1 = __webpack_require__(6);
-const snippet_1 = __importDefault(__webpack_require__(7));
-const provider_1 = __webpack_require__(35);
-const snipmateProvider_1 = __webpack_require__(39);
-const textmateProvider_1 = __webpack_require__(43);
-const ultisnipsProvider_1 = __webpack_require__(49);
-const debounce_1 = __importDefault(__webpack_require__(52));
-const languages_1 = __importDefault(__webpack_require__(53));
+const languages_1 = __importDefault(__webpack_require__(7));
+const snippet_1 = __importDefault(__webpack_require__(37));
+const provider_1 = __webpack_require__(38);
+const snipmateProvider_1 = __webpack_require__(40);
+const textmateProvider_1 = __webpack_require__(44);
+const ultisnipsProvider_1 = __webpack_require__(50);
const documentation = `# A valid snippet should starts with:
#
# snippet trigger_word [ "description" [ options ] ]
await util_1.default.promisify(fs_1.default.mkdir)(snippetsDir);
}
coc_nvim_1.events.on('CompleteDone', async (item) => {
- if (item.user_data && item.user_data.indexOf('snippets') !== -1) {
+ if (typeof item.user_data === 'string' && item.user_data.indexOf('snippets') !== -1) {
await mru.add(item.word);
}
}, null, subscriptions);
}
if (configuration.get('autoTrigger', true)) {
let insertTs;
- coc_nvim_1.events.on('InsertCharPre', () => {
+ let insertLeaveTs;
+ let lastInsert;
+ coc_nvim_1.events.on('InsertCharPre', character => {
insertTs = Date.now();
+ lastInsert = character;
}, null, subscriptions);
- coc_nvim_1.events.on(['TextChanged', 'TextChangedP', 'TextChangedI'], debounce_1.default(async () => {
- if (!coc_nvim_1.workspace.insertMode)
+ coc_nvim_1.events.on('InsertLeave', () => {
+ insertLeaveTs = Date.now();
+ }, null, subscriptions);
+ let inserting = false;
+ const handleTextChange = async (bufnr, pre) => {
+ let lastInsertTs = insertTs;
+ insertTs = undefined;
+ if (inserting)
+ return;
+ let doc = coc_nvim_1.workspace.getDocument(bufnr);
+ if (!doc || doc.isCommandLine || !doc.attached)
return;
- if (!insertTs || Date.now() - insertTs > 200)
+ let now = Date.now();
+ if (!lastInsertTs || now - lastInsertTs > 100 || !pre.endsWith(lastInsert))
return;
- let curr = insertTs;
let edits = await manager.getTriggerSnippets(true);
- if (insertTs != curr || edits.length == 0)
+ if (edits.length == 0)
return;
if (edits.length > 1) {
channel.appendLine(`Multiple snippet found for auto trigger: ${edits.map(s => s.prefix).join(', ')}`);
coc_nvim_1.workspace.showMessage('Multiple snippet found for auto trigger, check output by :CocCommand workspace.showOutput', 'warning');
}
- await coc_nvim_1.commands.executeCommand('editor.action.insertSnippet', edits[0]);
- await mru.add(edits[0].prefix);
- }, 100), null, subscriptions);
+ if (insertLeaveTs > now || inserting)
+ return;
+ inserting = true;
+ try {
+ await coc_nvim_1.commands.executeCommand('editor.action.insertSnippet', edits[0]);
+ await mru.add(edits[0].prefix);
+ }
+ catch (e) {
+ console.error(e);
+ }
+ inserting = false;
+ };
+ coc_nvim_1.events.on('TextChangedI', async (bufnr, info) => {
+ await handleTextChange(bufnr, info.pre);
+ }, null, subscriptions);
+ coc_nvim_1.events.on('TextChangedP', async (bufnr, info) => {
+ await handleTextChange(bufnr, info.pre);
+ }, null, subscriptions);
}
let statusItem;
if (configuration.get('enableStatusItem', true)) {
}
return true;
}
- if (configuration.get("convertToSnippetsAction")) {
- subscriptions.push(coc_nvim_1.languages.registerCodeActionProvider([{ scheme: 'file' }, { scheme: 'untitled' }], {
- provideCodeActions: async (document, range, context) => {
- if (context.only && !context.only.includes(vscode_languageserver_types_1.CodeActionKind.Source))
- return;
- let text = document.getText(range);
- if (text.endsWith('\n'))
- text = text.replace(/\n$/, '');
- let action = vscode_languageserver_types_1.CodeAction.create('Convert to snippet', {
- command: 'snippets.editSnippets',
- title: 'Convert to snippet',
- arguments: [text]
- });
- return [action];
- }
- }, 'snippets', [vscode_languageserver_types_1.CodeActionKind.Source]));
- }
+ subscriptions.push(coc_nvim_1.workspace.registerKeymap(['x'], 'convert-snippet', async () => {
+ let mode = await coc_nvim_1.workspace.nvim.call('visualmode');
+ if (!mode)
+ return;
+ let doc = await coc_nvim_1.workspace.document;
+ if (!doc)
+ return;
+ doc.forceSync();
+ let range = await coc_nvim_1.workspace.getSelectedRange(mode, doc);
+ let text = doc.textDocument.getText(range);
+ if (text)
+ await coc_nvim_1.commands.executeCommand('snippets.editSnippets', text);
+ }, { sync: false }));
subscriptions.push(coc_nvim_1.commands.registerCommand('snippets.editSnippets', async (text) => {
let buf = await nvim.buffer;
let doc = coc_nvim_1.workspace.getDocument(buf.id);
let expanded = await doExpand();
if (!expanded)
await fallback();
- }, { silent: true, sync: true, cancel: true }));
+ }, { silent: true, sync: false, cancel: true }));
subscriptions.push(coc_nvim_1.workspace.registerKeymap(['i'], 'snippets-expand-jump', async () => {
let expanded = await doExpand();
if (!expanded) {
}
await fallback();
}
- }, { silent: true, sync: true, cancel: true }));
+ }, { silent: true, sync: false, cancel: true }));
subscriptions.push(coc_nvim_1.workspace.registerKeymap(['v'], 'snippets-select', async () => {
let doc = await coc_nvim_1.workspace.document;
if (!doc)
let text = doc.textDocument.getText(range);
await nvim.call('feedkeys', ['i', 'in']);
if (mode == 'v') {
- await doc.applyEdits(coc_nvim_1.workspace.nvim, [{ range, newText: '' }]);
+ await doc.applyEdits([{ range, newText: '' }]);
}
else {
// keep indent
lines = lines.map(s => s.startsWith(indent) ? s.slice(indent.length) : s);
text = lines.join('\n');
range = vscode_languageserver_types_1.Range.create(vscode_languageserver_types_1.Position.create(start.line, indent.length), end);
- await doc.applyEdits(coc_nvim_1.workspace.nvim, [{ range, newText: '' }]);
+ await doc.applyEdits([{ range, newText: '' }]);
}
await nvim.setVar('coc_selected_text', text);
await coc_nvim_1.workspace.moveTo(range.start);
/***/ }),
/* 1 */
-/***/ (function(module, exports) {
+/***/ ((module) => {
-module.exports = require("coc.nvim");
+module.exports = require("coc.nvim");;
/***/ }),
/* 2 */
-/***/ (function(module, exports) {
+/***/ ((module) => {
-module.exports = require("os");
+module.exports = require("fs");;
/***/ }),
/* 3 */
-/***/ (function(module, exports) {
+/***/ ((module) => {
-module.exports = require("fs");
+module.exports = require("os");;
/***/ }),
/* 4 */
-/***/ (function(module, exports) {
+/***/ ((module) => {
-module.exports = require("path");
+module.exports = require("path");;
/***/ }),
/* 5 */
-/***/ (function(module, exports) {
+/***/ ((module) => {
-module.exports = require("util");
+module.exports = require("util");;
/***/ }),
/* 6 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
-"use strict";
__webpack_require__.r(__webpack_exports__);
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Position", function() { return Position; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Range", function() { return Range; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Location", function() { return Location; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "LocationLink", function() { return LocationLink; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Color", function() { return Color; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ColorInformation", function() { return ColorInformation; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ColorPresentation", function() { return ColorPresentation; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FoldingRangeKind", function() { return FoldingRangeKind; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FoldingRange", function() { return FoldingRange; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DiagnosticRelatedInformation", function() { return DiagnosticRelatedInformation; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DiagnosticSeverity", function() { return DiagnosticSeverity; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DiagnosticTag", function() { return DiagnosticTag; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Diagnostic", function() { return Diagnostic; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Command", function() { return Command; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TextEdit", function() { return TextEdit; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TextDocumentEdit", function() { return TextDocumentEdit; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CreateFile", function() { return CreateFile; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "RenameFile", function() { return RenameFile; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DeleteFile", function() { return DeleteFile; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "WorkspaceEdit", function() { return WorkspaceEdit; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "WorkspaceChange", function() { return WorkspaceChange; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TextDocumentIdentifier", function() { return TextDocumentIdentifier; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "VersionedTextDocumentIdentifier", function() { return VersionedTextDocumentIdentifier; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TextDocumentItem", function() { return TextDocumentItem; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MarkupKind", function() { return MarkupKind; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MarkupContent", function() { return MarkupContent; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CompletionItemKind", function() { return CompletionItemKind; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "InsertTextFormat", function() { return InsertTextFormat; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CompletionItemTag", function() { return CompletionItemTag; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CompletionItem", function() { return CompletionItem; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CompletionList", function() { return CompletionList; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MarkedString", function() { return MarkedString; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Hover", function() { return Hover; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ParameterInformation", function() { return ParameterInformation; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SignatureInformation", function() { return SignatureInformation; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DocumentHighlightKind", function() { return DocumentHighlightKind; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DocumentHighlight", function() { return DocumentHighlight; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SymbolKind", function() { return SymbolKind; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SymbolTag", function() { return SymbolTag; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SymbolInformation", function() { return SymbolInformation; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DocumentSymbol", function() { return DocumentSymbol; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CodeActionKind", function() { return CodeActionKind; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CodeActionContext", function() { return CodeActionContext; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CodeAction", function() { return CodeAction; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CodeLens", function() { return CodeLens; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FormattingOptions", function() { return FormattingOptions; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DocumentLink", function() { return DocumentLink; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SelectionRange", function() { return SelectionRange; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EOL", function() { return EOL; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TextDocument", function() { return TextDocument; });
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "Position": () => /* binding */ Position,
+/* harmony export */ "Range": () => /* binding */ Range,
+/* harmony export */ "Location": () => /* binding */ Location,
+/* harmony export */ "LocationLink": () => /* binding */ LocationLink,
+/* harmony export */ "Color": () => /* binding */ Color,
+/* harmony export */ "ColorInformation": () => /* binding */ ColorInformation,
+/* harmony export */ "ColorPresentation": () => /* binding */ ColorPresentation,
+/* harmony export */ "FoldingRangeKind": () => /* binding */ FoldingRangeKind,
+/* harmony export */ "FoldingRange": () => /* binding */ FoldingRange,
+/* harmony export */ "DiagnosticRelatedInformation": () => /* binding */ DiagnosticRelatedInformation,
+/* harmony export */ "DiagnosticSeverity": () => /* binding */ DiagnosticSeverity,
+/* harmony export */ "DiagnosticTag": () => /* binding */ DiagnosticTag,
+/* harmony export */ "Diagnostic": () => /* binding */ Diagnostic,
+/* harmony export */ "Command": () => /* binding */ Command,
+/* harmony export */ "TextEdit": () => /* binding */ TextEdit,
+/* harmony export */ "TextDocumentEdit": () => /* binding */ TextDocumentEdit,
+/* harmony export */ "CreateFile": () => /* binding */ CreateFile,
+/* harmony export */ "RenameFile": () => /* binding */ RenameFile,
+/* harmony export */ "DeleteFile": () => /* binding */ DeleteFile,
+/* harmony export */ "WorkspaceEdit": () => /* binding */ WorkspaceEdit,
+/* harmony export */ "WorkspaceChange": () => /* binding */ WorkspaceChange,
+/* harmony export */ "TextDocumentIdentifier": () => /* binding */ TextDocumentIdentifier,
+/* harmony export */ "VersionedTextDocumentIdentifier": () => /* binding */ VersionedTextDocumentIdentifier,
+/* harmony export */ "TextDocumentItem": () => /* binding */ TextDocumentItem,
+/* harmony export */ "MarkupKind": () => /* binding */ MarkupKind,
+/* harmony export */ "MarkupContent": () => /* binding */ MarkupContent,
+/* harmony export */ "CompletionItemKind": () => /* binding */ CompletionItemKind,
+/* harmony export */ "InsertTextFormat": () => /* binding */ InsertTextFormat,
+/* harmony export */ "CompletionItemTag": () => /* binding */ CompletionItemTag,
+/* harmony export */ "CompletionItem": () => /* binding */ CompletionItem,
+/* harmony export */ "CompletionList": () => /* binding */ CompletionList,
+/* harmony export */ "MarkedString": () => /* binding */ MarkedString,
+/* harmony export */ "Hover": () => /* binding */ Hover,
+/* harmony export */ "ParameterInformation": () => /* binding */ ParameterInformation,
+/* harmony export */ "SignatureInformation": () => /* binding */ SignatureInformation,
+/* harmony export */ "DocumentHighlightKind": () => /* binding */ DocumentHighlightKind,
+/* harmony export */ "DocumentHighlight": () => /* binding */ DocumentHighlight,
+/* harmony export */ "SymbolKind": () => /* binding */ SymbolKind,
+/* harmony export */ "SymbolTag": () => /* binding */ SymbolTag,
+/* harmony export */ "SymbolInformation": () => /* binding */ SymbolInformation,
+/* harmony export */ "DocumentSymbol": () => /* binding */ DocumentSymbol,
+/* harmony export */ "CodeActionKind": () => /* binding */ CodeActionKind,
+/* harmony export */ "CodeActionContext": () => /* binding */ CodeActionContext,
+/* harmony export */ "CodeAction": () => /* binding */ CodeAction,
+/* harmony export */ "CodeLens": () => /* binding */ CodeLens,
+/* harmony export */ "FormattingOptions": () => /* binding */ FormattingOptions,
+/* harmony export */ "DocumentLink": () => /* binding */ DocumentLink,
+/* harmony export */ "SelectionRange": () => /* binding */ SelectionRange,
+/* harmony export */ "EOL": () => /* binding */ EOL,
+/* harmony export */ "TextDocument": () => /* binding */ TextDocument
+/* harmony export */ });
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
/***/ }),
/* 7 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
-var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-/******************************************************************
-MIT License http://www.opensource.org/licenses/mit-license.php
-Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
-*******************************************************************/
+Object.defineProperty(exports, "__esModule", ({ value: true }));
const coc_nvim_1 = __webpack_require__(1);
const vscode_languageserver_protocol_1 = __webpack_require__(8);
-const os_1 = __importDefault(__webpack_require__(2));
-class SnippetsList extends coc_nvim_1.BasicList {
- constructor(nvim, manager, mru) {
- super(nvim);
- this.manager = manager;
- this.mru = mru;
- this.name = 'snippets';
- this.description = 'snippets list';
- this.addLocationActions();
+const util_1 = __webpack_require__(35);
+const codesMap = new Map();
+codesMap.set(1, 'invalid snippet line, trigger requried.');
+codesMap.set(2, 'invalid snippet option, option "$1" not supported.');
+codesMap.set(3, 'invalid python expression, $1');
+codesMap.set(4, 'invalid code interpolation, #! not supported.');
+const validOptions = ['b', 'i', 'w', 'r', 'e', 'A'];
+class LanguageProvider {
+ constructor(channel, trace = 'error') {
+ this.channel = channel;
+ this.trace = trace;
+ this.disposables = [];
+ this.collection = coc_nvim_1.languages.createDiagnosticCollection('snippets');
+ for (let doc of coc_nvim_1.workspace.documents) {
+ if (this.shouldValidate(doc.uri)) {
+ this.validate(doc.uri, doc.getDocumentContent()).catch(e => {
+ channel.appendLine(`[Error ${(new Date()).toLocaleTimeString()}]: ${e.message}`);
+ });
+ }
+ }
+ coc_nvim_1.workspace.onDidOpenTextDocument(async (textDocument) => {
+ let doc = coc_nvim_1.workspace.getDocument(textDocument.uri);
+ if (!this.shouldValidate(doc.uri))
+ return;
+ await this.validate(doc.uri, doc.getDocumentContent());
+ }, null, this.disposables);
+ coc_nvim_1.workspace.onDidChangeTextDocument(async (ev) => {
+ let doc = coc_nvim_1.workspace.getDocument(ev.textDocument.uri);
+ if (!doc || !this.shouldValidate(doc.uri))
+ return;
+ await this.validate(doc.uri, doc.getDocumentContent());
+ }, null, this.disposables);
+ coc_nvim_1.workspace.onDidCloseTextDocument(e => {
+ this.collection.delete(e.uri);
+ }, null, this.disposables);
}
- async loadItems(context) {
- let { window } = context;
- let valid = await window.valid;
- if (!valid)
- return;
- let buf = await window.buffer;
- let doc = coc_nvim_1.workspace.getDocument(buf.id);
- if (!doc)
- return [];
- let snippets = await this.manager.getSnippets(doc.filetype);
- let res = [];
- let recents = await this.mru.load();
- for (let snip of snippets) {
- let pos = vscode_languageserver_protocol_1.Position.create(snip.lnum, 0);
- let location = vscode_languageserver_protocol_1.Location.create(coc_nvim_1.Uri.file(snip.filepath).toString(), vscode_languageserver_protocol_1.Range.create(pos, pos));
- let prefix = snip.prefix;
- if (prefix.length < 20) {
- prefix = `${prefix}${' '.repeat(20 - prefix.length)}`;
+ shouldValidate(uri) {
+ return uri.endsWith('.snippets');
+ }
+ async validate(uri, content) {
+ let lines = content.split('\n');
+ let diagnostics = [];
+ let curr = 0;
+ for (let line of lines) {
+ if (/^snippet\s*$/.test(line)) {
+ let range = vscode_languageserver_protocol_1.Range.create(curr, 0, curr, line.length);
+ diagnostics.push(vscode_languageserver_protocol_1.Diagnostic.create(range, codesMap.get(1), vscode_languageserver_protocol_1.DiagnosticSeverity.Error, 1));
+ continue;
}
- let idx = recents.indexOf(snip.prefix);
- res.push({
- label: `${prefix}\t${snip.description}\t${snip.filepath.replace(os_1.default.homedir(), '~')}`,
- filterText: `${snip.prefix} ${snip.description}`,
- location,
- recentScore: idx == -1 ? -1 : recents.length - idx
- });
+ if (line.startsWith('snippet ')) {
+ let content = util_1.headTail(line)[1];
+ let ms = content.match(/^(.+?)(?:\s+(?:"(.*?)")?(?:\s+"(.*?)")?(?:\s+(\w+))?)?$/);
+ let prefix = ms[1];
+ if (prefix.length > 2 && prefix[0] == prefix[prefix.length - 1] && !/\w/.test(prefix[0])) {
+ prefix = prefix.slice(1, prefix.length - 1);
+ }
+ let option = ms[4] || '';
+ let isExpression = option.indexOf('r') !== -1;
+ let startCharacter = line.length - option.length;
+ for (let ch of option) {
+ if (validOptions.indexOf(ch) == -1) {
+ let range = vscode_languageserver_protocol_1.Range.create(curr, startCharacter, curr, startCharacter + 1);
+ let message = codesMap.get(2).replace('$1', ch);
+ diagnostics.push(vscode_languageserver_protocol_1.Diagnostic.create(range, message, vscode_languageserver_protocol_1.DiagnosticSeverity.Error, 2));
+ }
+ startCharacter = startCharacter + 1;
+ }
+ if (isExpression) {
+ try {
+ util_1.convertRegex(prefix);
+ }
+ catch (e) {
+ let start = line.indexOf(prefix);
+ let range = vscode_languageserver_protocol_1.Range.create(curr, start, curr, start + prefix.length);
+ let message = codesMap.get(3).replace('$1', e.message);
+ diagnostics.push(vscode_languageserver_protocol_1.Diagnostic.create(range, message, vscode_languageserver_protocol_1.DiagnosticSeverity.Error, 3));
+ }
+ }
+ }
+ else {
+ let idx = line.indexOf('`#!');
+ if (idx !== -1) {
+ let range = vscode_languageserver_protocol_1.Range.create(curr, idx, curr, idx + 3);
+ let message = codesMap.get(4);
+ diagnostics.push(vscode_languageserver_protocol_1.Diagnostic.create(range, message, vscode_languageserver_protocol_1.DiagnosticSeverity.Error, 4));
+ }
+ }
+ curr++;
}
- return res;
+ if (this.trace == 'verbose') {
+ this.channel.appendLine(`[Debug ${(new Date()).toLocaleTimeString()}] diagnostics of ${uri} -> ${JSON.stringify(diagnostics)}`);
+ }
+ this.collection.set(uri, diagnostics);
}
- async doHighlight() {
- let { nvim } = coc_nvim_1.workspace;
- nvim.pauseNotification();
- nvim.command('syntax match CocSnippetsPrefix /\\v^\\S+/ contained containedin=CocSnippetsLine', true);
- nvim.command('syntax match CocSnippetsFile /\\v\\t\\S+$/ contained containedin=CocSnippetsLine', true);
- nvim.command('highlight default link CocSnippetsPrefix Identifier', true);
- nvim.command('highlight default link CocSnippetsFile Comment', true);
- await nvim.resumeNotification();
+ provideCompletionItems(_document, position, _token, context) {
+ let { input, col } = context.option;
+ if (context.triggerCharacter == '$') {
+ return [{
+ label: '$VISUAL',
+ kind: vscode_languageserver_protocol_1.CompletionItemKind.Snippet,
+ // tslint:disable-next-line: no-invalid-template-strings
+ detail: '${VISUAL}',
+ insertTextFormat: vscode_languageserver_protocol_1.InsertTextFormat.Snippet,
+ textEdit: {
+ range: vscode_languageserver_protocol_1.Range.create(position.line, position.character - 1, position.line, position.character),
+ // tslint:disable-next-line: no-invalid-template-strings
+ newText: '\\${VISUAL${1::default}\\}'
+ }
+ }];
+ }
+ if (col == 0 && 'snippet'.startsWith(input)) {
+ return [{
+ label: 'snippet',
+ kind: vscode_languageserver_protocol_1.CompletionItemKind.Snippet,
+ detail: 'Snippet definition',
+ insertTextFormat: vscode_languageserver_protocol_1.InsertTextFormat.Snippet,
+ // tslint:disable-next-line: no-invalid-template-strings
+ insertText: 'snippet ${1:Tab_trigger} "${2:Description}" ${3:b}\n$0\nendsnippet'
+ }];
+ }
+ return [];
+ }
+ async resolveCompletionItem(item) {
+ // tslint:disable-next-line: deprecation
+ let text = item.insertText || item.textEdit.newText;
+ // tslint:disable-next-line: deprecation
+ let snip = await Promise.resolve(coc_nvim_1.snippetManager.resolveSnippet(text));
+ item.documentation = {
+ kind: 'markdown',
+ value: util_1.markdownBlock(snip.toString(), 'snippets')
+ };
+ return item;
}
}
-exports.default = SnippetsList;
+exports.default = LanguageProvider;
/***/ }),
/* 8 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
function __export(m) {\r
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r
}\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const vscode_jsonrpc_1 = __webpack_require__(9);\r
exports.ErrorCodes = vscode_jsonrpc_1.ErrorCodes;\r
exports.ResponseError = vscode_jsonrpc_1.ResponseError;\r
/***/ }),
/* 9 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
function __export(m) {\r
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r
}\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const Is = __webpack_require__(10);\r
const messages_1 = __webpack_require__(11);\r
exports.RequestType = messages_1.RequestType;\r
/***/ }),
/* 10 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
function boolean(value) {\r
return value === true || value === false;\r
}\r
/***/ }),
/* 11 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const is = __webpack_require__(10);\r
/**\r
* Predefined error codes.\r
/***/ }),
/* 12 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const events_1 = __webpack_require__(13);\r
const Is = __webpack_require__(10);\r
let DefaultSize = 8192;\r
/***/ }),
/* 13 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
var Disposable;\r
(function (Disposable) {\r
function create(func) {\r
/***/ }),
/* 14 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const events_1 = __webpack_require__(13);\r
const Is = __webpack_require__(10);\r
let ContentLength = 'Content-Length: ';\r
/***/ }),
/* 15 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/*---------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
*--------------------------------------------------------------------------------------------*/\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const events_1 = __webpack_require__(13);\r
const Is = __webpack_require__(10);\r
var CancellationToken;\r
/***/ }),
/* 16 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports) => {
-"use strict";
\r
/*---------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
*--------------------------------------------------------------------------------------------*/\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
var Touch;\r
(function (Touch) {\r
Touch.None = 0;\r
/***/ }),
/* 17 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const path_1 = __webpack_require__(4);\r
-const os_1 = __webpack_require__(2);\r
+const os_1 = __webpack_require__(3);\r
const crypto_1 = __webpack_require__(18);\r
const net_1 = __webpack_require__(19);\r
const messageReader_1 = __webpack_require__(12);\r
/***/ }),
/* 18 */
-/***/ (function(module, exports) {
+/***/ ((module) => {
-module.exports = require("crypto");
+module.exports = require("crypto");;
/***/ }),
/* 19 */
-/***/ (function(module, exports) {
+/***/ ((module) => {
-module.exports = require("net");
+module.exports = require("net");;
/***/ }),
/* 20 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const net_1 = __webpack_require__(19);\r
const messageReader_1 = __webpack_require__(12);\r
const messageWriter_1 = __webpack_require__(14);\r
/***/ }),
/* 21 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const Is = __webpack_require__(22);\r
const vscode_jsonrpc_1 = __webpack_require__(9);\r
const messages_1 = __webpack_require__(23);\r
/***/ }),
/* 22 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
function boolean(value) {\r
return value === true || value === false;\r
}\r
/***/ }),
/* 23 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const vscode_jsonrpc_1 = __webpack_require__(9);\r
class ProtocolRequestType0 extends vscode_jsonrpc_1.RequestType0 {\r
constructor(method) {\r
/***/ }),
/* 24 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const vscode_jsonrpc_1 = __webpack_require__(9);\r
const messages_1 = __webpack_require__(23);\r
// @ts-ignore: to avoid inlining LocatioLink as dynamic import\r
/***/ }),
/* 25 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const vscode_jsonrpc_1 = __webpack_require__(9);\r
const messages_1 = __webpack_require__(23);\r
// @ts-ignore: to avoid inlining LocatioLink as dynamic import\r
/***/ }),
/* 26 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const messages_1 = __webpack_require__(23);\r
/**\r
* The `workspace/workspaceFolders` is sent from the server to the client to fetch the open workspace folders.\r
/***/ }),
/* 27 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const messages_1 = __webpack_require__(23);\r
/**\r
* The 'workspace/configuration' request is sent from the server to the client to fetch a certain\r
/***/ }),
/* 28 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const vscode_jsonrpc_1 = __webpack_require__(9);\r
const messages_1 = __webpack_require__(23);\r
/**\r
/***/ }),
/* 29 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
\r
/*---------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
*--------------------------------------------------------------------------------------------*/\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const vscode_jsonrpc_1 = __webpack_require__(9);\r
const messages_1 = __webpack_require__(23);\r
/**\r
/***/ }),
/* 30 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const vscode_jsonrpc_1 = __webpack_require__(9);\r
const messages_1 = __webpack_require__(23);\r
// @ts-ignore: to avoid inlining LocatioLink as dynamic import\r
/***/ }),
/* 31 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
\r
/*---------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
*--------------------------------------------------------------------------------------------*/\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const vscode_jsonrpc_1 = __webpack_require__(9);\r
const messages_1 = __webpack_require__(23);\r
/**\r
/***/ }),
/* 32 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const vscode_jsonrpc_1 = __webpack_require__(9);\r
const messages_1 = __webpack_require__(23);\r
var WorkDoneProgress;\r
/***/ }),
/* 33 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) TypeFox and others. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const messages_1 = __webpack_require__(23);\r
/**\r
* A request to result a `CallHierarchyItem` in a document at a given position.\r
/***/ }),
/* 34 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
/* --------------------------------------------------------------------------------------------\r
* Copyright (c) Microsoft Corporation. All rights reserved.\r
* Licensed under the MIT License. See License.txt in the project root for license information.\r
* ------------------------------------------------------------------------------------------ */\r
\r
-Object.defineProperty(exports, "__esModule", { value: true });\r
+Object.defineProperty(exports, "__esModule", ({ value: true }));\r
const messages_1 = __webpack_require__(23);\r
/**\r
* A set of predefined token types. This set is not fixed\r
/***/ }),
/* 35 */
-/***/ (function(module, exports, __webpack_require__) {
+/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
-"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
-Object.defineProperty(exports, "__esModule", { value: true });
+Object.defineProperty(exports, "__esModule", ({ value: true }));
+exports.markdownBlock = exports.getRegexText = exports.wait = exports.convertRegex = exports.distinct = exports.trimQuote = exports.memorize = exports.headTail = exports.readdirAsync = exports.readFileAsync = exports.writeFileAsync = exports.statAsync = exports.flatten = exports.replaceText = exports.uid = void 0;
/******************************************************************
MIT License http://www.opensource.org/licenses/mit-license.php
Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
*******************************************************************/
-const coc_nvim_1 = __webpack_require__(1);
-const path_1 = __importDefault(__webpack_require__(4));
-const vscode_languageserver_protocol_1 = __webpack_require__(8);
-const types_1 = __webpack_require__(36);
-const util_1 = __webpack_require__(37);
-class ProviderManager {
- constructor() {
- this.providers = new Map();
- }
- regist(provider, name) {
- this.providers.set(name, provider);
- return vscode_languageserver_protocol_1.Disposable.create(() => {
- this.providers.delete(name);
- });
+const pify_1 = __importDefault(__webpack_require__(36));
+const fs_1 = __importDefault(__webpack_require__(2));
+const crypto_1 = __importDefault(__webpack_require__(18));
+const BASE64 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_';
+function tostr(bytes) {
+ let r = [];
+ let i;
+ for (i = 0; i < bytes.length; i++) {
+ r.push(BASE64[bytes[i] % 64]);
}
- get hasProvider() {
- return this.providers.size > 0;
- }
- async init() {
- let providers = Array.from(this.providers.values());
- await Promise.all(providers.map(provider => {
- return provider.init();
- }));
- }
- async getSnippets(filetype) {
- let names = Array.from(this.providers.keys());
- let list = [];
- for (let name of names) {
- let provider = this.providers.get(name);
- let snippets = await provider.getSnippets(filetype);
- snippets.map(s => s.provider = name);
- list.push(...snippets);
- }
- return list;
- }
- async getSnippetFiles(filetype) {
- let files = [];
- for (let provider of this.providers.values()) {
- let res = await provider.getSnippetFiles(filetype);
- files = files.concat(res);
- }
- return files;
- }
- async getTriggerSnippets(autoTrigger = false) {
- let bufnr = await coc_nvim_1.workspace.nvim.call('bufnr', '%');
- let doc = coc_nvim_1.workspace.getDocument(bufnr);
- if (!doc)
- return [];
- await doc.patchChange();
- let position = await coc_nvim_1.workspace.getCursorPosition();
- let names = Array.from(this.providers.keys());
- let list = [];
- for (let name of names) {
- let provider = this.providers.get(name);
- let items = await provider.getTriggerSnippets(doc, position, autoTrigger);
- for (let item of items) {
- if (list.findIndex(o => o.prefix == item.prefix) == -1) {
- list.push(item);
- }
- }
- }
- list.sort((a, b) => b.priority - a.priority);
- if (list.length > 1 && list[0].priority > 0) {
- list = list.filter(o => o.priority > 0);
- }
- return list;
- }
- async provideCompletionItems(document, position, _token, context) {
- let doc = coc_nvim_1.workspace.getDocument(document.uri);
- if (!doc)
- return [];
- let snippets = await this.getSnippets(doc.filetype);
- let currline = doc.getline(position.line, true);
- let { input, col } = context.option;
- let character = characterIndex(currline, col);
- let before_content = currline.slice(0, character);
- let res = [];
- let contextPrefixes = [];
- for (let snip of snippets) {
- let contentBehind = before_content;
- if (contextPrefixes.indexOf(snip.prefix) !== -1)
- continue;
- if (snip.regex != null && snip.prefix == '')
- continue;
- if (snip.context) {
- let provider = this.providers.get(snip.provider);
- let valid = await provider.checkContext(snip.context);
- if (!valid)
- continue;
- contextPrefixes.push(snip.prefix);
- }
- let head = this.getPrefixHead(doc, snip.prefix);
- if (input.length == 0 && !before_content.endsWith(snip.prefix))
- continue;
- let item = {
- label: snip.prefix,
- kind: vscode_languageserver_protocol_1.CompletionItemKind.Snippet,
- filterText: snip.prefix,
- detail: snip.description,
- insertTextFormat: vscode_languageserver_protocol_1.InsertTextFormat.Snippet
- };
- item.data = {
- snip,
- provider: snip.provider,
- filepath: `${path_1.default.basename(snip.filepath)}:${snip.lnum}`
- };
- if (snip.regex) {
- if (!input.length || snip.prefix && input[0] != snip.prefix[0])
- continue;
- let content = before_content + snip.prefix;
- let ms = content.match(snip.regex);
- if (!ms)
- continue;
- }
- else if (head && before_content.endsWith(head)) {
- contentBehind = before_content.slice(0, -head.length);
- let prefix = snip.prefix.slice(head.length);
- Object.assign(item, {
- textEdit: {
- range: vscode_languageserver_protocol_1.Range.create({ line: position.line, character: character - head.length }, position),
- newText: prefix
- }
- });
- }
- else if (input.length == 0) {
- let { prefix } = snip;
- contentBehind = before_content.slice(0, -prefix.length);
- Object.assign(item, {
- preselect: true,
- textEdit: {
- range: vscode_languageserver_protocol_1.Range.create({ line: position.line, character: character - prefix.length }, position),
- newText: prefix
- }
- });
- }
- if (snip.triggerKind == types_1.TriggerKind.LineBegin && contentBehind.trim().length)
- continue;
- if (snip.triggerKind == types_1.TriggerKind.SpaceBefore) {
- if (contentBehind.length && !/\s/.test(contentBehind[contentBehind.length - 1])) {
- continue;
- }
- }
- if (!item.textEdit) {
- item.textEdit = {
- range: vscode_languageserver_protocol_1.Range.create({ line: position.line, character }, position),
- newText: item.label
- };
- }
- item.data.location = `${snip.filepath}:${snip.lnum}`;
- item.data.line = contentBehind + snip.prefix;
- res.push(item);
- }
- return res;
- }
- async resolveCompletionItem(item) {
- let provider = this.providers.get(item.data.provider);
- if (provider) {
- let filetype = await coc_nvim_1.workspace.nvim.eval('&filetype');
- let insertSnippet = await provider.resolveSnippetBody(item.data.snip, item.textEdit.range, item.data.line);
- item.textEdit.newText = insertSnippet;
- if (coc_nvim_1.snippetManager) {
- let snip = await Promise.resolve(coc_nvim_1.snippetManager.resolveSnippet(insertSnippet));
- item.documentation = {
- kind: 'markdown',
- value: util_1.markdownBlock(snip.toString(), filetype)
- };
- }
- }
- return item;
- }
- getPrefixHead(doc, prefix) {
- let res = 0;
- for (let idx = prefix.length - 1; idx >= 0; idx--) {
- if (!doc.isWord(prefix[idx])) {
- res = idx;
- break;
- }
- }
- return res == 0 ? '' : prefix.slice(0, res + 1);
- }
-}
-exports.ProviderManager = ProviderManager;
-function characterIndex(content, byteIndex) {
- let buf = Buffer.from(content, 'utf8');
- return buf.slice(0, byteIndex).toString('utf8').length;
-}
-exports.characterIndex = characterIndex;
-
-
-/***/ }),
-/* 36 */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", { value: true });
-var TriggerKind;
-(function (TriggerKind) {
- TriggerKind[TriggerKind["SpaceBefore"] = 0] = "SpaceBefore";
- TriggerKind[TriggerKind["LineBegin"] = 1] = "LineBegin";
- TriggerKind[TriggerKind["WordBoundary"] = 2] = "WordBoundary";
- TriggerKind[TriggerKind["InWord"] = 3] = "InWord";
-})(TriggerKind = exports.TriggerKind || (exports.TriggerKind = {}));
-
-
-/***/ }),
-/* 37 */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
-
-var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-/******************************************************************
-MIT License http://www.opensource.org/licenses/mit-license.php
-Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
-*******************************************************************/
-const pify_1 = __importDefault(__webpack_require__(38));
-const fs_1 = __importDefault(__webpack_require__(3));
-const crypto_1 = __importDefault(__webpack_require__(18));
-const BASE64 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_';
-function tostr(bytes) {
- let r = [];
- let i;
- for (i = 0; i < bytes.length; i++) {
- r.push(BASE64[bytes[i] % 64]);
- }
- return r.join('');
-}
-function uid() {
- return tostr(crypto_1.default.randomBytes(10));
-}
-exports.uid = uid;
-function replaceText(content, items) {
- let res = '';
- items.sort((a, b) => a.index - b.index);
- let item = items.shift();
- for (let i = 0; i < content.length; i++) {
- let idx = item ? item.index : null;
- if (idx == null || i != idx) {
- res = res + content[i];
- continue;
- }
- res = res + item.newText;
- i = i + item.length;
+ return r.join('');
+}
+function uid() {
+ return tostr(crypto_1.default.randomBytes(10));
+}
+exports.uid = uid;
+function replaceText(content, items) {
+ let res = '';
+ items.sort((a, b) => a.index - b.index);
+ let item = items.shift();
+ for (let i = 0; i < content.length; i++) {
+ let idx = item ? item.index : null;
+ if (idx == null || i != idx) {
+ res = res + content[i];
+ continue;
+ }
+ res = res + item.newText;
+ i = i + item.length;
}
return res;
}
/***/ }),
-/* 38 */
-/***/ (function(module, exports, __webpack_require__) {
+/* 36 */
+/***/ ((module) => {
-"use strict";
const processFn = (fn, options, proxy, unwrapped) => function (...arguments_) {
const cached = cache.get(property);
- if (cached) {
- return cached;
- }
+ if (cached) {
+ return cached;
+ }
+
+ if (typeof property === 'function') {
+ const pified = processFn(property, options, proxy, target);
+ cache.set(property, pified);
+ return pified;
+ }
+
+ return property;
+ }
+ });
+
+ return proxy;
+};
+
+
+/***/ }),
+/* 37 */
+/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
+
+
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", ({ value: true }));
+/******************************************************************
+MIT License http://www.opensource.org/licenses/mit-license.php
+Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
+*******************************************************************/
+const coc_nvim_1 = __webpack_require__(1);
+const vscode_languageserver_protocol_1 = __webpack_require__(8);
+const os_1 = __importDefault(__webpack_require__(3));
+class SnippetsList extends coc_nvim_1.BasicList {
+ constructor(nvim, manager, mru) {
+ super(nvim);
+ this.manager = manager;
+ this.mru = mru;
+ this.name = 'snippets';
+ this.description = 'snippets list';
+ this.addLocationActions();
+ }
+ async loadItems(context) {
+ let { window } = context;
+ let valid = await window.valid;
+ if (!valid)
+ return;
+ let buf = await window.buffer;
+ let doc = coc_nvim_1.workspace.getDocument(buf.id);
+ if (!doc)
+ return [];
+ let snippets = await this.manager.getSnippets(doc.filetype);
+ let res = [];
+ let recents = await this.mru.load();
+ for (let snip of snippets) {
+ let pos = vscode_languageserver_protocol_1.Position.create(snip.lnum, 0);
+ let location = vscode_languageserver_protocol_1.Location.create(coc_nvim_1.Uri.file(snip.filepath).toString(), vscode_languageserver_protocol_1.Range.create(pos, pos));
+ let prefix = snip.prefix;
+ if (prefix.length < 20) {
+ prefix = `${prefix}${' '.repeat(20 - prefix.length)}`;
+ }
+ let idx = recents.indexOf(snip.prefix);
+ res.push({
+ label: `${prefix}\t${snip.description}\t${snip.filepath.replace(os_1.default.homedir(), '~')}`,
+ filterText: `${snip.prefix} ${snip.description}`,
+ location,
+ recentScore: idx == -1 ? -1 : recents.length - idx
+ });
+ }
+ return res;
+ }
+ async doHighlight() {
+ let { nvim } = coc_nvim_1.workspace;
+ nvim.pauseNotification();
+ nvim.command('syntax match CocSnippetsPrefix /\\v^\\S+/ contained containedin=CocSnippetsLine', true);
+ nvim.command('syntax match CocSnippetsFile /\\v\\t\\S+$/ contained containedin=CocSnippetsLine', true);
+ nvim.command('highlight default link CocSnippetsPrefix Identifier', true);
+ nvim.command('highlight default link CocSnippetsFile Comment', true);
+ await nvim.resumeNotification();
+ }
+}
+exports.default = SnippetsList;
+
+
+/***/ }),
+/* 38 */
+/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
+
+
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", ({ value: true }));
+exports.characterIndex = exports.ProviderManager = void 0;
+/******************************************************************
+MIT License http://www.opensource.org/licenses/mit-license.php
+Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
+*******************************************************************/
+const coc_nvim_1 = __webpack_require__(1);
+const path_1 = __importDefault(__webpack_require__(4));
+const vscode_languageserver_protocol_1 = __webpack_require__(8);
+const types_1 = __webpack_require__(39);
+const util_1 = __webpack_require__(35);
+class ProviderManager {
+ constructor() {
+ this.providers = new Map();
+ }
+ regist(provider, name) {
+ this.providers.set(name, provider);
+ return vscode_languageserver_protocol_1.Disposable.create(() => {
+ this.providers.delete(name);
+ });
+ }
+ get hasProvider() {
+ return this.providers.size > 0;
+ }
+ async init() {
+ let providers = Array.from(this.providers.values());
+ await Promise.all(providers.map(provider => {
+ return provider.init();
+ }));
+ }
+ async getSnippets(filetype) {
+ let names = Array.from(this.providers.keys());
+ let list = [];
+ for (let name of names) {
+ let provider = this.providers.get(name);
+ let snippets = await provider.getSnippets(filetype);
+ snippets.map(s => s.provider = name);
+ list.push(...snippets);
+ }
+ return list;
+ }
+ async getSnippetFiles(filetype) {
+ let files = [];
+ for (let provider of this.providers.values()) {
+ let res = await provider.getSnippetFiles(filetype);
+ files = files.concat(res);
+ }
+ return files;
+ }
+ async getTriggerSnippets(autoTrigger = false) {
+ let bufnr = await coc_nvim_1.workspace.nvim.call('bufnr', '%');
+ let doc = coc_nvim_1.workspace.getDocument(bufnr);
+ if (!doc)
+ return [];
+ await doc.patchChange();
+ let position = await coc_nvim_1.workspace.getCursorPosition();
+ let names = Array.from(this.providers.keys());
+ let list = [];
+ for (let name of names) {
+ let provider = this.providers.get(name);
+ let items = await provider.getTriggerSnippets(doc, position, autoTrigger);
+ for (let item of items) {
+ if (list.findIndex(o => o.prefix == item.prefix) == -1) {
+ list.push(item);
+ }
+ }
+ }
+ list.sort((a, b) => b.priority - a.priority);
+ if (list.length > 1 && list[0].priority > 0) {
+ list = list.filter(o => o.priority > 0);
+ }
+ return list;
+ }
+ async provideCompletionItems(document, position, _token, context) {
+ let doc = coc_nvim_1.workspace.getDocument(document.uri);
+ if (!doc)
+ return [];
+ let snippets = await this.getSnippets(doc.filetype);
+ let currline = doc.getline(position.line, true);
+ let { input, col } = context.option;
+ let character = characterIndex(currline, col);
+ let before_content = currline.slice(0, character);
+ let res = [];
+ let contextPrefixes = [];
+ for (let snip of snippets) {
+ let contentBehind = before_content;
+ if (contextPrefixes.indexOf(snip.prefix) !== -1)
+ continue;
+ if (snip.regex != null && snip.prefix == '')
+ continue;
+ if (snip.context) {
+ let provider = this.providers.get(snip.provider);
+ let valid = await provider.checkContext(snip.context);
+ if (!valid)
+ continue;
+ contextPrefixes.push(snip.prefix);
+ }
+ let head = this.getPrefixHead(doc, snip.prefix);
+ if (input.length == 0 && !before_content.endsWith(snip.prefix))
+ continue;
+ let item = {
+ label: snip.prefix,
+ kind: vscode_languageserver_protocol_1.CompletionItemKind.Snippet,
+ filterText: snip.prefix,
+ detail: snip.description,
+ insertTextFormat: vscode_languageserver_protocol_1.InsertTextFormat.Snippet
+ };
+ item.data = {
+ snip,
+ provider: snip.provider,
+ filepath: `${path_1.default.basename(snip.filepath)}:${snip.lnum}`
+ };
+ if (snip.regex) {
+ if (!input.length || snip.prefix && input[0] != snip.prefix[0])
+ continue;
+ let content = before_content + snip.prefix;
+ let ms = content.match(snip.regex);
+ if (!ms)
+ continue;
+ }
+ else if (head && before_content.endsWith(head)) {
+ contentBehind = before_content.slice(0, -head.length);
+ let prefix = snip.prefix.slice(head.length);
+ Object.assign(item, {
+ textEdit: {
+ range: vscode_languageserver_protocol_1.Range.create({ line: position.line, character: character - head.length }, position),
+ newText: prefix
+ }
+ });
+ }
+ else if (input.length == 0) {
+ let { prefix } = snip;
+ contentBehind = before_content.slice(0, -prefix.length);
+ Object.assign(item, {
+ preselect: true,
+ textEdit: {
+ range: vscode_languageserver_protocol_1.Range.create({ line: position.line, character: character - prefix.length }, position),
+ newText: prefix
+ }
+ });
+ }
+ if (snip.triggerKind == types_1.TriggerKind.LineBegin && contentBehind.trim().length)
+ continue;
+ if (snip.triggerKind == types_1.TriggerKind.SpaceBefore) {
+ if (contentBehind.length && !/\s/.test(contentBehind[contentBehind.length - 1])) {
+ continue;
+ }
+ }
+ if (!item.textEdit) {
+ item.textEdit = {
+ range: vscode_languageserver_protocol_1.Range.create({ line: position.line, character }, position),
+ newText: item.label
+ };
+ }
+ item.data.location = `${snip.filepath}:${snip.lnum}`;
+ item.data.line = contentBehind + snip.prefix;
+ res.push(item);
+ }
+ return res;
+ }
+ async resolveCompletionItem(item) {
+ let provider = this.providers.get(item.data.provider);
+ if (provider) {
+ let filetype = await coc_nvim_1.workspace.nvim.eval('&filetype');
+ let insertSnippet = await provider.resolveSnippetBody(item.data.snip, item.textEdit.range, item.data.line);
+ item.textEdit.newText = insertSnippet;
+ if (coc_nvim_1.snippetManager) {
+ let snip = await Promise.resolve(coc_nvim_1.snippetManager.resolveSnippet(insertSnippet));
+ item.documentation = {
+ kind: 'markdown',
+ value: util_1.markdownBlock(snip.toString(), filetype)
+ };
+ }
+ }
+ return item;
+ }
+ getPrefixHead(doc, prefix) {
+ let res = 0;
+ for (let idx = prefix.length - 1; idx >= 0; idx--) {
+ if (!doc.isWord(prefix[idx])) {
+ res = idx;
+ break;
+ }
+ }
+ return res == 0 ? '' : prefix.slice(0, res + 1);
+ }
+}
+exports.ProviderManager = ProviderManager;
+function characterIndex(content, byteIndex) {
+ let buf = Buffer.from(content, 'utf8');
+ return buf.slice(0, byteIndex).toString('utf8').length;
+}
+exports.characterIndex = characterIndex;
+
- if (typeof property === 'function') {
- const pified = processFn(property, options, proxy, target);
- cache.set(property, pified);
- return pified;
- }
+/***/ }),
+/* 39 */
+/***/ ((__unused_webpack_module, exports) => {
- return property;
- }
- });
- return proxy;
-};
+Object.defineProperty(exports, "__esModule", ({ value: true }));
+exports.TriggerKind = void 0;
+var TriggerKind;
+(function (TriggerKind) {
+ TriggerKind[TriggerKind["SpaceBefore"] = 0] = "SpaceBefore";
+ TriggerKind[TriggerKind["LineBegin"] = 1] = "LineBegin";
+ TriggerKind[TriggerKind["WordBoundary"] = 2] = "WordBoundary";
+ TriggerKind[TriggerKind["InWord"] = 3] = "InWord";
+})(TriggerKind = exports.TriggerKind || (exports.TriggerKind = {}));
/***/ }),
-/* 39 */
-/***/ (function(module, exports, __webpack_require__) {
+/* 40 */
+/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
-"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
-Object.defineProperty(exports, "__esModule", { value: true });
+Object.defineProperty(exports, "__esModule", ({ value: true }));
+exports.SnipmateProvider = void 0;
/******************************************************************
MIT License http://www.opensource.org/licenses/mit-license.php
Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
*******************************************************************/
const coc_nvim_1 = __webpack_require__(1);
-const fs_1 = __importDefault(__webpack_require__(3));
+const fs_1 = __importDefault(__webpack_require__(2));
const path_1 = __importDefault(__webpack_require__(4));
-const readline_1 = __importDefault(__webpack_require__(40));
+const readline_1 = __importDefault(__webpack_require__(41));
const vscode_languageserver_types_1 = __webpack_require__(6);
-const baseProvider_1 = __importDefault(__webpack_require__(41));
-const types_1 = __webpack_require__(36);
-const util_1 = __webpack_require__(37);
-const parser_1 = __importDefault(__webpack_require__(42));
+const baseProvider_1 = __importDefault(__webpack_require__(42));
+const types_1 = __webpack_require__(39);
+const util_1 = __webpack_require__(35);
+const parser_1 = __importDefault(__webpack_require__(43));
class SnipmateProvider extends baseProvider_1.default {
constructor(channel, trace, config) {
super(config);
filetype,
snippets
});
- if (this.trace == 'verbose') {
- this.channel.appendLine(`[Info ${(new Date()).toLocaleTimeString()}] Loaded ${snippets.length} snippets from: ${filepath}`);
- }
+ this.channel.appendLine(`[Info ${(new Date()).toISOString()}] Loaded ${snippets.length} snipmate snippets from: ${filepath}`);
}
/**
* Resolve snippet body to inserted text.
/***/ }),
-/* 40 */
-/***/ (function(module, exports) {
+/* 41 */
+/***/ ((module) => {
-module.exports = require("readline");
+module.exports = require("readline");;
/***/ }),
-/* 41 */
-/***/ (function(module, exports, __webpack_require__) {
+/* 42 */
+/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
+Object.defineProperty(exports, "__esModule", ({ value: true }));
const coc_nvim_1 = __webpack_require__(1);
-const util_1 = __webpack_require__(37);
+const util_1 = __webpack_require__(35);
class BaseProvider {
constructor(config) {
this.config = config;
/***/ }),
-/* 42 */
-/***/ (function(module, exports, __webpack_require__) {
+/* 43 */
+/***/ ((__unused_webpack_module, exports) => {
-"use strict";
/******************************************************************
MIT License http://www.opensource.org/licenses/mit-license.php
Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
*******************************************************************/
-Object.defineProperty(exports, "__esModule", { value: true });
+Object.defineProperty(exports, "__esModule", ({ value: true }));
/**
* A very basic parser
*
/***/ }),
-/* 43 */
-/***/ (function(module, exports, __webpack_require__) {
+/* 44 */
+/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
-"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
-Object.defineProperty(exports, "__esModule", { value: true });
+Object.defineProperty(exports, "__esModule", ({ value: true }));
+exports.TextmateProvider = void 0;
const coc_nvim_1 = __webpack_require__(1);
-const fs_1 = __importDefault(__webpack_require__(3));
-const jsonc_parser_1 = __webpack_require__(44);
-const os_1 = __importDefault(__webpack_require__(2));
+const fs_1 = __importDefault(__webpack_require__(2));
+const jsonc_parser_1 = __webpack_require__(45);
+const os_1 = __importDefault(__webpack_require__(3));
const path_1 = __importDefault(__webpack_require__(4));
const util_1 = __importDefault(__webpack_require__(5));
const vscode_languageserver_types_1 = __webpack_require__(6);
-const baseProvider_1 = __importDefault(__webpack_require__(41));
-const types_1 = __webpack_require__(36);
-const util_2 = __webpack_require__(37);
+const baseProvider_1 = __importDefault(__webpack_require__(42));
+const types_1 = __webpack_require__(39);
+const util_2 = __webpack_require__(35);
class TextmateProvider extends baseProvider_1.default {
constructor(channel, trace, config) {
super(config);
});
});
const snippets = this.loadSnippetsFromText(snippetFilePath, contents);
- if (this.trace == 'verbose') {
- this.channel.appendLine(`[Info ${(new Date()).toLocaleDateString()}] Loaded ${snippets.length} snippets from ${snippetFilePath}`);
- }
+ this.channel.appendLine(`[Info ${(new Date()).toISOString()}] Loaded ${snippets.length} textmate snippets from ${snippetFilePath}`);
return snippets;
}
loadSnippetsFromText(filepath, contents) {
let errors = [];
let snippetObject = jsonc_parser_1.parse(contents, errors, { allowTrailingComma: true });
if (errors.length) {
- this.channel.appendLine(`[Error ${(new Date()).toLocaleDateString()}] parser error: ${errors[0].error}`);
+ this.channel.appendLine(`[Error ${(new Date()).toLocaleDateString()}] parser error of ${filepath}: ${JSON.stringify(errors, null, 2)}`);
}
if (snippetObject) {
for (let key of Object.keys(snippetObject)) {
/***/ }),
-/* 44 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
+/* 45 */
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
-"use strict";
__webpack_require__.r(__webpack_exports__);
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createScanner", function() { return createScanner; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getLocation", function() { return getLocation; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parse", function() { return parse; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parseTree", function() { return parseTree; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "findNodeAtLocation", function() { return findNodeAtLocation; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "findNodeAtOffset", function() { return findNodeAtOffset; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getNodePath", function() { return getNodePath; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getNodeValue", function() { return getNodeValue; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "visit", function() { return visit; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "stripComments", function() { return stripComments; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "printParseErrorCode", function() { return printParseErrorCode; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "format", function() { return format; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "modify", function() { return modify; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "applyEdits", function() { return applyEdits; });
-/* harmony import */ var _impl_format__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(45);
-/* harmony import */ var _impl_edit__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(47);
-/* harmony import */ var _impl_scanner__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(46);
-/* harmony import */ var _impl_parser__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(48);
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "createScanner": () => /* binding */ createScanner,
+/* harmony export */ "getLocation": () => /* binding */ getLocation,
+/* harmony export */ "parse": () => /* binding */ parse,
+/* harmony export */ "parseTree": () => /* binding */ parseTree,
+/* harmony export */ "findNodeAtLocation": () => /* binding */ findNodeAtLocation,
+/* harmony export */ "findNodeAtOffset": () => /* binding */ findNodeAtOffset,
+/* harmony export */ "getNodePath": () => /* binding */ getNodePath,
+/* harmony export */ "getNodeValue": () => /* binding */ getNodeValue,
+/* harmony export */ "visit": () => /* binding */ visit,
+/* harmony export */ "stripComments": () => /* binding */ stripComments,
+/* harmony export */ "printParseErrorCode": () => /* binding */ printParseErrorCode,
+/* harmony export */ "format": () => /* binding */ format,
+/* harmony export */ "modify": () => /* binding */ modify,
+/* harmony export */ "applyEdits": () => /* binding */ applyEdits
+/* harmony export */ });
+/* harmony import */ var _impl_format__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(46);
+/* harmony import */ var _impl_edit__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(48);
+/* harmony import */ var _impl_scanner__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(47);
+/* harmony import */ var _impl_parser__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(49);
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Creates a JSON scanner on the given text.
* If ignoreTrivia is set, whitespaces or comments are ignored.
*/
-var createScanner = _impl_scanner__WEBPACK_IMPORTED_MODULE_2__["createScanner"];
+var createScanner = _impl_scanner__WEBPACK_IMPORTED_MODULE_3__.createScanner;
/**
* For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
*/
-var getLocation = _impl_parser__WEBPACK_IMPORTED_MODULE_3__["getLocation"];
+var getLocation = _impl_parser__WEBPACK_IMPORTED_MODULE_2__.getLocation;
/**
* Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
* Therefore, always check the errors list to find out if the input was valid.
*/
-var parse = _impl_parser__WEBPACK_IMPORTED_MODULE_3__["parse"];
+var parse = _impl_parser__WEBPACK_IMPORTED_MODULE_2__.parse;
/**
* Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
*/
-var parseTree = _impl_parser__WEBPACK_IMPORTED_MODULE_3__["parseTree"];
+var parseTree = _impl_parser__WEBPACK_IMPORTED_MODULE_2__.parseTree;
/**
* Finds the node at the given path in a JSON DOM.
*/
-var findNodeAtLocation = _impl_parser__WEBPACK_IMPORTED_MODULE_3__["findNodeAtLocation"];
+var findNodeAtLocation = _impl_parser__WEBPACK_IMPORTED_MODULE_2__.findNodeAtLocation;
/**
* Finds the innermost node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
*/
-var findNodeAtOffset = _impl_parser__WEBPACK_IMPORTED_MODULE_3__["findNodeAtOffset"];
+var findNodeAtOffset = _impl_parser__WEBPACK_IMPORTED_MODULE_2__.findNodeAtOffset;
/**
* Gets the JSON path of the given JSON DOM node
*/
-var getNodePath = _impl_parser__WEBPACK_IMPORTED_MODULE_3__["getNodePath"];
+var getNodePath = _impl_parser__WEBPACK_IMPORTED_MODULE_2__.getNodePath;
/**
* Evaluates the JavaScript object of the given JSON DOM node
*/
-var getNodeValue = _impl_parser__WEBPACK_IMPORTED_MODULE_3__["getNodeValue"];
+var getNodeValue = _impl_parser__WEBPACK_IMPORTED_MODULE_2__.getNodeValue;
/**
* Parses the given text and invokes the visitor functions for each object, array and literal reached.
*/
-var visit = _impl_parser__WEBPACK_IMPORTED_MODULE_3__["visit"];
+var visit = _impl_parser__WEBPACK_IMPORTED_MODULE_2__.visit;
/**
* Takes JSON with JavaScript-style comments and remove
* them. Optionally replaces every none-newline character
* of comments with a replaceCharacter
*/
-var stripComments = _impl_parser__WEBPACK_IMPORTED_MODULE_3__["stripComments"];
+var stripComments = _impl_parser__WEBPACK_IMPORTED_MODULE_2__.stripComments;
function printParseErrorCode(code) {
switch (code) {
case 1 /* InvalidSymbol */: return 'InvalidSymbol';
* To apply edits to an input, you can use `applyEdits`.
*/
function format(documentText, range, options) {
- return _impl_format__WEBPACK_IMPORTED_MODULE_0__["format"](documentText, range, options);
+ return _impl_format__WEBPACK_IMPORTED_MODULE_0__.format(documentText, range, options);
}
/**
* Computes the edits needed to modify a value in the JSON document.
* To apply edits to an input, you can use `applyEdits`.
*/
function modify(text, path, value, options) {
- return _impl_edit__WEBPACK_IMPORTED_MODULE_1__["setProperty"](text, path, value, options.formattingOptions, options.getInsertionIndex);
+ return _impl_edit__WEBPACK_IMPORTED_MODULE_1__.setProperty(text, path, value, options);
}
/**
* Applies edits to a input string.
*/
function applyEdits(text, edits) {
for (var i = edits.length - 1; i >= 0; i--) {
- text = _impl_edit__WEBPACK_IMPORTED_MODULE_1__["applyEdit"](text, edits[i]);
+ text = _impl_edit__WEBPACK_IMPORTED_MODULE_1__.applyEdit(text, edits[i]);
}
return text;
}
/***/ }),
-/* 45 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
+/* 46 */
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
-"use strict";
__webpack_require__.r(__webpack_exports__);
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "format", function() { return format; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isEOL", function() { return isEOL; });
-/* harmony import */ var _scanner__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(46);
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "format": () => /* binding */ format,
+/* harmony export */ "isEOL": () => /* binding */ isEOL
+/* harmony export */ });
+/* harmony import */ var _scanner__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(47);
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
else {
indentValue = '\t';
}
- var scanner = Object(_scanner__WEBPACK_IMPORTED_MODULE_0__["createScanner"])(formatText, false);
+ var scanner = (0,_scanner__WEBPACK_IMPORTED_MODULE_0__.createScanner)(formatText, false);
var hasError = false;
function newLineAndIndent() {
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
/***/ }),
-/* 46 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
+/* 47 */
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
-"use strict";
__webpack_require__.r(__webpack_exports__);
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createScanner", function() { return createScanner; });
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "createScanner": () => /* binding */ createScanner
+/* harmony export */ });
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
/***/ }),
-/* 47 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
+/* 48 */
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
-"use strict";
__webpack_require__.r(__webpack_exports__);
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeProperty", function() { return removeProperty; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setProperty", function() { return setProperty; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "applyEdit", function() { return applyEdit; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isWS", function() { return isWS; });
-/* harmony import */ var _format__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(45);
-/* harmony import */ var _parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(48);
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "removeProperty": () => /* binding */ removeProperty,
+/* harmony export */ "setProperty": () => /* binding */ setProperty,
+/* harmony export */ "applyEdit": () => /* binding */ applyEdit,
+/* harmony export */ "isWS": () => /* binding */ isWS
+/* harmony export */ });
+/* harmony import */ var _format__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(46);
+/* harmony import */ var _parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(49);
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
-function removeProperty(text, path, formattingOptions) {
- return setProperty(text, path, void 0, formattingOptions);
+function removeProperty(text, path, options) {
+ return setProperty(text, path, void 0, options);
}
-function setProperty(text, originalPath, value, formattingOptions, getInsertionIndex) {
+function setProperty(text, originalPath, value, options) {
var _a;
var path = originalPath.slice();
var errors = [];
- var root = Object(_parser__WEBPACK_IMPORTED_MODULE_1__["parseTree"])(text, errors);
+ var root = (0,_parser__WEBPACK_IMPORTED_MODULE_1__.parseTree)(text, errors);
var parent = void 0;
var lastSegment = void 0;
while (path.length > 0) {
lastSegment = path.pop();
- parent = Object(_parser__WEBPACK_IMPORTED_MODULE_1__["findNodeAtLocation"])(root, path);
+ parent = (0,_parser__WEBPACK_IMPORTED_MODULE_1__.findNodeAtLocation)(root, path);
if (parent === void 0 && value !== void 0) {
if (typeof lastSegment === 'string') {
value = (_a = {}, _a[lastSegment] = value, _a);
if (value === void 0) { // delete
throw new Error('Can not delete in empty document');
}
- return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, formattingOptions);
+ return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
}
else if (parent.type === 'object' && typeof lastSegment === 'string' && Array.isArray(parent.children)) {
- var existing = Object(_parser__WEBPACK_IMPORTED_MODULE_1__["findNodeAtLocation"])(parent, [lastSegment]);
+ var existing = (0,_parser__WEBPACK_IMPORTED_MODULE_1__.findNodeAtLocation)(parent, [lastSegment]);
if (existing !== void 0) {
if (value === void 0) { // delete
if (!existing.parent) {
removeEnd = next.offset;
}
}
- return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: '' }, formattingOptions);
+ return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: '' }, options);
}
else {
// set value of existing property
- return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, formattingOptions);
+ return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
}
}
else {
return []; // property does not exist, nothing to do
}
var newProperty = JSON.stringify(lastSegment) + ": " + JSON.stringify(value);
- var index = getInsertionIndex ? getInsertionIndex(parent.children.map(function (p) { return p.children[0].value; })) : parent.children.length;
+ var index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map(function (p) { return p.children[0].value; })) : parent.children.length;
var edit = void 0;
if (index > 0) {
var previous = parent.children[index - 1];
else {
edit = { offset: parent.offset + 1, length: 0, content: newProperty + ',' };
}
- return withFormatting(text, edit, formattingOptions);
+ return withFormatting(text, edit, options);
}
}
else if (parent.type === 'array' && typeof lastSegment === 'number' && Array.isArray(parent.children)) {
var previous = parent.children[parent.children.length - 1];
edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
}
- return withFormatting(text, edit, formattingOptions);
+ return withFormatting(text, edit, options);
}
- else {
- if (value === void 0 && parent.children.length >= 0) {
- //Removal
- var removalIndex = lastSegment;
- var toRemove = parent.children[removalIndex];
- var edit = void 0;
- if (parent.children.length === 1) {
- // only item
- edit = { offset: parent.offset + 1, length: parent.length - 2, content: '' };
- }
- else if (parent.children.length - 1 === removalIndex) {
- // last item
- var previous = parent.children[removalIndex - 1];
- var offset = previous.offset + previous.length;
- var parentEndOffset = parent.offset + parent.length;
- edit = { offset: offset, length: parentEndOffset - 2 - offset, content: '' };
- }
- else {
- edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: '' };
- }
- return withFormatting(text, edit, formattingOptions);
+ else if (value === void 0 && parent.children.length >= 0) {
+ // Removal
+ var removalIndex = lastSegment;
+ var toRemove = parent.children[removalIndex];
+ var edit = void 0;
+ if (parent.children.length === 1) {
+ // only item
+ edit = { offset: parent.offset + 1, length: parent.length - 2, content: '' };
+ }
+ else if (parent.children.length - 1 === removalIndex) {
+ // last item
+ var previous = parent.children[removalIndex - 1];
+ var offset = previous.offset + previous.length;
+ var parentEndOffset = parent.offset + parent.length;
+ edit = { offset: offset, length: parentEndOffset - 2 - offset, content: '' };
+ }
+ else {
+ edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: '' };
+ }
+ return withFormatting(text, edit, options);
+ }
+ else if (value !== void 0) {
+ var edit = void 0;
+ var newProperty = "" + JSON.stringify(value);
+ if (!options.isArrayInsertion && parent.children.length > lastSegment) {
+ var toModify = parent.children[lastSegment];
+ edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
+ }
+ else if (parent.children.length === 0 || lastSegment === 0) {
+ edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + ',' };
}
else {
- throw new Error('Array modification not supported yet');
+ var index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
+ var previous = parent.children[index - 1];
+ edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
}
+ return withFormatting(text, edit, options);
+ }
+ else {
+ throw new Error("Can not " + (value === void 0 ? 'remove' : (options.isArrayInsertion ? 'insert' : 'modify')) + " Array index " + insertIndex + " as length is not sufficient");
}
}
else {
throw new Error("Can not add " + (typeof lastSegment !== 'number' ? 'index' : 'property') + " to parent of type " + parent.type);
}
}
-function withFormatting(text, edit, formattingOptions) {
+function withFormatting(text, edit, options) {
+ if (!options.formattingOptions) {
+ return [edit];
+ }
// apply the edit
var newText = applyEdit(text, edit);
// format the new text
var begin = edit.offset;
var end = edit.offset + edit.content.length;
if (edit.length === 0 || edit.content.length === 0) { // insert or remove
- while (begin > 0 && !Object(_format__WEBPACK_IMPORTED_MODULE_0__["isEOL"])(newText, begin - 1)) {
+ while (begin > 0 && !(0,_format__WEBPACK_IMPORTED_MODULE_0__.isEOL)(newText, begin - 1)) {
begin--;
}
- while (end < newText.length && !Object(_format__WEBPACK_IMPORTED_MODULE_0__["isEOL"])(newText, end)) {
+ while (end < newText.length && !(0,_format__WEBPACK_IMPORTED_MODULE_0__.isEOL)(newText, end)) {
end++;
}
}
- var edits = Object(_format__WEBPACK_IMPORTED_MODULE_0__["format"])(newText, { offset: begin, length: end - begin }, formattingOptions);
+ var edits = (0,_format__WEBPACK_IMPORTED_MODULE_0__.format)(newText, { offset: begin, length: end - begin }, options.formattingOptions);
// apply the formatting edits and track the begin and end offsets of the changes
for (var i = edits.length - 1; i >= 0; i--) {
var edit_1 = edits[i];
/***/ }),
-/* 48 */
-/***/ (function(module, __webpack_exports__, __webpack_require__) {
+/* 49 */
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
-"use strict";
__webpack_require__.r(__webpack_exports__);
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getLocation", function() { return getLocation; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parse", function() { return parse; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parseTree", function() { return parseTree; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "findNodeAtLocation", function() { return findNodeAtLocation; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getNodePath", function() { return getNodePath; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getNodeValue", function() { return getNodeValue; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "contains", function() { return contains; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "findNodeAtOffset", function() { return findNodeAtOffset; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "visit", function() { return visit; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "stripComments", function() { return stripComments; });
-/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getNodeType", function() { return getNodeType; });
-/* harmony import */ var _scanner__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(46);
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "getLocation": () => /* binding */ getLocation,
+/* harmony export */ "parse": () => /* binding */ parse,
+/* harmony export */ "parseTree": () => /* binding */ parseTree,
+/* harmony export */ "findNodeAtLocation": () => /* binding */ findNodeAtLocation,
+/* harmony export */ "getNodePath": () => /* binding */ getNodePath,
+/* harmony export */ "getNodeValue": () => /* binding */ getNodeValue,
+/* harmony export */ "contains": () => /* binding */ contains,
+/* harmony export */ "findNodeAtOffset": () => /* binding */ findNodeAtOffset,
+/* harmony export */ "visit": () => /* binding */ visit,
+/* harmony export */ "stripComments": () => /* binding */ stripComments,
+/* harmony export */ "getNodeType": () => /* binding */ getNodeType
+/* harmony export */ });
+/* harmony import */ var _scanner__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(47);
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/
function visit(text, visitor, options) {
if (options === void 0) { options = ParseOptions.DEFAULT; }
- var _scanner = Object(_scanner__WEBPACK_IMPORTED_MODULE_0__["createScanner"])(text, false);
+ var _scanner = (0,_scanner__WEBPACK_IMPORTED_MODULE_0__.createScanner)(text, false);
function toNoArgVisit(visitFunction) {
return visitFunction ? function () { return visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()); } : function () { return true; };
}
function parseLiteral() {
switch (_scanner.getToken()) {
case 11 /* NumericLiteral */:
- var value = 0;
- try {
- value = JSON.parse(_scanner.getTokenValue());
- if (typeof value !== 'number') {
- handleError(2 /* InvalidNumberFormat */);
- value = 0;
- }
- }
- catch (e) {
+ var tokenValue = _scanner.getTokenValue();
+ var value = Number(tokenValue);
+ if (isNaN(value)) {
handleError(2 /* InvalidNumberFormat */);
+ value = 0;
}
onLiteralValue(value);
break;
* of comments with a replaceCharacter
*/
function stripComments(text, replaceCh) {
- var _scanner = Object(_scanner__WEBPACK_IMPORTED_MODULE_0__["createScanner"])(text), parts = [], kind, offset = 0, pos;
+ var _scanner = (0,_scanner__WEBPACK_IMPORTED_MODULE_0__.createScanner)(text), parts = [], kind, offset = 0, pos;
do {
pos = _scanner.getPosition();
kind = _scanner.scan();
/***/ }),
-/* 49 */
-/***/ (function(module, exports, __webpack_require__) {
+/* 50 */
+/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
-"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
-Object.defineProperty(exports, "__esModule", { value: true });
+Object.defineProperty(exports, "__esModule", ({ value: true }));
+exports.UltiSnippetsProvider = void 0;
/******************************************************************
MIT License http://www.opensource.org/licenses/mit-license.php
Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
*******************************************************************/
const coc_nvim_1 = __webpack_require__(1);
-const fs_1 = __importDefault(__webpack_require__(3));
-const os_1 = __importDefault(__webpack_require__(2));
+const fs_1 = __importDefault(__webpack_require__(2));
+const os_1 = __importDefault(__webpack_require__(3));
const path_1 = __importDefault(__webpack_require__(4));
const vscode_languageserver_types_1 = __webpack_require__(6);
-const baseProvider_1 = __importDefault(__webpack_require__(41));
-const types_1 = __webpack_require__(36);
-const ultisnipsParser_1 = __importDefault(__webpack_require__(50));
-const util_1 = __webpack_require__(37);
+const baseProvider_1 = __importDefault(__webpack_require__(42));
+const types_1 = __webpack_require__(39);
+const ultisnipsParser_1 = __importDefault(__webpack_require__(51));
+const util_1 = __webpack_require__(35);
const pythonCodes = new Map();
class UltiSnippetsProvider extends baseProvider_1.default {
constructor(channel, trace, config, context) {
this.directories.push(dir);
}
}
- this.channel.appendLine(`[Info ${(new Date()).toLocaleTimeString()}] Using ultisnips directories: ${this.directories.join(' ')}`);
+ this.channel.appendLine(`[Info ${(new Date()).toISOString()}] Using ultisnips directories: ${this.directories.join(' ')}`);
let hasPythonx = await nvim.call('has', ['pythonx']);
let pythonCode = await util_1.readFileAsync(this.context.asAbsolutePath('python/ultisnips.py'), 'utf8');
if (hasPythonx && config.usePythonx) {
filetypes = filetypes.concat(extendFiletypes);
this.config.extends[filetype] = util_1.distinct(filetypes);
}
- if (this.trace == 'verbose') {
- this.channel.appendLine(`[Info ${(new Date()).toLocaleTimeString()}] Loaded ${snippets.length} snippets from: ${filepath}`);
- }
+ this.channel.appendLine(`[Info ${(new Date()).toISOString()}] Loaded ${snippets.length} UltiSnip snippets from: ${filepath}`);
pythonCodes.set(filepath, pythonCode);
}
async resolveSnippetBody(snippet, range, line) {
if (exists == null || (val && exists == "''")) {
if (/^`!\w/.test(val) && val.endsWith('`')) {
let code = val.slice(1).slice(0, -1);
- val = await this.parser.execute(code, this.pyMethod, ind);
+ // not execute python code since we don't have snip yet.
+ if (code.startsWith('!p')) {
+ val = '';
+ }
+ else {
+ val = await this.parser.execute(code, this.pyMethod, ind);
+ }
}
val = val.replace(/'/g, "\\'").replace(/\n/g, '\\n');
values.set(idx, "'" + val + "'");
/***/ }),
-/* 50 */
-/***/ (function(module, exports, __webpack_require__) {
+/* 51 */
+/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
-"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
-Object.defineProperty(exports, "__esModule", { value: true });
+Object.defineProperty(exports, "__esModule", ({ value: true }));
/******************************************************************
MIT License http://www.opensource.org/licenses/mit-license.php
Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
*******************************************************************/
-const child_process_1 = __webpack_require__(51);
+const child_process_1 = __webpack_require__(52);
const coc_nvim_1 = __webpack_require__(1);
-const fs_1 = __importDefault(__webpack_require__(3));
-const pify_1 = __importDefault(__webpack_require__(38));
-const readline_1 = __importDefault(__webpack_require__(40));
-const parser_1 = __importDefault(__webpack_require__(42));
-const types_1 = __webpack_require__(36);
-const util_1 = __webpack_require__(37);
+const fs_1 = __importDefault(__webpack_require__(2));
+const pify_1 = __importDefault(__webpack_require__(36));
+const readline_1 = __importDefault(__webpack_require__(41));
+const parser_1 = __importDefault(__webpack_require__(43));
+const types_1 = __webpack_require__(39);
+const util_1 = __webpack_require__(35);
class UltiSnipsParser {
constructor(pyMethod, channel, trace = 'error') {
this.pyMethod = pyMethod;
let description = ms[2] || '';
let context = ms[3];
let option = ms[4] || '';
- if (prefix.length > 2 && prefix[0] == prefix[prefix.length - 1] && !/\w/.test(prefix[0])) {
+ if (prefix.length > 2 && prefix[1] != prefix[0] && prefix[0] == prefix[prefix.length - 1] && !/\w/.test(prefix[0])) {
prefix = prefix.slice(1, prefix.length - 1);
}
let isExpression = option.indexOf('r') !== -1;
}
-/***/ }),
-/* 51 */
-/***/ (function(module, exports) {
-
-module.exports = require("child_process");
-
/***/ }),
/* 52 */
-/***/ (function(module, exports) {
-
-/**
- * Returns a function, that, as long as it continues to be invoked, will not
- * be triggered. The function will be called after it stops being called for
- * N milliseconds. If `immediate` is passed, trigger the function on the
- * leading edge, instead of the trailing. The function also has a property 'clear'
- * that is a function which will clear the timer to prevent previously scheduled executions.
- *
- * @source underscore.js
- * @see http://unscriptable.com/2009/03/20/debouncing-javascript-methods/
- * @param {Function} function to wrap
- * @param {Number} timeout in ms (`100`)
- * @param {Boolean} whether to execute at the beginning (`false`)
- * @api public
- */
-function debounce(func, wait, immediate){
- var timeout, args, context, timestamp, result;
- if (null == wait) wait = 100;
-
- function later() {
- var last = Date.now() - timestamp;
-
- if (last < wait && last >= 0) {
- timeout = setTimeout(later, wait - last);
- } else {
- timeout = null;
- if (!immediate) {
- result = func.apply(context, args);
- context = args = null;
- }
- }
- };
-
- var debounced = function(){
- context = this;
- args = arguments;
- timestamp = Date.now();
- var callNow = immediate && !timeout;
- if (!timeout) timeout = setTimeout(later, wait);
- if (callNow) {
- result = func.apply(context, args);
- context = args = null;
- }
-
- return result;
- };
-
- debounced.clear = function() {
- if (timeout) {
- clearTimeout(timeout);
- timeout = null;
- }
- };
-
- debounced.flush = function() {
- if (timeout) {
- result = func.apply(context, args);
- context = args = null;
-
- clearTimeout(timeout);
- timeout = null;
- }
- };
-
- return debounced;
-};
-
-// Adds compatibility for ES modules
-debounce.debounce = debounce;
-
-module.exports = debounce;
-
-
-/***/ }),
-/* 53 */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", { value: true });
-const coc_nvim_1 = __webpack_require__(1);
-const vscode_languageserver_protocol_1 = __webpack_require__(8);
-const util_1 = __webpack_require__(37);
-const codesMap = new Map();
-codesMap.set(1, 'invalid snippet line, trigger requried.');
-codesMap.set(2, 'invalid snippet option, option "$1" not supported.');
-codesMap.set(3, 'invalid python expression, $1');
-codesMap.set(4, 'invalid code interpolation, #! not supported.');
-const validOptions = ['b', 'i', 'w', 'r', 'e', 'A'];
-class LanguageProvider {
- constructor(channel, trace = 'error') {
- this.channel = channel;
- this.trace = trace;
- this.disposables = [];
- this.collection = coc_nvim_1.languages.createDiagnosticCollection('snippets');
- for (let doc of coc_nvim_1.workspace.documents) {
- if (this.shouldValidate(doc.uri)) {
- this.validate(doc.uri, doc.getDocumentContent()).catch(e => {
- channel.appendLine(`[Error ${(new Date()).toLocaleTimeString()}]: ${e.message}`);
- });
- }
- }
- coc_nvim_1.workspace.onDidOpenTextDocument(async (textDocument) => {
- let doc = coc_nvim_1.workspace.getDocument(textDocument.uri);
- if (!this.shouldValidate(doc.uri))
- return;
- await this.validate(doc.uri, doc.getDocumentContent());
- }, null, this.disposables);
- coc_nvim_1.workspace.onDidChangeTextDocument(async (ev) => {
- let doc = coc_nvim_1.workspace.getDocument(ev.textDocument.uri);
- if (!doc || !this.shouldValidate(doc.uri))
- return;
- await this.validate(doc.uri, doc.getDocumentContent());
- }, null, this.disposables);
- coc_nvim_1.workspace.onDidCloseTextDocument(e => {
- this.collection.delete(e.uri);
- }, null, this.disposables);
- }
- shouldValidate(uri) {
- return uri.endsWith('.snippets');
- }
- async validate(uri, content) {
- let lines = content.split('\n');
- let diagnostics = [];
- let curr = 0;
- for (let line of lines) {
- if (/^snippet\s*$/.test(line)) {
- let range = vscode_languageserver_protocol_1.Range.create(curr, 0, curr, line.length);
- diagnostics.push(vscode_languageserver_protocol_1.Diagnostic.create(range, codesMap.get(1), vscode_languageserver_protocol_1.DiagnosticSeverity.Error, 1));
- continue;
- }
- if (line.startsWith('snippet ')) {
- let content = util_1.headTail(line)[1];
- let ms = content.match(/^(.+?)(?:\s+(?:"(.*?)")?(?:\s+"(.*?)")?(?:\s+(\w+))?)?$/);
- let prefix = ms[1];
- if (prefix.length > 2 && prefix[0] == prefix[prefix.length - 1] && !/\w/.test(prefix[0])) {
- prefix = prefix.slice(1, prefix.length - 1);
- }
- let option = ms[4] || '';
- let isExpression = option.indexOf('r') !== -1;
- let startCharacter = line.length - option.length;
- for (let ch of option) {
- if (validOptions.indexOf(ch) == -1) {
- let range = vscode_languageserver_protocol_1.Range.create(curr, startCharacter, curr, startCharacter + 1);
- let message = codesMap.get(2).replace('$1', ch);
- diagnostics.push(vscode_languageserver_protocol_1.Diagnostic.create(range, message, vscode_languageserver_protocol_1.DiagnosticSeverity.Error, 2));
- }
- startCharacter = startCharacter + 1;
- }
- if (isExpression) {
- try {
- util_1.convertRegex(prefix);
- }
- catch (e) {
- let start = line.indexOf(prefix);
- let range = vscode_languageserver_protocol_1.Range.create(curr, start, curr, start + prefix.length);
- let message = codesMap.get(3).replace('$1', e.message);
- diagnostics.push(vscode_languageserver_protocol_1.Diagnostic.create(range, message, vscode_languageserver_protocol_1.DiagnosticSeverity.Error, 3));
- }
- }
- }
- else {
- let idx = line.indexOf('`#!');
- if (idx !== -1) {
- let range = vscode_languageserver_protocol_1.Range.create(curr, idx, curr, idx + 3);
- let message = codesMap.get(4);
- diagnostics.push(vscode_languageserver_protocol_1.Diagnostic.create(range, message, vscode_languageserver_protocol_1.DiagnosticSeverity.Error, 4));
- }
- }
- curr++;
- }
- if (this.trace == 'verbose') {
- this.channel.appendLine(`[Debug ${(new Date()).toLocaleTimeString()}] diagnostics of ${uri} -> ${JSON.stringify(diagnostics)}`);
- }
- this.collection.set(uri, diagnostics);
- }
- provideCompletionItems(_document, position, _token, context) {
- let { input, col } = context.option;
- if (context.triggerCharacter == '$') {
- return [{
- label: '$VISUAL',
- kind: vscode_languageserver_protocol_1.CompletionItemKind.Snippet,
- // tslint:disable-next-line: no-invalid-template-strings
- detail: '${VISUAL}',
- insertTextFormat: vscode_languageserver_protocol_1.InsertTextFormat.Snippet,
- textEdit: {
- range: vscode_languageserver_protocol_1.Range.create(position.line, position.character - 1, position.line, position.character),
- // tslint:disable-next-line: no-invalid-template-strings
- newText: '\\${VISUAL${1::default}\\}'
- }
- }];
- }
- if (col == 0 && 'snippet'.startsWith(input)) {
- return [{
- label: 'snippet',
- kind: vscode_languageserver_protocol_1.CompletionItemKind.Snippet,
- detail: 'Snippet definition',
- insertTextFormat: vscode_languageserver_protocol_1.InsertTextFormat.Snippet,
- // tslint:disable-next-line: no-invalid-template-strings
- insertText: 'snippet ${1:Tab_trigger} "${2:Description}" ${3:b}\n$0\nendsnippet'
- }];
- }
- return [];
- }
- async resolveCompletionItem(item) {
- // tslint:disable-next-line: deprecation
- let text = item.insertText || item.textEdit.newText;
- // tslint:disable-next-line: deprecation
- let snip = await Promise.resolve(coc_nvim_1.snippetManager.resolveSnippet(text));
- item.documentation = {
- kind: 'markdown',
- value: util_1.markdownBlock(snip.toString(), 'snippets')
- };
- return item;
- }
-}
-exports.default = LanguageProvider;
+/***/ ((module) => {
+module.exports = require("child_process");;
/***/ })
-/******/ ])));
\ No newline at end of file
+/******/ ]);
+/************************************************************************/
+/******/ // The module cache
+/******/ var __webpack_module_cache__ = {};
+/******/
+/******/ // The require function
+/******/ function __webpack_require__(moduleId) {
+/******/ // Check if module is in cache
+/******/ if(__webpack_module_cache__[moduleId]) {
+/******/ return __webpack_module_cache__[moduleId].exports;
+/******/ }
+/******/ // Create a new module (and put it into the cache)
+/******/ var module = __webpack_module_cache__[moduleId] = {
+/******/ // no module.id needed
+/******/ // no module.loaded needed
+/******/ exports: {}
+/******/ };
+/******/
+/******/ // Execute the module function
+/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
+/******/
+/******/ // Return the exports of the module
+/******/ return module.exports;
+/******/ }
+/******/
+/************************************************************************/
+/******/ /* webpack/runtime/define property getters */
+/******/ (() => {
+/******/ // define getter functions for harmony exports
+/******/ __webpack_require__.d = (exports, definition) => {
+/******/ for(var key in definition) {
+/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
+/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
+/******/ }
+/******/ }
+/******/ };
+/******/ })();
+/******/
+/******/ /* webpack/runtime/hasOwnProperty shorthand */
+/******/ (() => {
+/******/ __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
+/******/ })();
+/******/
+/******/ /* webpack/runtime/make namespace object */
+/******/ (() => {
+/******/ // define __esModule on exports
+/******/ __webpack_require__.r = (exports) => {
+/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
+/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
+/******/ }
+/******/ Object.defineProperty(exports, '__esModule', { value: true });
+/******/ };
+/******/ })();
+/******/
+/************************************************************************/
+/******/ // module exports must be returned from runtime so entry inlining is disabled
+/******/ // startup
+/******/ // Load entry module and return exports
+/******/ return __webpack_require__(0);
+/******/ })()
+
+));
\ No newline at end of file