inital commit

This commit is contained in:
2020-07-04 14:23:27 +02:00
commit 46d9d9eb4c
251 changed files with 15044 additions and 0 deletions

View File

@ -0,0 +1,3 @@
{
"lastUpdate": 1593852197191
}

View File

@ -0,0 +1,22 @@
# coc-vimtex
Tex completion source use [vimtex](https://github.com/lervag/vimtex).
## Install
In your vim/neovim, run command:
```
:CocInstall coc-vimtex
```
## Options
- `coc.source.vimtex.disableSyntaxes` disabled syntax names.
- `coc.source.vimtex.enable` set to false to disable this source.
- `coc.source.vimtex.priority` priority of source, default `99`.
- `coc.source.vimtex.shortcut` shortcut used in `menu` of completion item.
## License
MIT

View File

@ -0,0 +1,46 @@
{
"name": "coc-vimtex",
"version": "1.0.3",
"description": "vimtex integration for coc.nvim",
"main": "src/index.js",
"publisher": "chemzqm",
"keywords": [
"coc.nvim",
"vimtex"
],
"engines": {
"coc": "^0.0.56"
},
"activationEvents": [
"onLanguage:tex",
"onLanguage:plaintex",
"onLanguage:latex"
],
"contributes": {
"configuration": {
"type": "object",
"properties": {
"coc.source.vimtex.enable": {
"type": "boolean",
"default": true
},
"coc.source.vimtex.priority": {
"type": "integer",
"default": 99
}
}
}
},
"author": "chemzqm@gmail.com",
"repository": {
"type": "git",
"url": "git+https://github.com/neoclide/coc-vimtex.git"
},
"license": "MIT",
"devDependencies": {
"@types/node": "^10.12.24",
"coc.nvim": "^0.0.74",
"rimraf": "^2.6.3"
},
"dependencies": {}
}

View File

@ -0,0 +1,67 @@
const {sources, workspace, SourceType} = require('coc.nvim')
const {convertRegex, byteSlice} = require('./util')
exports.activate = async context => {
let config = workspace.getConfiguration('coc.source.vimtex')
let {nvim} = workspace
let regex = await nvim.getVar('vimtex#re#deoplete')
if (!regex) {
workspace.showMessage('vimtex not loaded', 'error')
return
}
regex = regex.slice(2, regex.length)
let pattern = new RegExp(convertRegex(regex) + '$')
function convertItems(list) {
let res = []
for (let item of list) {
if (typeof item == 'string') {
res.push(Object.assign({word: item}))
}
if (item.hasOwnProperty('word')) {
res.push(item)
}
}
return res
}
let source = {
name: 'vimtex',
enable: config.get('enable', true),
priority: config.get('priority', 99),
filetypes: ['tex', 'plaintex', 'latex'],
sourceType: SourceType.Remote,
triggerPatterns: [pattern],
doComplete: async opt => {
let {nvim} = workspace
let func = 'vimtex#complete#omnifunc'
let {line, colnr, col} = opt
let startcol = col
try {
startcol = await nvim.call(func, [1, ''])
startcol = Number(startcol)
} catch (e) {
workspace.showMessage(`vim error from ${func} :${e.message}`, 'error')
return null
}
// invalid startcol
if (isNaN(startcol) || startcol < 0 || startcol > colnr) return null
let text = byteSlice(line, startcol, colnr - 1)
let words = await nvim.call(func, [0, text])
if (words.hasOwnProperty('words')) {
words = words.words
}
let res = {items: convertItems(words)}
res.startcol = startcol
return res
}
}
sources.addSource(source)
context.subscriptions.push({
dispose: () => {
sources.removeSource(source)
}
})
}

View File

@ -0,0 +1,56 @@
/******************************************************************
MIT License http://www.opensource.org/licenses/mit-license.php
Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm)
*******************************************************************/
const conditionRe = /\(\?\(\?:\w+\).+\|/
const bellRe = /\\a/
const commentRe = /\(\?#.*?\)/
const stringStartRe = /\\A/
const lookBehindRe = /\(\?<[!=].*?\)/
const namedCaptureRe = /\(\?P<\w+>.*?\)/
const namedReferenceRe = /\(\?P=(\w+)\)/
const braceRe = /\^\]/
const regex = new RegExp(`${bellRe.source}|${commentRe.source}|${stringStartRe.source}|${lookBehindRe.source}|${namedCaptureRe.source}|${namedReferenceRe.source}|${braceRe}`, 'g')
/**
* Convert python regex to javascript regex,
* throw error when unsupported pattern found
*
* @public
* @param {string} str
* @returns {string}
*/
exports.convertRegex = function(str) {
if (str.indexOf('\\z') !== -1) {
throw new Error('pattern \\z not supported')
}
if (str.indexOf('(?s)') !== -1) {
throw new Error('pattern (?s) not supported')
}
if (str.indexOf('(?x)') !== -1) {
throw new Error('pattern (?x) not supported')
}
if (str.indexOf('\n') !== -1) {
throw new Error('multiple line pattern not supported')
}
if (conditionRe.test(str)) {
throw new Error('condition pattern not supported')
}
return str.replace(regex, (match, p1) => {
if (match == '^]') return '^\\]'
if (match == '\\a') return ''
if (match.startsWith('(?#')) return ''
if (match == '\\A') return '^'
if (match.startsWith('(?<')) return '(?' + match.slice(3)
if (match.startsWith('(?P<')) return '(?' + match.slice(3)
if (match.startsWith('(?P=')) return `\\k<${p1}>`
return ''
})
}
exports.byteSlice = function (content, start, end) {
let buf = Buffer.from(content, 'utf8')
return buf.slice(start, end).toString('utf8')
}

View File

@ -0,0 +1,6 @@
{
"dependencies": {
"coc-json": ">=1.2.6",
"coc-vimtex": ">=1.0.3"
}
}