Skip to content

Commit

Permalink
Rewrite for LSP
Browse files Browse the repository at this point in the history
  • Loading branch information
cannorin committed Jul 13, 2019
1 parent 012d98c commit 885c1c9
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 1,310 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -3,6 +3,9 @@
*.pyc
tags
paket.exe
.paket
ftplugin/bin/
packages/
FsAutoComplete/*
fsac/
fsac.zip
9 changes: 5 additions & 4 deletions Makefile
@@ -1,16 +1,17 @@
# Directories

bin_d = $(abspath ftplugin/bin)
bin_d = $(abspath fsac)

# Installation paths.
#dest_root = $(HOME)/.vim/bundle/vim-fsharp/
#dest_bin = $(dest_root)/ftplugin/bin/

ac_exe = $(bin_d)/fsautocomplete.exe
ac_archive = fsautocomplete.zip
ac_version = 0.34.0
ac_archive = fsautocomplete.netcore.zip
ac_version = master
ac_url = https://github.com/fsharp/FSharp.AutoComplete/releases/download/$(ac_version)/$(ac_archive)

ac_url = https://ci.appveyor.com/api/projects/fsautocomplete/fsautocomplete/artifacts/bin/pkgs/$(ac_archive)?branch=$(ac_version)

git_url = https://github.com/fsharp/FsAutoComplete.git

# ----------------------------------------------------------------------------
Expand Down
211 changes: 40 additions & 171 deletions README.mkd
@@ -1,29 +1,37 @@
## F# support for Vim (vim-fsharp)
## F# support for Vim through LSP (vim-fsharp-languageclient)

Syntax and indent files have been copied from [fsharp-vim](http://github.com/kongo2002/fsharp-vim) with kind permissions from [kongo2002](https://github.com/kongo2002).
This is a modified version of [fsharp/vim-fsharp](https://github.com/fsharp/vim-fsharp) which uses LSP-mode of [FsAutoComplete](https://github.com/fsharp/FsAutoComplete) as a backend, and is powered by [autozimu/LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim).

> Requires vim 7.3 or higher compiled with python 2 or 3 support.
The original description is as follows:

This was adapted from http://github.com/timrobinson/fsharp-vim. The current aim is to provide a good experience for fsx scripting. On opening an fs or fsi file any project file found in the same directory will be parsed. Multiple projects are supported.
> Syntax and indent files have been copied from [fsharp-vim](http://github.com/kongo2002/fsharp-vim) with kind permissions from [kongo2002](https://github.com/kongo2002).
>
> > Requires vim 7.3 or higher compiled with python 2 or 3 support.
>
> This was adapted from http://github.com/timrobinson/fsharp-vim. The current aim is to provide a good experience for fsx scripting. On opening an fs or fsi file any project file found in the same directory will be parsed. Multiple projects are supported.
Note that this plugin does not require python support. Also, [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim) requires neovim or vim 8.0+.

### Installing

vim-fsharp requires mono and fsharp installed.
vim-fsharp-languageclient requires .NET Core Runtime installed. Also it depends on [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim), so make sure it's installed beforehand.

I have only tested vim-plug and _install.sh_(_install.cmd_ should also work).

#### OSX and linux

##### Installing with pathogen

1. Install [pathogen][pathogen] and [syntastic][syntastic]

2. Clone vim-fsharp into your bundle directory.
2. Clone vim-fsharp-languageclient into your bundle directory.

2. Run *make* inside the vim directory. This downloads the auto completion server.

##### Installing with [vim-plug][vim-plug]

~~~.vim
Plug 'fsharp/vim-fsharp', {
Plug 'cannorin/vim-fsharp-languageclient', {
\ 'for': 'fsharp',
\ 'do': 'make fsautocomplete',
\}
Expand All @@ -33,7 +41,7 @@ Plug 'fsharp/vim-fsharp', {

By VimL way:
~~~.vim
NeoBundle 'fsharp/vim-fsharp', {
NeoBundle 'cannorin/vim-fsharp-languageclient', {
\ 'description': 'F# support for Vim',
\ 'lazy': 1,
\ 'autoload': {'filetypes': 'fsharp'},
Expand All @@ -48,7 +56,7 @@ By using TOML configuration:
~~~.toml
[[plugins]]
description = 'F# support for Vim'
repository = 'fsharp/vim-fsharp'
repository = 'cannorin/vim-fsharp-languageclient'
lazy = 1
filetypes = 'fsharp'
build_commands = ['curl', 'make', 'mozroots', 'touch', 'unzip']
Expand All @@ -58,196 +66,57 @@ build_commands = ['curl', 'make', 'mozroots', 'touch', 'unzip']

#### Windows

1. Install [pathogen][pathogen] and [syntastic][syntastic]
1. Run _install.cmd_

2. Run _install.cmd_
### Setting up the language client

#### Syntastic
Once you installed, add the following to somewhere in your `.vimrc`:

vim-fsharp utilizes the [syntastic][syntastic] plugin in order to
supply interactive syntax and type checking. You may want to install that plugin
in order to get all of the fsharpbindings functionality.
```vim
let g:LanguageClient_serverCommands = {
\ 'fsharp': g:fsharp#languageserver_command
\ }
```

Moreover you benefit from additional [syntastic][syntastic] features like
optional integration in your status bar (i.e. [vim-airline][airline]).

All you have to do is to install [syntastic][syntastic] in your vim runtime path.
This will configure FSAC to be used from LanguageClient-neovim.

### Usage

Opening either `*.fs`, `*.fsi` or `*.fsx` files should trigger syntax highlighting and other depending runtime files as well.

Omnicomplete triggers the fsharp autocomplete process. (suggestion: install [supertab](https://github.com/ervandew/supertab))

### Commands

##### General
* `:make` Calls xbuild on the fsproj for the current file (if any).
* `:FSharpParseProject` Reparses all the project files and dependencies (this is done automatically when opening a .fs or .fsi file).
* `:FSharpBuildProject` Calls xbuild on the fsproj for the current file (if any). Can also take a path to the proj file to build.
* `:FSharpRunProject` Runs the project for the current file (if any).
* `:FSharpRunTests` If `g:fsharp_test_runner` is set it will build the current project and run any tests. (Currently only tested with nunit-console.exe)
* `:FSharpToggleHelptext` toggles g:fsharp_completion_helptext. (See below for details)
* `leader<t>` Echoes the type of the expression currently pointed to by the cursor.
* `leader<h>` Echoes the help info (type and comments) of the expression currently pointed to by the cursor.
* `leader<d>` _go to declaration_ in current window.
* `leader<s>` Takes you back from where _go to declaration_ was triggered. Experimental.

##### FSharp Interactive
* `:FsiEval` Evaluates an fsharp expression in the fsi
* `leader<e>` Same as FsiEval but from a vim command line
* `:FsiEvalBuffer` Evaluates the entire buffer in the fsi
* `:FsiReset` Resets the current fsharp interactive
* `:FsiRead` Outputs any lines written by the fsi but not yet output as vim messages
* `:FsiClear` Deletes all text from the fsi output buffer but doesn't reset the fsi session.
* `:FsiShow` Opens the _fsi-out_ buffer in a split window.
* `Alt-Enter` Send either the current selection or the current line to the fsharp interactive and echoes the output the first line of the output. All output will be written to the _fsi-out_ buffer.
* `leader<i>` Same as Alt-Enter

### On-the-fly syntax checking

> Interactive syntax/type checking requires vim 7.4 or higher and [syntastic][syntastic]
By default your F# files will be syntax/type checked on every open/save of a vim buffer as well as after 500ms of inactivity in Normal mode.
In case you would prefer not to have you errors checked continuously add the following to your vimrc:

~~~.vim
let g:fsharp_only_check_errors_on_write = 1
~~~
Refer to [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim) for features provided via Language Server Protocol.

In case you prefer to disable the syntax checker, add the following to your vimrc:
To be added as requested for F#-specific features.

~~~.vim
let g:syntastic_fsharp_checkers = ['']
~~~
##### General
* :FSharpLoadWorkspaceAuto` Guess a workspace (`sln` or `fsproj`) and then load it. Equivalent to `FSharp.workspaceMode = sln` in Ionide. Automatically called when you open F# files.
* `:FSharpParseProject <files>+` Load specified projects (`fsproj` or `sln`).
* `:FSharpReloadWorkspace` Reload all the projects currently loaded. Automatically called when you edit and save `.fsproj` files.

### Settings

You can enable *debug-mode* in order to inspect the fsautocomplete behavior by
setting the global vim variable `g:fsharpbinding_debug` to a non-zero value:

~~~.vim
let g:fsharpbinding_debug = 1
~~~

This will create two log files `log.txt` and `log2.txt` in your temporary folder
(i.e. `/tmp/`).

Override the default F# interactive binary

~~~.vim
let g:fsharp_interactive_bin = '/path/to/fsi'
~~~

You can set the msbuild/xbuild path.

~~~.vim
let g:fsharp_xbuild_path = "/path/to/xbuild/or/msbuild"
~~~

This setting needs to point to a suitable test runner (such as nunit-console.exe)

~~~.vim
let g:fsharp_test_runner = "/path/to/test/runner"
~~~

This enables the helptext to be displayed during auto completion. Turn off if completion is too slow.

~~~.vim
let g:fsharp_completion_helptext = 1
~~~

Show comments, in addition to type signature, when using Omni completion (default=0).

~~~.vim
let g:fsharp_helptext_comments = 1
~~~

If you find the default bindings unsuitable then it is possible to turn them off.

~~~.vim
let g:fsharp_map_keys = 0
~~~

It is also possible to configure them to provide a more customised experience.

Override the default prefix of `<leader>` to the keys `cp`

~~~.vim
let g:fsharp_map_prefix = 'cp'
~~~

Override the default mapping to send the current like to fsharp interactive

~~~.vim
let g:fsharp_map_fsisendline = 'p'
~~~

Override the default mapping to send the current selection to fsharp interactive

~~~.vim
let g:fsharp_map_fsisendsel = 'p'
~~~

Override the default mapping to go to declaration in the current window
Refer to [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim) for features provided via Language Server Protocol.

~~~.vim
let g:fsharp_map_gotodecl = 'g'
~~~

Override the default mapping to go back to where go to declaration was triggered

~~~.vim
let g:fsharp_map_gobackfromdecl = 'b'
~~~
To be added as requested for F#-specific features.

Override the default mapping to evaluate an fsharp expression in the fsi
Show the type signature at the cursor position (default: 1).

~~~.vim
let g:fsharp_map_fsiinput = 'i'
let g:fsharp#show_signature_on_cursor_move = 1 " 0 to disable.
~~~

Automatically open the result of an FsiEval (fsi-out buffer) in a vsplit window
Enable/disable automatic calling of `:FSharpLoadWorkspaceAuto`. (default: 1)

~~~.vim
let g:fsharp_fsi_show_auto_open = 1
let g:fsharp#automatic_workspace_init = 1 " 0 to disable.
~~~


### Troubleshooting

> I get syntax highlighting but not error checking and commands like :FsiEval are not found
Type
Enable/disable automatic calling of `:FSharpReloadWorkspace`. (default: 1)

~~~.vim
:SyntasticInfo
~~~

The "available" and "currently enabled" checkers should be listed as "syntax". If these entries are blank, then
the syntax checker has not been loaded properly. One cause can be that your vim is compiled without Python support; type

~~~
:echo has('python')
:echo has('python3')
let g:fsharp#automatic_reload_workspace = 1 " 0 to disable.
~~~

to check this.

If both of this commands return 0 and you're on Debian 8, you may need to install the package 'vim-python-jedi' instead of 'vim' to have Python support.

[syntastic]: https://github.com/scrooloose/syntastic
[airline]: https://github.com/bling/vim-airline
[pathogen]: https://github.com/tpope/vim-pathogen
[vim-plug]: https://github.com/junegunn/vim-plug
[NeoBundle]: https://github.com/Shougo/neobundle.vim

NB: if you in the past installed `fsharpbinding-vim` you need to remove this from the `bundles` directory. They don't play nicely together and `fsharpbinding-vim` is no longer developed.

Maintainers
-----------

Tha maintainers of this repository appointed by the F# Core Engineering Group are:

- [Robin Neatherway](https://github.com/rneatherway), [Steffen Forkmann](http://github.com/forki), [Karl Nilsson](http://github.com/kjnilsson), [Dave Thomas](http://github.com/7sharp9) and [Guillermo López-Anglada](http://github.com/guillermooo)
- The primary maintainer for this repository is [Karl Nilsson](http://github.com/kjnilsson)

0 comments on commit 885c1c9

Please sign in to comment.