Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
fannheyward committed Jul 8, 2019
0 parents commit 5e1bf0d
Show file tree
Hide file tree
Showing 9 changed files with 3,827 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib
node_modules/
server
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
src
node_modules
tsconfig.json
*.map
.tags
webpack.config.js
yarn.lock
server
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Heyward Fann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# coc-texlab

> fork of [texlab-vscode](https://github.com/latex-lsp/texlab-vscode), provides editing support for LaTeX documents, powered by the [TexLab](https://github.com/latex-lsp/texlab) language server.
## Install

`:CocInstall coc-texlab`

## Requirements

- A [TeX distribution](https://www.latex-project.org/get/#tex-distributions). All distributions that are based on [TeX Live](https://www.tug.org/texlive/) or [MikTeX](https://miktex.org/) are supported.
- The Node.js runtime. This is an optional dependency used for the citation rendering feature.
- On Windows, you will need to install [Microsoft Visual C++ Redistributable for Visual Studio 2015](https://aka.ms/vs/16/release/vc_redist.x64.exe).

More info in [TexLab Docs](https://texlab.netlify.com/docs)

## License

MIT
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "coc-texlab",
"version": "1.0.0",
"description": "TexLab extension for coc.nvim",
"main": "lib/index.js",
"author": "Heyward Fann <[email protected]>",
"license": "MIT",
"scripts": {
"clean": "rimraf lib",
"watch": "webpack --watch",
"build": "webpack",
"prepare": "npx npm-run-all clean build"
},
"keywords": [
"coc.nvim",
"latex",
"texlab"
],
"engines": {
"coc": "^0.0.70"
},
"devDependencies": {
"@types/node": "^12.0.4",
"@types/request": "^2.48.1",
"@types/tar": "^4.0.2",
"@types/unzipper": "^0.9.2",
"axios": "^0.19.0",
"coc.nvim": "^0.0.71",
"request": "^2.88.0",
"rimraf": "^2.6.3",
"tar": "^4.4.10",
"ts-loader": "^6.0.4",
"typescript": "^3.5.2",
"unzipper": "^0.10.1",
"webpack": "^4.35.0",
"webpack-cli": "^3.3.5"
},
"dependencies": {},
"prettier": {
"printWidth": 160,
"singleQuote": true
}
}
89 changes: 89 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import fs from 'fs';
import os from 'os';
import tar from 'tar';
import unzipper from 'unzipper';
import request from 'request';

import { ServerOptions, services, ExtensionContext, workspace, LanguageClientOptions, LanguageClient } from 'coc.nvim';

export async function activate(context: ExtensionContext): Promise<void> {
const serverPath = getServerPath(context);
if (!fs.existsSync(serverPath)) {
workspace.showMessage(`TexLab Server is not found, downloading...`);
try {
await downloadServer(context);
} catch (_e) {
workspace.showMessage(`Download TexLab failed`);
return;
}
}

const serverOptions = getServerOptions(serverPath);
const clientOptions: LanguageClientOptions = {
documentSelector: ['tex', 'latex', 'bib', 'bibtex'],
outputChannelName: 'LaTeX'
};

const client = new LanguageClient('TexLab', serverOptions, clientOptions);
context.subscriptions.push(services.registLanguageClient(client));

client.onReady().then(() => {
workspace.showMessage(`TexLab Server Started`);
});
}

function getServerPath(context: ExtensionContext): string {
const name = os.platform() === 'win32' ? 'texlab.exe' : 'texlab';
return context.asAbsolutePath(`./server/${name}`);
}

function getServerOptions(serverPath: string): ServerOptions {
const { ELECTRON_RUN_AS_NODE, ...env } = process.env;
return {
run: {
command: serverPath,
options: {
env
}
},
debug: {
command: serverPath,
args: ['-vvvv'],
options: {
env: {
...env,
RUST_BACKTRACE: '1'
}
}
}
};
}

async function downloadServer(context: ExtensionContext): Promise<void> {
const urls = {
win32: 'https://github.com/latex-lsp/texlab/releases/download/v1.0.0/texlab-x86_64-windows.zip',
linux: 'https://github.com/latex-lsp/texlab/releases/download/v1.0.0/texlab-x86_64-linux.tar.gz',
darwin: 'https://github.com/latex-lsp/texlab/releases/download/v1.0.0/texlab-x86_64-macos.tar.gz'
};

const url = urls[os.platform()];
const path = context.asAbsolutePath('server');
const extract = os.platform() === 'win32' ? () => unzipper.Extract({ path }) : () => tar.x({ C: path });

let statusItem = workspace.createStatusBarItem(0, { progress: true });
statusItem.text = 'Downloading TexLab Server';
statusItem.show();

return new Promise((resolve, reject) => {
request(url)
.pipe(extract())
.on('close', () => {
resolve();
statusItem.dispose();
})
.on('error', e => {
reject(e);
});
});
}

15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es2017",
"lib": ["es2017", "es2018"],
"module": "commonjs",
"declaration": false,
"sourceMap": true,
"outDir": "lib",
"strict": true,
"moduleResolution": "node",
"noImplicitAny": false,
"esModuleInterop": true
},
"include": ["src"]
}
42 changes: 42 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const path = require('path');

module.exports = {
entry: './src/index.ts',
target: 'node',
mode: 'none',
resolve: {
mainFields: ['module', 'main'],
extensions: ['.js', '.ts']
},
externals: {
'coc.nvim': 'commonjs coc.nvim'
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
sourceMap: true
}
}
}
]
}
]
},
output: {
path: path.join(__dirname, 'lib'),
filename: 'index.js',
libraryTarget: 'commonjs'
},
plugins: [],
node: {
__dirname: false,
__filename: false
}
};
Loading

0 comments on commit 5e1bf0d

Please sign in to comment.