From fcb88b6ed583955313c992fe975cad0767ceb2e1 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Sat, 26 Sep 2020 11:14:25 +0800 Subject: [PATCH] Update kotlin doc (#3840) --- autoload/SpaceVim.vim | 15 +- autoload/SpaceVim/layers/core/statusline.vim | 5 + autoload/SpaceVim/layers/core/tabline.vim | 2 +- autoload/SpaceVim/layers/lang/kotlin.vim | 6 +- doc/SpaceVim.txt | 31 ++-- .../2020-09-24-use-vim-as-a-kotlin-ide.md | 132 ++++++++++++++++++ .../2020-09-25-use-vim-as-a-kotlin-ide.md | 111 +++++++++++++++ docs/layers/lang/kotlin.md | 30 +++- 8 files changed, 318 insertions(+), 14 deletions(-) create mode 100644 docs/_posts/2020-09-24-use-vim-as-a-kotlin-ide.md create mode 100644 docs/_posts/2020-09-25-use-vim-as-a-kotlin-ide.md diff --git a/autoload/SpaceVim.vim b/autoload/SpaceVim.vim index 38f5fd292..163c4f792 100644 --- a/autoload/SpaceVim.vim +++ b/autoload/SpaceVim.vim @@ -560,7 +560,20 @@ let g:spacevim_statusline_left_sections = ['winnr', 'filename', 'major mode', let g:spacevim_statusline_right_sections = ['fileformat', 'cursorpos', 'percentage'] "" -" Enable/Disable unicode symbols in statusline +" @section statusline_unicode_symbols, options-statusline_unicode_symbols +" @parentsection options +" Enable/Disable unicode symbols in statusline, includes the mode icons and +" fileformat icons. This option is enabled by default, to disable it: +" > +" statusline_unicode_symbols = false +" < + +"" +" Enable/Disable unicode symbols in statusline, includes the mode icons and +" fileformat icons. This option is enabled by default, to disable it: +" > +" let g:spacevim_statusline_unicode_symbols = 0 +" < let g:spacevim_statusline_unicode_symbols = 1 "" " Enable/Disable language specific leader, by default you can use `,` ket diff --git a/autoload/SpaceVim/layers/core/statusline.vim b/autoload/SpaceVim/layers/core/statusline.vim index ba7e95fb3..ab8010218 100644 --- a/autoload/SpaceVim/layers/core/statusline.vim +++ b/autoload/SpaceVim/layers/core/statusline.vim @@ -30,6 +30,10 @@ let s:ICON = SpaceVim#api#import('unicode#icon') let s:VIM = SpaceVim#api#import('vim') " init +" " the separators icons: +" +" arrow : +" active: let s:separators = { \ 'arrow' : ["\ue0b0", "\ue0b2"], \ 'curve' : ["\ue0b4", "\ue0b6"], @@ -40,6 +44,7 @@ let s:separators = { \ } let s:i_separators = { \ 'arrow' : ["\ue0b1", "\ue0b3"], + \ 'slant' : ["\ue0b9", "\ue0bb"], \ 'bar' : ['|', '|'], \ 'nil' : ['', ''], \ } diff --git a/autoload/SpaceVim/layers/core/tabline.vim b/autoload/SpaceVim/layers/core/tabline.vim index 0f9d1225d..576d293f5 100644 --- a/autoload/SpaceVim/layers/core/tabline.vim +++ b/autoload/SpaceVim/layers/core/tabline.vim @@ -47,9 +47,9 @@ let s:separators = { \ 'fire' : ["\ue0c0", "\ue0c2"], \ 'nil' : ['', ''], \ } - let s:i_separators = { \ 'arrow' : ["\ue0b1", "\ue0b3"], + \ 'slant' : ["\ue0b9", "\ue0bb"], \ 'bar' : ['|', '|'], \ 'nil' : ['', ''], \ } diff --git a/autoload/SpaceVim/layers/lang/kotlin.vim b/autoload/SpaceVim/layers/lang/kotlin.vim index b97306655..08bbd89e1 100644 --- a/autoload/SpaceVim/layers/lang/kotlin.vim +++ b/autoload/SpaceVim/layers/lang/kotlin.vim @@ -69,7 +69,7 @@ function! SpaceVim#layers#lang#kotlin#config() abort call SpaceVim#mapping#space#regesit_lang_mappings('kotlin', function('s:language_specified_mappings')) if s:enable_native_support let runner = { - \ 'exe' : 'kotlinc-native'. (s:SYS.isWindows ? '.BAT' : ''), + \ 'exe' : 'kotlinc-native'. (s:SYS.isWindows ? '.CMD' : ''), \ 'targetopt' : '-o', \ 'opt' : [], \ 'usestdin' : 0, @@ -77,13 +77,13 @@ function! SpaceVim#layers#lang#kotlin#config() abort call SpaceVim#plugins#runner#reg_runner('kotlin', [runner, '#TEMP#']) else let runner = { - \ 'exe' : 'kotlinc-jvm'. (s:SYS.isWindows ? '.BAT' : ''), + \ 'exe' : 'kotlinc-jvm'. (s:SYS.isWindows ? '.CMD' : ''), \ 'opt' : ['-script'], \ 'usestdin' : 0, \ } call SpaceVim#plugins#runner#reg_runner('kotlin', runner) endif - call SpaceVim#plugins#repl#reg('kotlin', ['kotlinc-jvm'. (s:SYS.isWindows ? '.BAT' : '')]) + call SpaceVim#plugins#repl#reg('kotlin', ['kotlinc-jvm'. (s:SYS.isWindows ? '.CMD' : '')]) endfunction function! s:language_specified_mappings() abort diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index f93b9f54b..84ac75cbc 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -64,13 +64,15 @@ CONTENTS *SpaceVim-contents* 44. statusline_iseparator.......|SpaceVim-options-statusline_iseparator| 45. statusline_left_sections.|SpaceVim-options-statusline_left_sections| 46. statusline_separator.........|SpaceVim-options-statusline_separator| - 47. terminal_cursor_shape.......|SpaceVim-options-terminal_cursor_shape| - 48. vim_help_language...............|SpaceVim-options-vim_help_language| - 49. vimcompatible.......................|SpaceVim-options-vimcompatible| - 50. warning_symbol.....................|SpaceVim-options-warning_symbol| - 51. windows_index_type.............|SpaceVim-options-windows_index_type| - 52. windows_leader.....................|SpaceVim-options-windows_leader| - 53. windows_smartclose.............|SpaceVim-options-windows_smartclose| + 47. statusline_unicode_symbols +.................................|SpaceVim-options-statusline_unicode_symbols| + 48. terminal_cursor_shape.......|SpaceVim-options-terminal_cursor_shape| + 49. vim_help_language...............|SpaceVim-options-vim_help_language| + 50. vimcompatible.......................|SpaceVim-options-vimcompatible| + 51. warning_symbol.....................|SpaceVim-options-warning_symbol| + 52. windows_index_type.............|SpaceVim-options-windows_index_type| + 53. windows_leader.....................|SpaceVim-options-windows_leader| + 54. windows_smartclose.............|SpaceVim-options-windows_smartclose| 3. Configuration...........................................|SpaceVim-config| 4. Commands..............................................|SpaceVim-commands| 5. Functions............................................|SpaceVim-functions| @@ -615,6 +617,15 @@ Set the statusline separators of statusline, default is 'nil' See more details in: http://spacevim.org/documentation/#statusline +============================================================================== +STATUSLINE_UNICODE_SYMBOLS *SpaceVim-options-statusline_unicode_symbols* + +Enable/Disable unicode symbols in statusline, includes the mode icons and +fileformat icons. This option is enabled by default, to disable it: +> + statusline_unicode_symbols = false +< + ============================================================================== TERMINAL_CURSOR_SHAPE *SpaceVim-options-terminal_cursor_shape* @@ -918,7 +929,11 @@ Define the right section of statusline in active windows. By default: < *g:spacevim_statusline_unicode_symbols* -Enable/Disable unicode symbols in statusline +Enable/Disable unicode symbols in statusline, includes the mode icons and +fileformat icons. This option is enabled by default, to disable it: +> + let g:spacevim_statusline_unicode_symbols = 0 +< *g:spacevim_enable_language_specific_leader* Enable/Disable language specific leader, by default you can use `,` ket diff --git a/docs/_posts/2020-09-24-use-vim-as-a-kotlin-ide.md b/docs/_posts/2020-09-24-use-vim-as-a-kotlin-ide.md new file mode 100644 index 000000000..c5a0b9e98 --- /dev/null +++ b/docs/_posts/2020-09-24-use-vim-as-a-kotlin-ide.md @@ -0,0 +1,132 @@ +--- +title: "使用 Vim 搭建 Kotlin 开发环境" +categories: [tutorials_cn, blog_cn] +image: https://user-images.githubusercontent.com/13142418/94328509-cbcc9f00-ffe5-11ea-8f0d-9ea7b5b81352.png +description: "使用 SpaceVim 搭建 Kotlin 的开发环境,简介 lang#kotlin 模块所支持的功能特性以及使用技巧" +permalink: /cn/:title/ +lang: zh +type: article +comments: true +commentsID: "使用 Vim 搭建 Kotlin 开发环境" +--- + +# [Blogs](../blog/) >> 使用 Vim 搭建 Kotlin 开发环境 + +本文主要介绍了使用 `SpaceVim` 搭建 `kotlin` 语言开发环境的基本流程,以及所包含的功能。 +`lang#kotlin` 模块提供了 `kotlin` 语言开发的基础环境,包括语法高亮、自动补全、语法检查、格式化等功能。 +在阅读这篇文章之前,可以先阅读《[使用 Vim 搭建基础的开发环境](../use-vim-as-ide/)》, +对 `SpaceVim` 的基本使用有一个大致的了解。 + + + +- [安装模块](#安装模块) +- [代码自动补全](#代码自动补全) +- [语法检查](#语法检查) +- [工程文件跳转](#工程文件跳转) +- [快速运行](#快速运行) +- [代码格式化](#代码格式化) +- [交互式编程](#交互式编程) +- [任务管理](#任务管理) + + + +### 安装模块 + +SpaceVim 初次安装时默认并未启用相关语言模块。因此,首先需要启用 +`lang#kotlin` 模块,通过快捷键 `SPC f v d` 打开配置文件,添加如下片断: + +```toml +[[layers]] + name = "lang#kotlin" +``` + +启用 `lang#kotlin` 模块后,在打开 Kotlin 文件时,就可以使用语言专属快捷键,这些快捷键都是以 `SPC l` 为前缀的。 + +### 代码自动补全 + +`autocomplete` 模块为 SpaceVim 提供了自动补全功能,目前针对 Kotlin 而言,比较好的补全方案是配合使用 lsp 模块: + +```toml +[[layers]] + name = 'lsp' + filetypes = [ + 'kotlin', + ] +``` + +lsp 模块默认使用 `kotlin-language-server` 作为 Kotlin 的语言服务器后台命令,首先需要安装 kotlin-language-server. +如果 `kotlin-language-server` 这一命令不在 `$PATH` 内,可以修改 kotlin 语言服务器命令为完整路径: + +```toml +[[layers]] + name = 'lsp' + filetypes = [ + 'kotlin', + ] + [layers.override_cmd] + kotlin = 'path/to/kotlin-language-server' +``` + +### 语法检查 + +`checkers` 模块为 SpaceVim 提供了语法检查的功能,该模块默认已经载入。该模块默认使用 [neomake](https://github.com/neomake/neomake) +这一异步语法检查工具。对于 Kotlin 的支持,是通过异步调用 `kotlinc` 命令来完成的。 + +### 工程文件跳转 + +SpaceVim 自带工程管理插件,可以识别项目根目录,自动跳转 alternate 文件。需要在项目根目录添加工程文件 `.project_alt.json`: + +```json +{ + "src/*.kt": { "alternate": "test/{}.kt" }, + "test/*.kt": { "alternate": "src/{}.kt" } +} +``` + +通过以上的配置,就可以使用命令 `:A` 在源文件和测试文件之间进行跳转。 + +### 快速运行 + +在编辑 `kotlin` 文件时,可以快速运行当前文件,这个功能有点类似于 vscode 的 code runner 插件,默认的快捷键是 `SPC l r` 。按下后, +会在屏幕下方打开一个插件窗口,运行的结果会被展示在窗口内。于此同时,光标并不会跳到该插件窗口,避免影响编辑。在这里需要说明下, +这一功能是根据当前 buffer 内容调用 Kotlin 命令。因此,在执行这个快捷键之前,不一定要保存该文件。 + +![kotlin-runner](https://user-images.githubusercontent.com/13142418/94288524-14566f00-ff8a-11ea-8440-ee9ca8ba8843.png) + +### 代码格式化 + +Kotlin 代码格式化,主要依赖 `format` 模块,同时需要安装相关的后台命令 [prettier](https://prettier.io/),默认快捷键为 `SPC b f` : + +```toml +[[layers]] + name = "format" +``` + +使用 npm 安装 prettier: + +``` +npm install --save-dev --save-exact prettier +``` + +### 交互式编程 + +在编辑 Kotlin 文件时,可通过快捷键 `SPC l s i` 启动 `kotlinc-jvm` 交互窗口, +之后使用快捷键将代码发送至解释器。默认快捷键都以 `SPC l s` 为前缀。 + +![kotlin-repl](https://user-images.githubusercontent.com/13142418/94289606-84192980-ff8b-11ea-84c8-1547741f377c.png) + +### 任务管理 + +在项目根目录新建 `.SpaceVim.d/task.toml` 文件,将常用的任务命令加入其中,示例如下: + +```toml +[gradle-build] + command = 'gradlew' + args = ['build'] +``` + +更多关于任务管理的配置教程,可以阅读 [task 文档](../documentation/#任务管理) + + +这篇文章还未完结,新的内容后续会继续更新,如果想要帮助改善这篇文章, +可以加入 [SpaceVim 中文聊天室](https://gitter.im/SpaceVim/cn) 一起交流。 diff --git a/docs/_posts/2020-09-25-use-vim-as-a-kotlin-ide.md b/docs/_posts/2020-09-25-use-vim-as-a-kotlin-ide.md new file mode 100644 index 000000000..46fe0e3ad --- /dev/null +++ b/docs/_posts/2020-09-25-use-vim-as-a-kotlin-ide.md @@ -0,0 +1,111 @@ +--- +title: "Use Vim as a Kotlin IDE" +categories: [tutorials, blog] +image: https://user-images.githubusercontent.com/13142418/94328509-cbcc9f00-ffe5-11ea-8f0d-9ea7b5b81352.png +description: "A general guide for using SpaceVim as Kotlin IDE, including layer configuration, requiems installation and usage." +type: article +comments: true +commentsID: "Use Vim as a Kotlin IDE" +--- + +# [Blogs](../blog/) >> Use Vim as a Kotlin IDE + +This is a general guide for using SpaceVim as a Kotlin IDE, including layer configuration and usage. +Each of the following sections will be covered: + + + + +- [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) +- [REPL support](#repl-support) +- [Tasks manager](#tasks-manager) + + + +### Enable language layer + +To add Kotlin language support in SpaceVim, you need to enable the `lang#kotlin` layer. Press `SPC f v d` to open +SpaceVim configuration file, and add the following snippet: + +```toml +[[layers]] + name = "lang#kotlin" +``` + +For more info, you can read the [lang#kotlin](../layers/lang/kotlin/) layer documentation. + +### Code completion + +`lang#kotlin` layer will load the Kotlin plugin automatically, unless it's overriden in your `init.toml`. +The completion menu will be opened as you type. + +![rubycomplete](https://user-images.githubusercontent.com/13142418/53355518-20202080-3964-11e9-92f3-476060f2761e.png) + +### Syntax linting + +The [checkers](../checkers/) layer is enabled by default. +This layer provides asynchronous syntax linting via [neomake](https://github.com/neomake/neomake). +It will run `kotlinc` asynchronously. + +### Jump to test file + +To manager the alternate files in a project, you need to current a `.project_alt.json` in the root of your project. +Within the `.project_alt.json` file, the definitions of alternate files should be included. + +For example: + +```json +{ + "src/*.kt": {"alternate": "test/{}.kt"}, + "test/*.kt": {"alternate": "src/{}.kt"} +} +``` + +With this configuration, you can jump between the source code and test file via command `:A` + +### running code + +To run current kotlin script, you can press `SPC l r`, and a split window +will be openen, the output of the script will be shown in this window. +It is running asynchronously, and will not block your Vim. + +![kotlin-runner](https://user-images.githubusercontent.com/13142418/94288524-14566f00-ff8a-11ea-8440-ee9ca8ba8843.png) + +### Code formatting + +The [format](../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 [prettier](https://prettier.io/): + +``` +npm install --save-dev --save-exact prettier +``` + +### REPL support + +Start a `kotlinc-jvm` inferior REPL process with `SPC l s i`. After the REPL process being started, you can +send code to inferior process. All key bindings prefix with `SPC l s`, including sending line, sending selection or even +send whole buffer. + +![kotlin-repl](https://user-images.githubusercontent.com/13142418/94289606-84192980-ff8b-11ea-84c8-1547741f377c.png) + +### Tasks manager + +Create `.SpaceVim.d/task.toml` file in the root of your project. and add all the task command into it. + +```toml +[gradle-build] + command = 'gradlew' + args = ['build'] +``` + +For more info about task configuration, please checkout the [task documentation](../documentation/#task) + + +This article is not finished yet and new content will be updated in the future. +If you want to help improve this article, please join the SpaceVim [gitter room](https://gitter.im/SpaceVim/SpaceVim). diff --git a/docs/layers/lang/kotlin.md b/docs/layers/lang/kotlin.md index 982dc3870..ae1d65f79 100644 --- a/docs/layers/lang/kotlin.md +++ b/docs/layers/lang/kotlin.md @@ -14,6 +14,7 @@ description: "This layer adds Kotlin language support to SpaceVim, including syn - [Key bindings](#key-bindings) - [Inferior REPL process](#inferior-repl-process) - [Running current file](#running-current-file) +- [Language Server Protocol](#language-server-protocol) @@ -63,4 +64,31 @@ Send code to inferior process commands: ### Running current file -To running current file, you can press `SPC l r` to run current file without loss focus, and the result will be shown in a runner buffer. +To running current file, you can press `SPC l r` to run current file without loss focus, +and the result will be shown in a runner buffer. + +## Language Server Protocol + +To enable lsp support for kotlin, you need to load the [lsp](../language-server-protocol/) layer, and include `kotlin` filetype: + +```toml +[[layers]] + name = 'lsp' + filetypes = [ + 'kotlin', + ] +``` + +The default language server command for kotlin is `kotlin-language-server`. +If the language server command is not in your `$PATH`, you can override the +kotlin language server command via: + +```toml +[[layers]] + name = 'lsp' + filetypes = [ + 'kotlin', + ] + [layers.override_cmd] + kotlin = 'path/to/kotlin-language-server' +```