LoginSignup
4
2

More than 5 years have passed since last update.

vim, F# and lsp ( vimでF#を書いてみる)

Last updated at Posted at 2019-04-09

IMG_2165.jpeg


ネコと和解せよ


Summary

vimfsharpをかいてみる

Motivation

FCSを使った自作の補完エンジンを使ってたのですが、lspを使用した分を試しに使ったらいい感じだったので切り替えようと思いました

The Time required

15分ぐらい

Merit for lsp

サーバーを入れ替えるだけで他の言語(pythonとかtypescriptとか) も同様の機能を使える(と思う・・・

-> まだF#しか試してません・・・(すいません・・・

Environment

$ sw_vers 
ProductName:    Mac OS X
ProductVersion: 10.14.4
BuildVersion:   18E226

$ uname -a
Darwin callmekoheis-MacBook-Air.local 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64

Prepare

dotnet

もともと入れてる場合は brew cask upgrade dotnet-sdk もしくは brew cask uninstall dotnet-sdk

$ brew cask install dotnet-sdk
$ dotnet --version
2.2.105

macvim( Neovim, Vim お好みで )

$ brew install macvim
$ vim --version | head -n 1
VIM - Vi IMproved 8.1 (2018 May 18, compiled Feb 19 2019 12:07:03)

vim plugins(ここは自分のやりやすいように)

必要なのは3つ(vimだと5つ)

  1. fsharp-language-server (サーバー)
  2. LanguageClient-neovim (クライアント)
  3. deoplete.nvim (補完便利ツール)
$ cd .vim/
$ vim foo.bash
if [ ! -d pack/pack1/start/ ]; then
  mkdir -p pack/pack1/start
fi

cd pack/pack1/start

# FSharp
git clone --depth 1 https://github.com/fsprojects/fsharp-language-server
$(cd fsharp-language-server
  wget 'https://raw.githubusercontent.com/fsharp/vim-fsharp/master/syntax/fsharp.vim' -P './syntax/'
  npm install
  dotnet build -c Release)
git clone --depth 1 https://github.com/autozimu/LanguageClient-neovim
$(cd LanguageClient-neovim ; git checkout next ; bash install.sh )
git clone --depth 1 https://github.com/Shougo/deoplete.nvim
git clone --depth 1 https://github.com/roxma/nvim-yarp
git clone --depth 1 https://github.com/roxma/vim-hug-neovim-rpc
$ bash foo.bash

vimrc( keymap はお好みで )

autocmd BufNewFile,BufRead *.fs,*.fsi,*.fsx 

setlocal filetype=fsharp

let g:mapleader = "\<Space>"

" fsharp-language-server
" ( change your path )
let s:pathFslangServer = '/Users/callmekohei/dotfiles/vim/pack/pack1/start/fsharp-language-server/src/FSharpLanguageServer/bin/Release/netcoreapp2.0/FSharpLanguageServer.dll'

" LanguageClient-neovim
let g:LanguageClient_autoStart = 1
let g:LanguageClient_serverCommands = {'fsharp': ['dotnet', s:pathFslangServer ] }

nmap <silent> <nowait><Leader>d :call LanguageClient#textDocument_definition()<CR>
nmap <silent> <nowait> K :call LanguageClient#textDocument_hover()<CR>

" deoplete( with yarp )
let g:deoplete#enable_at_startup = 1

Check

# foo フォルダを作成
$ mkdir foo/

# foo.fsx ファイルを作成
$ touch foo.fsx

# List.と入力する
$ vim foo.fsx
    List.

5秒ほど待って下記の画面になったらオーケー

Screen Shot 2019-04-09 at 10.24.33.png

Usage

Autocomplete

文字を入力するだけ

Screen Shot 2019-04-09 at 10.26.15.png

Go-to-definition

Space + d で定義元にジャンプ
Ctrl  + o で元のとこに戻る

foo の上で Space + d

Screen Shot 2019-04-09 at 10.30.07.png

foo関数にジャンプ!

Screen Shot 2019-04-09 at 10.30.27.png

definition (Hover)

調べたい文字の上で K(大文字のk)

RegularExpressions の上で K

Screen Shot 2019-04-09 at 10.38.08.png

上窓ででるやつも・・・

bar の上で K

Screen Shot 2019-04-09 at 10.38.19.png

留意点

フォルダを作って、かつファイルを作ってからでないと、うまく動かない
-> ファイル単体では動作しない
-> プロジェクトフォルダ管理を前提とした作りとなっている

Hoverをいい感じに動作させるにはあとひとひねり必要な感じ
-> どなたかよかったら教えてください!

他にもいろいろ機能ありそう

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2