Skip to content

Instantly share code, notes, and snippets.

@TylerLeonhardt
Created May 24, 2018 16:32
Show Gist options
  • Save TylerLeonhardt/89e2d55341862734fc91bee52af8acc6 to your computer and use it in GitHub Desktop.
Save TylerLeonhardt/89e2d55341862734fc91bee52af8acc6 to your computer and use it in GitHub Desktop.
NeoVim PowerShell setup
call plug#begin('~/.local/share/nvim/plugged')
" Handles the fzf popups
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" The LSP client
Plug 'autozimu/LanguageClient-neovim', {
\ 'branch': 'next',
\ 'do': 'bash install.sh',
\ }
" figures out what language you're using
Plug 'sheerun/vim-polyglot'
" completions
Plug 'roxma/nvim-completion-manager'
Plug 'flazz/vim-colorschemes'
call plug#end()
colorscheme luna-term
"LanguageServerProtocol setup
"required for operations modifying multiple buffers like rename.
set hidden
" a hash of file types to language server launch command
let g:LanguageClient_serverCommands = {
\ 'ps1': ['pwsh', '~/Desktop/Tech/PowerShell/vscode/PowerShellEditorServices/module/PowerShellEditorServices/Start-EditorServices.ps1', '-HostName', 'nvim', '-HostProfileId', '0', '-HostVersion', '1.0.0', '-LogPath', '~/Desktop/pses.log.txt', '-LogLevel', 'Diagnostic', '-BundledModulesPath', '~/Desktop/Tech/PowerShell/vscode/PowerShellEditorServices/module', '-Stdio', '-SessionDetailsPath', '~/Desktop/.pses_session']
\ }
" for debugging LanguageClient-neovim
let g:LanguageClient_loggingLevel = 'DEBUG'
" fun with F8
function! PS1OutputHandle(output) abort
echomsg json_encode(a:output)
endfunction
" If the filetype is powershell set up our keybindings
autocmd FileType ps1 call VsimEnableLanguageServerKeys()
function! VsimEnableLanguageServerKeys()
" TODO hover with timer
nnoremap <silent> <S-K> :call LanguageClient_textDocument_hover()<CR>
nnoremap <silent> <F2> :call LanguageClient_textDocument_rename()<CR>
nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
nnoremap <silent> <F12> :call LanguageClient_textDocument_definition()<CR>
set formatexpr=LanguageClient_textDocument_rangeFormatting()
vnoremap = :call LanguageClient_textDocument_rangeFormatting()<CR>
nnoremap <C-k><C-r> :call LanguageClient_textDocument_references()<CR>
nnoremap <C-e><C-d> :call LanguageClient_textDocument_formatting()<CR>
autocmd! CursorHold * call LanguageClient_textDocument_hover()
call LanguageClient#registerHandlers({'output': 'PS1OutputHandle'})
vnoremap <silent> <F8> :call RunCode()<CR>
"autocmd! VimLeave * :LanguageClientStop
endfunction
" fun with F8
function RunCode()
let codeString = s:get_visual_selection()
:call LanguageClient#Call("evaluate", { 'expression': s:get_visual_selection() }, function("PS1OutputHandle"))
endfunction
" fun with F8
function! s:get_visual_selection()
" Why is this not a built-in Vim script function?!
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment