Skip to content

FuelLabs/sway.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

About

Vim syntax file for Sway

Installation

Pre-requisites:

  1. Clone this repo
  2. Ensure you have the forc-lsp binary with which forc-lsp. If not, install the Sway toolchain.

Neovim

  1. Copy the folders 'ftdetect' and 'syntax' to the config folder:
cp -R ~/sway.vim/syntax ~/.config/nvim && cp -R ~/sway.vim/ftdetect ~/.config/nvim
  1. If you do not have ~/.config/nvim/init.lua, install kickstart.nvim.
  2. If you already have init.lua, you may need to require extra dependencies, or simply copy this block.
  3. Add the following to ~/.config/nvim/init.lua:
-- Install Sway LSP as a custom	server
local lspconfig = require 'lspconfig'
local configs = require 'lspconfig.configs'

-- Check if the config is already defined (useful when reloading this file)
if not configs.sway_lsp then
   configs.sway_lsp = {
     default_config = {
       cmd = {'forc-lsp'},
       filetypes = {'sway'},
       on_attach = on_attach,
       init_options = { 
         -- Any initialization options
         logging = { level = 'trace' }
       },
       root_dir = function(fname)
         return lspconfig.util.find_git_ancestor(fname)
       end;
       settings = {};
     };
   }
 end

lspconfig.sway_lsp.setup{}
  1. Check that the LSP is running by running :LspInfo and trying out features like Goto Definition (gd) and Hover (K). The key mappings are defined in ~/.config/nvim/init.lua

Nov-10-2022 20-18-51

Vim

  1. Clone this repo
  2. Copy the folders 'ftdetect' and 'syntax' to the config folder:
cp -R ~/sway.vim/syntax ~/.vim && cp -R ~/sway.vim/ftdetect ~/.vim
  1. Edit your ~/.vim/filetype.vim to contain the following block:
if exists("did_load_filetypes")
  finish
endif

augroup filetypedetect
  au! BufNewFile,BufRead *.[sS][wW] setf sway
augroup END
  1. Install plug.vim
  2. Add the following to your ~/.vimrc
call plug#begin()

Plug 'prabirshrestha/vim-lsp'

call plug#end()
  1. Create a file called ~/.vim/lsp.vim with the following contents, or add this to an existing vim script:
" vim-lsp for Sway (sway-lsp)
if executable('sway-lsp')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'sway-lsp',
        \ 'cmd': {server_info->['sway-lsp']},
        \ 'whitelist': ['sway'],
        \ })
endif
  1. Open vim and :source ~/.vim/lsp.vim
  2. Check that the LSP is running with :LspStatus and try out feature like :LspDefinition and :LspHover. The full list of commands are defined here.

Nov-10-2022 21-05-18