1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

関数型の言語に興味があり、なんやかんやあってF#をはじめることにした。
エディタはNeovimを使用しており、補完やハイライトまわりでハマったが、ネット上に情報が少なく苦労したため自分の環境構築をまとめておく。

最初はIonide-vimを使用する方針で進めていたが、補完がうまくいかなかったため断念した。
このプラグインでうまくいくならそれに越したことはないので、まずはこちらのプラグインを試すことをオススメする。

環境

  • Arch Linux
  • tree-sitter: 0.26.5
  • Neovim v0.11.2
    • LSPクライアント: coc.nvim
    • nvim-treesitter: mainブランチ
  • .NET SDK 10.0.103

LSP

coc.nvimを使用する。
Language servers · neoclide/coc.nvim Wikiに従って設定する。

まずはfsautocompleteのインストール。
dotnet tool install --global fsautocompleteを実行する。
パスを通す必要があるので適宜通す。
自分は実行ファイルを~/.local/bin/にまとめていて、ここのパスを通してあるのでln -s ~/.dotnet/tools/fsautocomplete ~/.local/binを実行した。

つづいて拡張子とfiletypeの紐づけ。
init.vimに以下を追記する。

.init.vim
autocmd BufNewFile,BufRead *.fs,*.fsx,*.fsi set filetype=fsharp

最後にcoc-settings.jsonの編集。
languageserver内にF#用の設定を追加する。

coc-settings.json
"languageserver": {
  "fsharp": {
    "command": "fsautocomplete",
    "args": [],
    "filetypes": ["fsharp"],
    "trace.server": "verbose",
    "initializationOptions": {
      "AutomaticWorkspaceInit": true
    },
    "settings": {
      "FSharp.keywordsAutocomplete": true,
      "FSharp.ExternalAutocomplete": false,
      "FSharp.Linter": true,
      "FSharp.UnionCaseStubGeneration": true,
      "FSharp.UnionCaseStubGenerationBody": "failwith \"Not Implemented\"",
      "FSharp.RecordStubGeneration": true,
      "FSharp.RecordStubGenerationBody": "failwith \"Not Implemented\"",
      "FSharp.InterfaceStubGeneration": true,
      "FSharp.InterfaceStubGenerationObjectIdentifier": "this",
      "FSharp.InterfaceStubGenerationMethodBody": "failwith \"Not Implemented\"",
      "FSharp.UnusedOpensAnalyzer": true,
      "FSharp.UnusedDeclarationsAnalyzer": true,
      "FSharp.UseSdkScripts": true,
      "FSharp.SimplifyNameAnalyzer": false,
      "FSharp.ResolveNamespaces": true,
      "FSharp.EnableReferenceCodeLens": true
    }
  }
}

このままではポップアップがうるさかったので自分は以下の設定も追加した。
参考: Disable indexing progress reports · erlang-ls/erlang_ls · Discussion #1349

"notification.disabledProgressSources": ["*"]

これで自動補完やエラーのハイライト、定義ジャンプなどが使えるようになる。
2026-03-28-135425_hyprshot.png

シンタックスハイライト

nvim-treesitterでハイライトを行う。
以下に載せるコードはnvim-treesitterのmainブランチの使用を前提としていることに注意。
nvim-treesitterのmainブランチへの移行に関しては以下の情報が参考になる。

init.vimを編集して、F#のパーサの自動インストールとF#のファイルを開いたときにシンタックスハイライトが適用されるように設定する。
自分は以下のようにした。

init.vim
require('nvim-treesitter').install({
  -- 省略
  "fsharp", -- F#を追加
  -- 省略
})

-- 省略
vim.api.nvim_create_autocmd("FileType", {
  group = vim.api.nvim_create_augroup("vim-treesitter-start", { clear = true }),
  callback = function(ctx)
    local enable = {
      -- 省略
      fsharp = true, -- F#を追加
      -- 省略
    }
    if enable[ctx.match] then
      pcall(vim.treesitter.start)
    end
  end,
})

これでシンタックスハイライトも有効になる。
2026-03-28-135457_hyprshot.png

最初はtreesitterのハイライトではコメント部分のハイライトがうまくいかなかったのでDrTom/fsharp-vim: Syntax highlighting for F# in the VIM editor.でハイライトしていたがnvim-treesitterのプラグインをアップデートしたところ改善した。treesitterを使用していない場合はこちらのプラグインでハイライトしてもいいかもしれない。

余談

カラースキームは自作のものを使用している。
かなり色数を絞っており、好みは分かれると思うがご紹介しておく。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?