1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 02:00:05 +08:00

Add coffeescript suport (#2521)

* Add coffeescript.vim

* Add lang#coffeescript layer

* Add post

* Update coffee ide post

* Fix image info

* Update coffeescript ide post

* Update layer list

* Fix format

* Fix type in doc
This commit is contained in:
Wang Shidong 2019-01-29 11:52:51 +08:00 committed by GitHub
parent dac32e1729
commit d388b33f2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 306 additions and 6 deletions

View File

@ -13,6 +13,8 @@
"wiki/cn/Following-HEAD.md": {"alternate": "wiki/en/Following-HEAD.md"},
"docs/_posts/2017-02-11-use-vim-as-a-java-ide.md": {"alternate": "docs/_posts/2018-09-19-use-vim-as-a-java-ide.md"},
"docs/_posts/2018-09-19-use-vim-as-a-java-ide.md": {"alternate": "docs/_posts/2017-02-11-use-vim-as-a-java-ide.md"},
"docs/_posts/2019-01-28-use-vim-as-a-coffeescript-ide.md": {"alternate": "docs/_posts/2019-01-29-use-vim-as-a-coffeescript-ide.md"},
"docs/_posts/2019-01-29-use-vim-as-a-coffeescript-ide.md": {"alternate": "docs/_posts/2019-01-28-use-vim-as-a-coffeescript-ide.md"},
"docs/_posts/2018-09-27-use-vim-as-a-python-ide.md": {"alternate": "docs/_posts/2018-09-28-use-vim-as-a-python-ide.md"},
"docs/_posts/2018-09-28-use-vim-as-a-python-ide.md": {"alternate": "docs/_posts/2018-09-27-use-vim-as-a-python-ide.md"},
"docs/_posts/2018-09-27-use-vim-as-ide.md": {"alternate": "docs/_posts/2018-09-28-use-vim-as-ide.md"},

View File

@ -0,0 +1,68 @@
"=============================================================================
" coffeescript.vim --- lang#coffeescript layer
" Copyright (c) 2016-2017 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg at 163.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
function! SpaceVim#layers#lang#coffeescript#plugins() abort
let plugins = []
call add(plugins, ['wsdjeg/vim-coffeescript', {'on_ft' : 'coffee'}])
return plugins
endfunction
function! SpaceVim#layers#lang#coffeescript#config() abort
call SpaceVim#plugins#runner#reg_runner('coffee', 'coffee %s')
call SpaceVim#plugins#repl#reg('coffee', 'coffee')
call SpaceVim#mapping#space#regesit_lang_mappings('coffee', function('s:language_specified_mappings'))
endfunction
function! s:language_specified_mappings() abort
call SpaceVim#mapping#space#langSPC('nmap', ['l','r'], 'call SpaceVim#plugins#runner#open()', 'execute current file', 1)
let g:_spacevim_mappings_space.l.s = {'name' : '+Send'}
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'i'],
\ 'call SpaceVim#plugins#repl#start("coffee")',
\ 'start REPL process', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'l'],
\ 'call SpaceVim#plugins#repl#send("line")',
\ 'send line and keep code buffer focused', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'b'],
\ 'call SpaceVim#plugins#repl#send("buffer")',
\ 'send buffer and keep code buffer focused', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 's'],
\ 'call SpaceVim#plugins#repl#send("selection")',
\ 'send selection and keep code buffer focused', 1)
let g:neomake_coffee_enabled_makers = ['coffee', 'coffeelint']
let g:neomake_coffee_coffeelint_maker = {
\ 'args': ['--reporter=csv'],
\ 'errorformat': '%f\,%l\,%\d%#\,%trror\,%m,' .
\ '%f\,%l\,%trror\,%m,' .
\ '%f\,%l\,%\d%#\,%tarn\,%m,' .
\ '%f\,%l\,%tarn\,%m'
\ }
let g:neomake_coffee_coffeelint_remove_invalid_entries = 1
let g:neomake_coffee_coffee_maker = {
\ 'args': [],
\ 'output_stream': 'stderr',
\ 'errorformat': '%f:%l:%c: %m',
\ }
let g:neomake_coffee_coffee_remove_invalid_entries = 1
" \ 'filter_output' : function('s:filter_coffee_lint'),
let g:neoformat_enabled_coffee = ['coffeefmt']
let g:neoformat_coffee_coffeefmt = {
\ 'exe': 'coffee-fmt',
\ 'args': ['--indent_stype', 'space', '-i'],
\ 'stdin': 0,
\ }
endfunction
function! s:filter_coffee_lint(lines, job) abort
let a:lines = []
endfunction

View File

@ -1,7 +1,7 @@
---
title: "Use Vim as a Lua IDE"
categories: [tutorials, blog]
images: https://user-images.githubusercontent.com/13142418/51436347-3502f780-1cc6-11e9-9ae1-02e1dfa1e165.png
image: https://user-images.githubusercontent.com/13142418/51436347-3502f780-1cc6-11e9-9ae1-02e1dfa1e165.png
excerpt: "A general guide for using SpaceVim as Lua IDE, including layer configuration, requiems installation and usage."
type: BlogPosting
comments: true

View File

@ -1,7 +1,7 @@
---
title: "使用 Vim 搭建 Lua 开发环境"
categories: [tutorials_cn, blog_cn]
images: https://user-images.githubusercontent.com/13142418/51436347-3502f780-1cc6-11e9-9ae1-02e1dfa1e165.png
image: https://user-images.githubusercontent.com/13142418/51436347-3502f780-1cc6-11e9-9ae1-02e1dfa1e165.png
excerpt: "这篇文章主要介绍如何使用 SpaceVim 搭建 Lua 的开发环境,简介 lang#lua 模块所支持的功能特性以及使用技巧"
permalink: /cn/:title/
lang: cn

View File

@ -0,0 +1,92 @@
---
title: "Use Vim as a CoffeeScript IDE"
categories: [tutorials, blog]
image: https://user-images.githubusercontent.com/13142418/51876268-fe526e80-23a2-11e9-8964-01fd62392a1f.png
excerpt: "A general guide for using SpaceVim as CoffeeScript IDE, including layer configuration, requiems installation and usage."
type: BlogPosting
comments: true
commentsID: "Use Vim as a CoffeeScript IDE"
---
# [Blogs](../blog/) >> Use Vim as a CoffeeScript IDE
This is a general guide for using SpaceVim as a [CoffeeScript](https://coffeescript.org/) IDE, including layer configuration and usage.
Each of the following sections will be covered:
<!-- vim-markdown-toc GFM -->
- [Enable language layer](#enable-language-layer)
- [Code completion](#code-completion)
- [Syntax linting](#syntax-linting)
- [Jump to test file](#jump-to-test-file)
- [running code](#running-code)
- [Code formatting](#code-formatting)
<!-- vim-markdown-toc -->
### Enable language layer
By default `lang#coffeescript` layer is not loaded. To add CoffeeScript language support in SpaceVim,
you need to enable the `lang#coffeescript` layer. Press `SPC f v d` to open
SpaceVim configuration file, and add following configuration:
```toml
[[layers]]
name = "lang#coffeescript"
```
for more info, you can read the [lang#coffeescript](../layers/lang/coffeescript/) layer documentation.
### Code completion
`lang#coffeescript` layer will load the vim-coffeescript plugin automatically, unless overriden in your `init.toml`.
The completion menu will be opened as you type.
![coffeeide](https://user-images.githubusercontent.com/13142418/51876268-fe526e80-23a2-11e9-8964-01fd62392a1f.png)
### Syntax linting
The checkers layer is enabled by default. This layer provides asynchronous syntax linting via [neomake](https://github.com/neomake/neomake).
It will run [coffeelint](https://github.com/clutchski/coffeelint) asynchronously.
The coffeelint is command line lint for coffeescript, currently is maintained by [Shuan Wang](https://github.com/swang).
To install coffeelint, just run following command in terminal.
```sh
npm install -g coffeelint
```
Note: if no coffeelint is installed, neomake will ues default command `coffee`.
![coffeecheckers](https://user-images.githubusercontent.com/13142418/51875890-bb43cb80-23a1-11e9-93b2-037e7120f5f2.png)
### Jump to test file
SpaceVim use built-in plugin to manager the files in a project,
you can add a `.project_alt.json` to the root of your project with following content:
```json
{
"src/*.coffee": {"alternate": "test/{}.coffee"},
"test/*.coffee": {"alternate": "src/{}.coffee"}
}
```
with this configuration, you can jump between the source code and test file via command `:A`.
### running code
To run current script, you can press `SPC l r`, and a split windows
will be openen, the output of the script will be shown in this windows.
It is running asynchronously, and will not block your vim.
![coffeerunner](https://user-images.githubusercontent.com/13142418/51877740-3f00b680-23a8-11e9-91ce-18cf147dbb95.png)
### Code formatting
The format layer is also enabled by default, with this layer you can use key binding `SPC b f` to format current buffer.
Before using this feature, please install coffee-fmt.
```sh
npm install -g coffee-fmt
```

View File

@ -0,0 +1,102 @@
---
title: "使用 Vim 搭建 CoffeeScript 开发环境"
categories: [tutorials_cn, blog_cn]
image: https://user-images.githubusercontent.com/13142418/51876268-fe526e80-23a2-11e9-8964-01fd62392a1f.png
excerpt: "这篇文章主要介绍如何使用 SpaceVim 搭建 CoffeeScript 的开发环境,简介 lang#coffeescript 模块所支持的功能特性以及使用技巧"
permalink: /cn/:title/
lang: cn
type: BlogPosting
comments: true
commentsID: "使用 Vim 搭建 CoffeeScript 开发环境"
---
# [Blogs](../blog/) >> 使用 Vim 搭建 CoffeeScript 开发环境
SpaceVim 是一个模块化的 Vim IDE针对 CoffeeScript 这一语言的支持主要依靠 `lang#coffeescript` 模块以及与之相关的其他模块。
的这篇文章主要介绍如何使用 SpaceVim 搭建 CoffeeScript 的开发环境,侧重介绍跟 CoffeeScript 开发相关使用技巧。
在阅读这篇文章之前,可以先阅读《[使用 Vim 搭建基础的开发环境](../use-vim-as-ide/)》,对语言相关以外的功能有一个大致的了解。
<!-- vim-markdown-toc GFM -->
- [安装模块](#安装模块)
- [代码自动补全](#代码自动补全)
- [语法检查](#语法检查)
- [工程文件跳转](#工程文件跳转)
- [快速运行](#快速运行)
- [代码格式化](#代码格式化)
<!-- vim-markdown-toc -->
### 安装模块
SpaceVim 初次安装时默认并未启用相关语言模块。首先需要启用
`lang#coffeescript` 模块, 通过快捷键 `SPC f v d` 打开配置文件,添加:
```toml
[[layers]]
name = "lang#coffeescript"
```
启用 `lang#coffeescript` 模块后,在打开 CoffeeScript 文件时,就可以使用语言专属快捷键,这些快捷键都是以 `SPC l` 为前缀的。
### 代码自动补全
`autocomplete` 模块为 SpaceVim 提供了自动补全功能,
该模块会根据当前环境自动在多种补全引擎之间选择合适的,
默认的补全引擎有deoplete、neocomplete、ycm、asyncomplete 以及 neocomplcache。
几种自动补全引擎当中,要数 deoplete 的体验效果最好。
![coffeeide](https://user-images.githubusercontent.com/13142418/51876268-fe526e80-23a2-11e9-8964-01fd62392a1f.png)
### 语法检查
`checkers` 模块为 SpaceVim 提供了语法检查的功能,该模块默认已经载入。该模块默认使用 [neomake](https://github.com/neomake/neomake)
这一异步语法检查工具。对于 CoffeeScript 的支持是通过异步调用 [coffeelint](https://github.com/clutchski/coffeelint) 命令来完成的。
`coffeelint` 是 CoffeeScript 命令行检测工具,目前由 [Shuan Wang](https://github.com/swang) 维护。可通过以下命令安装:
```sh
npm install -g coffeelint
```
值得注意的是,除了 coffeelint, CoffeeScript 本身的 coffee 命令也居于语法检查功能,在 SpaceVim 中若 coffeelint 未安装,
则默认使用 coffee 这一命令来异步检查语法。
![coffeecheckers](https://user-images.githubusercontent.com/13142418/51875890-bb43cb80-23a1-11e9-93b2-037e7120f5f2.png)
### 工程文件跳转
SpaceVim 自带工程管理插件可以识别项目根目录自动跳转alternate文件。
可以在工程根目录添加 `.project_alt.json` 文件,并加入以下内容:
```json
{
"src/*.coffee": {"alternate": "test/{}.coffee"},
"test/*.coffee": {"alternate": "src/{}.coffee"}
}
```
通过以上的配置,就可以使用命令 `:A` 在源文件和测试文件之间进行跳转。
### 快速运行
在编辑 CoffeeScript 文件时,可以快速运行当前文件,这个功能有点类似于 vscode 的 code runner 插件,默认的快捷键是 `SPC l r`。按下后,
会在屏幕下方打开一个插件窗口,运行的结果会被展示在窗口内。于此同时,光标并不会跳到该插件窗口,避免影响编辑。在这里需要说明下,
这一功能是根据当前文件的路径调用相对应的 `coffee` 命令。因此,在执行这个快捷键之前,应当先保存一下该文件。
![coffeerunner](https://user-images.githubusercontent.com/13142418/51877740-3f00b680-23a8-11e9-91ce-18cf147dbb95.png)
### 代码格式化
CoffeeScript 代码格式化,主要依赖 `format` 模块,同时需要安装相关的后台命令 `coffee-fmt`
```toml
[[layers]]
name = "format"
```
安装 `coffee-fmt`
```sh
npm install -g coffee-fmt
```

View File

@ -59,6 +59,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
| 名称 | 描述 |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| [VersionControl](VersionControl/) | 这一模块为 SpaceVim 提供了通用的代码版本控制支持,该模块支持 Git、Mercurial、Bazaar、SVN 等等多种后台工具。 |
| [autocomplete](autocomplete/) | 这一模块为 SpaceVim 提供了自动补全的框架,包括语法补全等多种补全来源,同时提供了代码块自动完成等特性。 |
| [chat](chat/) | 这一模块为 SpaceVim 提供了一个聊天框架,目前支持微信聊天和 QQ 聊天,同时支持自定义聊天服务器。 |
| [checkers](checkers/) | 这一模块为 SpaceVim 提供了代码语法检查的特性,同时提供代码实时检查,并列出语法错误的位置。 |
@ -80,6 +81,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
| [git](git/) | 这一模块为 SpaceVim 提供了 Git 支持,根据当前 Vim 版本特性,选择 gina 或者 gita 作为默认的后台 Git 插件。 |
| [github](github/) | 这一模块为 SpaceVim 提供了 Github 数据管理功能,包括问题列表、动态等管理。 |
| [japanese](japanese/) | 这一模块为 SpaceVim 的日文用户提供了日文的 Vim 帮助文档,同时提供部分插件的日文帮助文档。 |
| [lang#WebAssembly](lang/WebAssembly/) | 这一模块为 SpaceVim 提供了 WebAssembly 的开发支持。 |
| [lang#agda](lang/agda/) | 这一模块为 SpaceVim 提供了 Agda 的开发支持,主要包括语法高亮及一键运行。 |
| [lang#asciidoc](lang/asciidoc/) | 这一模块为 SpaceVim 提供了 AsciiDoc 的编辑支持,包括格式化、自动生成文章目录、代码块等特性。 |
| [lang#autohotkey](lang/autohotkey/) | 这一模块为 SpaceVim 提供了 Autohotkey 的开发支持,包括语法高亮和自动补全等功能。 |
@ -123,7 +125,6 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
| [lang#typescript](lang/typescript/) | 这一模块为 SpaceVim 提供了 Typescript 的开发支持,包括代码补全、语法检查、代码格式化等特性。 |
| [lang#vim](lang/vim/) | 这一模块为 SpaceVim 提供了 Vimscript 的开发支持,包括代码补全、语法检查、代码格式化等特性。 |
| [lang#vue](lang/vue/) | 这一模块为 SpaceVim 提供了 Vue 的的开发支持,包括代码补全、语法检查、代码格式化等特性。 |
| [lang#WebAssembly](lang/WebAssembly/) | 这一模块为 SpaceVim 提供了 WebAssembly 的开发支持。 |
| [language-server-protocol](language-server-protocol/) | 这一模块为 SpaceVim 提供了 language server protocol 的支持,提供更多语言相关服务。 |
| [leaderf](leaderf/) | 这一模块为 SpaceVim 提供了以 leaderf 为核心的异步模糊查找机制,支持模糊搜索文件、历史记录、函数列表等。 |
| [shell](shell/) | 这一模块为 SpaceVim 提供了终端集成特性,优化内置终端的使用体验。 |
@ -134,7 +135,6 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
| [tools](tools/) | 这一模块为 SpaceVim 提供了多种常用工具,包括日历、计算器等多种工具类插件,并针对 Vim8 以及 Neovim 提供了更好的插件选择。 |
| [ui](ui/) | 这一模块为 SpaceVim 提供了 IDE-like 的界面,包括状态栏、文件树、语法树等等特性。 |
| [unite](unite/) | 这一模块为 SpaceVim 提供以 unite 为核心的模糊查找机制,支持模糊搜索文件、历史纪录、函数列表等。 |
| [VersionControl](VersionControl/) | 这一模块为 SpaceVim 提供了通用的代码版本控制支持,该模块支持 Git、Mercurial、Bazaar、SVN 等等多种后台工具。 |
<!-- SpaceVim layer cn list end -->

View File

@ -65,6 +65,7 @@ Some layers are enabled by default. The following example shows how to disable `
| Name | Description |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [VersionControl](VersionControl/) | This layers provides general version control feature for vim. It should work with all VC backends such as Git, Mercurial, Bazaar, SVN, etc… |
| [autocomplete](autocomplete/) | Autocomplete code within SpaceVim, fuzzy find the candidates from multiple completion sources, expand snippet before cursor automatically |
| [chat](chat/) | SpaceVim chatting layer provide chatting with qq and weixin in vim. |
| [checkers](checkers/) | Syntax checking automatically within SpaceVim, display error on the sign column and statusline. |
@ -86,11 +87,13 @@ Some layers are enabled by default. The following example shows how to disable `
| [git](git/) | This layers adds extensive support for git |
| [github](github/) | This layer provides GitHub integration for SpaceVim |
| [japanese](japanese/) | Layer for japanese users, include japanese docs and runtime messages |
| [lang#WebAssembly](lang/WebAssembly/) | This layer adds WebAssembly support to SpaceVim |
| [lang#agda](lang/agda/) | This layer adds agda language support to SpaceVim |
| [lang#asciidoc](lang/asciidoc/) | Edit asciidoc within vim, autopreview asciidoc in the default browser, with this layer you can also format asciidoc file. |
| [lang#autohotkey](lang/autohotkey/) | This layer adds autohotkey language support to SpaceVim |
| [lang#c](lang/c/) | c/c++/object-c language support for SpaceVim, include code completion, jump to definition, quick runner. |
| [lang#clojure](lang/clojure/) | This layer is for clojure development, provide autocompletion, syntax checking, code format for clojure file. |
| [lang#coffeescript](lang/coffeescript/) | This layer is for coffeescript development, provide autocompletion, syntax checking, code format for coffeescript file. |
| [lang#csharp](lang/csharp/) | This layer is for csharp development |
| [lang#dart](lang/dart/) | This layer is for dart development, provide autocompletion, syntax checking, code format for dart file. |
| [lang#dockerfile](lang/dockerfile/) | This layer adds DockerFile to SpaceVim |
@ -130,7 +133,6 @@ Some layers are enabled by default. The following example shows how to disable `
| [lang#typescript](lang/typescript/) | This layer is for TypeScript development |
| [lang#vim](lang/vim/) | This layer is for writting vim script, including code completion, syntax checking and buffer formatting |
| [lang#vue](lang/vue/) | This layer adds vue language support to SpaceVim |
| [lang#WebAssembly](lang/WebAssembly/) | This layer adds WebAssembly support to SpaceVim |
| [language-server-protocol](language-server-protocol/) | This layers provides language server protocol for vim and neovim |
| [leaderf](leaderf/) | This layers provide a heavily customized LeaderF centric work-flow |
| [shell](shell/) | This layer provide shell support in SpaceVim |
@ -143,7 +145,6 @@ Some layers are enabled by default. The following example shows how to disable `
| [tools](tools/) | This layer provides some tools for vim |
| [ui](ui/) | Awesome UI layer for SpaceVim, provide IDE-like UI for neovim and vim in both TUI and GUI |
| [unite](unite/) | This layers provide a heavily customized Unite centric work-flow |
| [VersionControl](VersionControl/) | This layers provides general version control feature for vim. It should work with all VC backends such as Git, Mercurial, Bazaar, SVN, etc… |
<!-- SpaceVim layer list end -->

View File

@ -0,0 +1,35 @@
---
title: "SpaceVim lang#coffeescript layer"
description: "This layer is for coffeescript development, provide autocompletion, syntax checking, code format for coffeescript file."
---
# [Available Layers](../../) >> lang#coffeescript
<!-- vim-markdown-toc GFM -->
- [Description](#description)
- [Features](#features)
- [Install](#install)
<!-- vim-markdown-toc -->
## Description
This layer is for coffeescript development, and it includes vim-coffeescript.
## Features
- Code completion
- Syntax highlighting
- Indent
- Code formatting
- REPL support
## Install
To use this configuration layer, update custom configuration file with:
```toml
[[layers]]
name = "lang#coffeescript"
```