├── .npmignore ├── tsconfig.json ├── .eslintrc.js ├── src ├── completion.ts ├── index.ts └── list.ts ├── webpack.config.js ├── .github └── workflows │ └── ci.yml ├── README.md ├── package.json └── .gitignore /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | node_modules 3 | tsconfig.json 4 | tslint.json 5 | yarn.lock 6 | webpack.config.js 7 | package-lock.json 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/@voldikss/tsconfig/tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "outDir": "lib", 6 | "target": "es2015", 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "lib": ["es2018"], 10 | "plugins": [] 11 | }, 12 | "include": ["src"], 13 | "exclude": [] 14 | } 15 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | node: true, 4 | }, 5 | extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], 6 | parser: '@typescript-eslint/parser', 7 | parserOptions: { 8 | ecmaVersion: 2018, 9 | sourceType: 'module', 10 | }, 11 | plugins: ['@typescript-eslint'], 12 | rules: { 13 | '@typescript-eslint/explicit-function-return-type': 'off', 14 | '@typescript-eslint/no-explicit-any': 'off', 15 | '@typescript-eslint/no-non-null-assertion': 'off', 16 | '@typescript-eslint/no-empty-function': 'off', 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /src/completion.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CompletionItem, 3 | CompletionItemKind, 4 | CompletionItemProvider, 5 | Neovim, 6 | } from 'coc.nvim' 7 | 8 | export class FloatermCompletionProvider implements CompletionItemProvider { 9 | constructor(private nvim: Neovim) {} 10 | 11 | public async provideCompletionItems(): Promise { 12 | const words: string[] = [] 13 | const lines: string[] = await this.nvim.call('floaterm#buffer#getlines', [-1, 100]) 14 | 15 | lines.forEach(line => { 16 | const matches = line.match(/[0-9a-zA-Z_]{5,20}/g) 17 | if (matches) 18 | matches.forEach(word => { 19 | if (words && !words.includes(word)) 20 | words.push(word) 21 | }) 22 | }) 23 | 24 | return words.map(word => ({ 25 | label: word, 26 | kind: CompletionItemKind.Text, 27 | insertText: word 28 | })) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | commands, 3 | ExtensionContext, 4 | languages, 5 | listManager, 6 | workspace 7 | } from 'coc.nvim' 8 | import { FloatermCompletionProvider } from './completion' 9 | import Floaterm from './list' 10 | 11 | export async function activate(context: ExtensionContext): Promise { 12 | const { nvim } = workspace 13 | const { subscriptions } = context 14 | 15 | const config = workspace.getConfiguration('floaterm.completion') 16 | 17 | if (config.get('enable')) { 18 | subscriptions.push( 19 | languages.registerCompletionItemProvider( 20 | 'coc-floaterm', 21 | config.get('shortcut'), 22 | null, 23 | new FloatermCompletionProvider(nvim), 24 | [], 25 | config.get('priority') 26 | ) 27 | ) 28 | } 29 | 30 | subscriptions.push( 31 | listManager.registerList( 32 | new Floaterm(nvim) 33 | ) 34 | ) 35 | } 36 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | entry: './src/index.ts', 5 | target: 'node', 6 | mode: 'none', 7 | resolve: { 8 | mainFields: ['module', 'main'], 9 | extensions: ['.js', '.ts'] 10 | }, 11 | externals: { 12 | 'coc.nvim': 'commonjs coc.nvim' 13 | }, 14 | module: { 15 | rules: [ 16 | { 17 | test: /\.ts$/, 18 | exclude: /node_modules/, 19 | use: [ 20 | { 21 | loader: 'ts-loader', 22 | options: { 23 | compilerOptions: { 24 | sourceMap: true 25 | } 26 | } 27 | } 28 | ] 29 | } 30 | ] 31 | }, 32 | output: { 33 | path: path.join(__dirname, 'lib'), 34 | filename: 'index.js', 35 | libraryTarget: 'commonjs' 36 | }, 37 | plugins: [], 38 | node: { 39 | __dirname: false, 40 | __filename: false 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: publish 2 | 3 | on: push 4 | 5 | jobs: 6 | publish: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: Setup Node 11 | uses: actions/setup-node@v1 12 | with: 13 | node-version: '12.x' 14 | registry-url: 'https://registry.npmjs.org' 15 | - name: Build Package 16 | run: | 17 | npm install -g json 18 | npm install 19 | - name: Publish 20 | env: 21 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 22 | run: | 23 | pkgname=$(json name < package.json) 24 | localversion=$(json version < package.json) 25 | remoteversion=$(npm view ${pkgname} version) 26 | 27 | echo ${localversion} 28 | echo ${remoteversion} 29 | 30 | if [ ${localversion} \> ${remoteversion} ] 31 | then 32 | npm publish 33 | git config user.name github-actions 34 | git config user.email github-actions@github.com 35 | git tag -a ${localversion} -m v${localversion} 36 | git push --tags 37 | fi 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # coc-floaterm 2 | 3 | ![publish](https://github.com/voldikss/coc-floaterm/workflows/publish/badge.svg) 4 | [![npm version](https://badge.fury.io/js/coc-floaterm.svg)](https://badge.fury.io/js/coc-floaterm) 5 | 6 | coc.nvim extension for [vim-floaterm](https://github.com/voldikss/vim-floaterm) 7 | 8 | ![](https://user-images.githubusercontent.com/20282795/75005925-fcc27f80-54aa-11ea-832e-59ea5b02fc04.gif) 9 | 10 | # Use cases 11 | 12 | - CocList for all opened floaterms 13 | - Completion from opened floaterms 14 | 15 | ## Requirements 16 | 17 | - [coc.nvim](https://github.com/neoclide/coc.nvim) 18 | - [vim-floaterm](https://github.com/voldikss/vim-floaterm) 19 | 20 | ## Install 21 | 22 | ``` 23 | :CocInstall coc-floaterm 24 | ``` 25 | 26 | ## Configurations 27 | 28 | - `floaterm.completion.enable`: 29 | default: `true` 30 | 31 | - `floaterm.completion.shortcut`: 32 | default: `"floaterm"` 33 | 34 | - `floaterm.completion.priority`: 35 | default: `5` 36 | 37 | ## CocList 38 | 39 | Try `:CocList floaterm` 40 | 41 | - `open` 42 | - `preview` 43 | 44 | ## Commands 45 | 46 | Removed `:CocCommand floaterm.xxx` 47 | 48 | ## License 49 | 50 | MIT 51 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "coc-floaterm", 3 | "version": "0.2.2", 4 | "description": "CocList support for the floaterm", 5 | "main": "lib/index.js", 6 | "repository": { 7 | "url": "https://github.com/voldikss/coc-floaterm" 8 | }, 9 | "publisher": "voldikss", 10 | "keywords": [ 11 | "coc.nvim", 12 | "floaterm" 13 | ], 14 | "engines": { 15 | "coc": "^0.0.74" 16 | }, 17 | "scripts": { 18 | "clean": "rimraf lib", 19 | "watch": "webpack --watch", 20 | "build": "webpack", 21 | "prepare": "npx npm-run-all clean build" 22 | }, 23 | "activationEvents": [ 24 | "*" 25 | ], 26 | "contributes": { 27 | "configuration": { 28 | "type": "object", 29 | "properties": { 30 | "floaterm.completion.enable": { 31 | "type": "boolean", 32 | "default": true 33 | }, 34 | "floaterm.completion.shortcut": { 35 | "type": "string", 36 | "default": "floaterm" 37 | }, 38 | "floaterm.completion.priority": { 39 | "type": "number", 40 | "default": 5 41 | } 42 | } 43 | } 44 | }, 45 | "author": "dyzplus@gmail.com", 46 | "license": "MIT", 47 | "devDependencies": { 48 | "@voldikss/tsconfig": "^1.0.0", 49 | "@types/node": "^14.14.22", 50 | "@typescript-eslint/eslint-plugin": "^4.14.1", 51 | "@typescript-eslint/parser": "^4.14.1", 52 | "eslint": "^7.18.0", 53 | "coc.nvim": "^0.0.80", 54 | "colors": "^1.4.0", 55 | "rimraf": "^3.0.2", 56 | "ts-loader": "^8.0.14", 57 | "typescript": "^4.1.3", 58 | "webpack": "^5.18.0", 59 | "webpack-cli": "^4.4.0" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # For current directory only 2 | # ---------------------------------------------------------------------------- 3 | lib 4 | package-lock.json 5 | 6 | # General 7 | # ---------------------------------------------------------------------------- 8 | *.o 9 | *.out 10 | 11 | # log 12 | *.log 13 | 14 | # cache 15 | *.cache 16 | cache/ 17 | 18 | # Windows 19 | # ---------------------------------------------------------------------------- 20 | Thumbs.db 21 | Desktop.ini 22 | 23 | # Tags 24 | # ----------------------------------------------------------------------------- 25 | TAGS 26 | !TAGS/ 27 | tags 28 | tags-cn 29 | !tags/ 30 | .tags 31 | .tags1 32 | tags.lock 33 | tags.temp 34 | gtags.files 35 | GTAGS 36 | GRTAGS 37 | GPATH 38 | cscope.files 39 | cscope.out 40 | cscope.in.out 41 | cscope.po.out 42 | 43 | # Vim 44 | # ------------------------------------------------------------------------------ 45 | [._]*.s[a-w][a-z] 46 | [._]s[a-w][a-z] 47 | *.un~ 48 | Session.vim 49 | .netrwhist 50 | *~ 51 | 52 | # Test % Tmp 53 | # ------------------------------------------------------------------------------- 54 | test.* 55 | tmp.* 56 | temp.* 57 | 58 | # Java 59 | # ------------------------------------------------------------------------------- 60 | *.class 61 | 62 | # JavaScript 63 | # ------------------------------------------------------------------------------- 64 | node_modules 65 | 66 | # Python 67 | # ------------------------------------------------------------------------------- 68 | *.pyc 69 | .idea/ 70 | /.idea 71 | build/ 72 | __pycache__ 73 | 74 | # Rust 75 | # ------------------------------------------------------------------------------- 76 | target/ 77 | **/*.rs.bk 78 | -------------------------------------------------------------------------------- /src/list.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ListAction, 3 | ListItem, 4 | Neovim, 5 | BasicList 6 | } from 'coc.nvim' 7 | import colors from 'colors/safe' 8 | 9 | export default class Floaterm extends BasicList { 10 | public readonly name = 'floaterm' 11 | public readonly description = 'CocList for vim-floaterm' 12 | public readonly defaultAction = 'open' 13 | public actions: ListAction[] = [] 14 | 15 | constructor(nvim: Neovim) { 16 | super(nvim) 17 | 18 | this.addAction('open', async (item: ListItem) => { 19 | await this.nvim.call('floaterm#terminal#open_existing', item.data) 20 | }) 21 | 22 | this.addAction('preview', async (item: ListItem, context) => { 23 | const bufnr = item.data 24 | const lines: string[] = await this.nvim.call('floaterm#buffer#getlines', [bufnr, 10]) 25 | await this.preview({ 26 | sketch: true, 27 | filetype: 'floaterm_preview', 28 | lines 29 | }, context) 30 | }) 31 | } 32 | 33 | public async loadItems(): Promise { 34 | const list: ListItem[] = [] 35 | const loaded_floaterm = await this.nvim.eval('exists("*floaterm#buflist#gather")') 36 | if (loaded_floaterm.valueOf() == 0) return [] 37 | 38 | const buffers = await this.nvim.call('floaterm#buflist#gather') 39 | for (const bufnr of buffers) { 40 | const bufinfo = await this.nvim.call('getbufinfo', bufnr) 41 | const bufname = bufinfo[0]['name'] 42 | const term_title: string = await this.nvim.call('getbufvar', [bufnr, 'term_title']) 43 | list.push({ 44 | label: `${colors.cyan(bufnr.toString())} ${colors.yellow(bufname.toString())} ${colors.gray(term_title)}`, 45 | data: bufnr 46 | }) 47 | } 48 | return list 49 | } 50 | } 51 | --------------------------------------------------------------------------------