1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:50:05 +08:00

Improve kotlin support (#2573)

* Improve kotlin support

* Update kotlin layer doc

* Update kotlin support
This commit is contained in:
Wang Shidong 2019-02-11 21:16:00 +08:00 committed by GitHub
parent 6b9e4f65da
commit af636208cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 2 deletions

View File

@ -12,6 +12,13 @@
" This layer is for kotlin development.
" Load SpaceVim APIs:
let s:SYS = SpaceVim#api#import('system')
" Default Options:
let s:enable_native_support = 0
function! SpaceVim#layers#lang#kotlin#plugins() abort
let plugins = []
call add(plugins, ['udalov/kotlin-vim', {'merged' : 0}])
@ -33,6 +40,23 @@ function! SpaceVim#layers#lang#kotlin#config() abort
let g:neomake_kotlin_enabled_makers = ['kotlinc']
endif
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' : ''),
\ 'targetopt' : '-o',
\ 'opt' : [],
\ 'usestdin' : 0,
\ }
call SpaceVim#plugins#runner#reg_runner('kotlin', [runner, '#TEMP#'])
else
let runner = {
\ 'exe' : 'kotlinc-jvm'. (s:SYS.isWindows ? '.BAT' : ''),
\ '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' : '')])
endfunction
function! s:language_specified_mappings() abort
@ -44,6 +68,20 @@ function! s:language_specified_mappings() abort
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'],
\ 'call SpaceVim#lsp#rename()', 'rename symbol', 1)
endif
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("kotlin")',
\ '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)
endfunction
func! s:classpath() abort
@ -53,3 +91,8 @@ func! s:outputdir() abort
endf
function! SpaceVim#layers#lang#kotlin#set_variable(var) abort
let s:enable_native_support = get(a:var,
\ 'enable-native-support',
\ 'nil')
endfunction

View File

@ -11,6 +11,9 @@ lang: cn
- [模块简介](#模块简介)
- [功能特性](#功能特性)
- [启用模块](#启用模块)
- [快捷键](#快捷键)
- [交互式编程](#交互式编程)
- [运行当前文件](#运行当前文件)
<!-- vim-markdown-toc -->
@ -22,7 +25,8 @@ lang: cn
- 语法高亮
- 语言服务器支持(需要启用 [lsp](https://spacevim.org/layers/language-server-protocol/) 模块)
- 一键运行
- 交互式编程
## 启用模块
@ -35,4 +39,21 @@ lang: cn
若需要启用语言服务器支持,需要额外安装 Kotlin 的语言服务器 [KotlinLanguageServer](https://github.com/fwcd/KotlinLanguageServer)。
## 快捷键
### 交互式编程
启动 `kotlinc-jvm` 交互进程,快捷键为: `SPC l s i`
将代码传输给 REPL 进程执行:
| 快捷键 | 功能描述 |
| ----------- | ----------------------- |
| `SPC l s b` | 发送整个文件内容至 REPL |
| `SPC l s l` | 发送当前行内容至 REPL |
| `SPC l s s` | 发送已选中的内容至 REPL |
### 运行当前文件
在编辑 kotlin 文件时,可通过快捷键 `SPC l r` 快速异步运行当前文件,运行结果会展示在一个独立的执行窗口内。

View File

@ -1,6 +1,6 @@
---
title: "SpaceVim lang#kotlin layer"
description: "This layer adds Kotlin language support to SpaceVim"
description: "This layer adds Kotlin language support to SpaceVim, including syntax highlighting, code runner and REPL support."
---
# [Available Layers](../../) >> lang#kotlin
@ -10,6 +10,10 @@ description: "This layer adds Kotlin language support to SpaceVim"
- [Description](#description)
- [Features](#features)
- [Install](#install)
- [Layer options](#layer-options)
- [Key bindings](#key-bindings)
- [Inferior REPL process](#inferior-repl-process)
- [Running current file](#running-current-file)
<!-- vim-markdown-toc -->
@ -21,6 +25,8 @@ This layer adds Kotlin language support to SpaceVim.
- syntax highlighting
- lsp support (require [lsp](https://spacevim.org/layers/language-server-protocol/) layer)
- code runner
- REPL support
## Install
@ -34,3 +40,27 @@ To use this configuration layer, update custom configuration file with:
To enable language server protocol, you need to install:
https://github.com/fwcd/KotlinLanguageServer
## Layer options
- `enable-native-support`: Enable/Disable kotlin native support, disabled by default.
When native support is enabled, the code runner will use `kotlinc-native`, otherwise it will use `kotlinc-jvm`.
## Key bindings
### Inferior REPL process
Start a `kotlinc-jvm` inferior REPL process with `SPC l s i`.
Send code to inferior process commands:
| Key Bindings | Descriptions |
| ------------ | ------------------------------------------------ |
| `SPC l s b` | send buffer and keep code buffer focused |
| `SPC l s l` | send line and keep code buffer focused |
| `SPC l s s` | send selection text and keep code buffer focused |
### 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.