Skip to content

Commit ce31cd1

Browse files
committed
Update
1 parent 554a6ac commit ce31cd1

File tree

16 files changed

+209
-87
lines changed

16 files changed

+209
-87
lines changed

after/syntax/c.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ endif
88
" Original Author: Mikhail Wolfson <[email protected]>
99
" Maintainer: bfrg <https://github.com/bfrg>
1010
" Website: https://github.com/bfrg/vim-cpp-modern
11-
" Last Change: Nov 23, 2020
11+
" Last Change: Jul 24, 2021
1212
"
1313
" This syntax file is based on:
1414
" https://github.com/octol/vim-cpp-enhanced-highlight
@@ -20,7 +20,7 @@ syn keyword cTodo contained BUG NOTE
2020

2121

2222
" Highlight function names
23-
if !get(g:, 'cpp_no_function_highlight', 0)
23+
if get(g:, 'cpp_function_highlight', 1)
2424
syn match cUserFunction "\<\h\w*\>\(\s\|\n\)*("me=e-1 contains=cParen,cCppParen
2525
hi def link cUserFunction Function
2626
endif

autoload/fsharp.vim

Lines changed: 136 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ let g:loaded_autoload_fsharp = 1
1212
let s:cpo_save = &cpo
1313
set cpo&vim
1414

15+
16+
" basic setups
17+
18+
let s:script_root_dir = expand('<sfile>:p:h') . "/../"
19+
20+
if has('nvim-0.5')
21+
lua ionide = require("ionide")
22+
endif
23+
1524
function! s:prompt(msg)
1625
let height = &cmdheight
1726
if height < 2
@@ -21,6 +30,9 @@ function! s:prompt(msg)
2130
let &cmdheight = height
2231
endfunction
2332

33+
34+
" FSAC payload interfaces
35+
2436
function! s:PlainNotification(content)
2537
return { 'Content': a:content }
2638
endfunction
@@ -80,8 +92,24 @@ function! s:FsdnRequest(query)
8092
return { 'Query': a:query }
8193
endfunction
8294

95+
96+
" LSP functions
97+
8398
function! s:call(method, params, cont)
84-
call LanguageClient#Call(a:method, a:params, a:cont)
99+
if g:fsharp#backend == 'languageclient-neovim'
100+
call LanguageClient#Call(a:method, a:params, a:cont)
101+
elseif g:fsharp#backend == 'nvim'
102+
let key = fsharp#register_callback(a:cont)
103+
call luaeval('ionide.call(_A[1], _A[2], _A[3])', [a:method, a:params, key])
104+
endif
105+
endfunction
106+
107+
function! s:notify(method, params)
108+
if g:fsharp#backend == 'languageclient-neovim'
109+
call LanguageClient#Notify(a:method, a:params)
110+
elseif g:fsharp#backend == 'nvim'
111+
call luaeval('ionide.notify(_A[1], _A[2])', [a:method, a:params])
112+
endif
85113
endfunction
86114

87115
function! s:signature(filePath, line, character, cont)
@@ -121,6 +149,9 @@ function! s:documentationSymbol(xmlSig, assembly, cont)
121149
return s:call('fsharp/documentationSymbol', s:DocumentationForSymbolRequest(a:xmlSig, a:assembly), a:cont)
122150
endfunction
123151

152+
153+
" FSAC configuration
154+
124155
" FSharpConfigDto from https://github.com/fsharp/FsAutoComplete/blob/master/src/FsAutoComplete/LspHelpers.fs
125156
"
126157
" * The following options seems not working with workspace/didChangeConfiguration
@@ -160,7 +191,7 @@ let s:config_keys_camel =
160191
\ ]
161192
let s:config_keys = []
162193

163-
function! fsharp#toSnakeCase(str)
194+
function! s:toSnakeCase(str)
164195
let sn = substitute(a:str, '\(\<\u\l\+\|\l\+\)\(\u\)', '\l\1_\l\2', 'g')
165196
if sn == a:str | return tolower(a:str) | endif
166197
return sn
@@ -170,7 +201,7 @@ function! s:buildConfigKeys()
170201
if len(s:config_keys) == 0
171202
for key_camel in s:config_keys_camel
172203
let key = {}
173-
let key.snake = fsharp#toSnakeCase(key_camel.key)
204+
let key.snake = s:toSnakeCase(key_camel.key)
174205
let key.camel = key_camel.key
175206
if has_key(key_camel, 'default')
176207
let key.default = key_camel.default
@@ -180,7 +211,7 @@ function! s:buildConfigKeys()
180211
endif
181212
endfunction
182213

183-
function! g:fsharp#getServerConfig()
214+
function! fsharp#getServerConfig()
184215
let fsharp = {}
185216
call s:buildConfigKeys()
186217
for key in s:config_keys
@@ -196,12 +227,76 @@ function! g:fsharp#getServerConfig()
196227
return fsharp
197228
endfunction
198229

199-
function! g:fsharp#updateServerConfig()
230+
function! fsharp#updateServerConfig()
200231
let fsharp = fsharp#getServerConfig()
201232
let settings = {'settings': {'FSharp': fsharp}}
202-
call LanguageClient#Notify('workspace/didChangeConfiguration', settings)
233+
call s:notify('workspace/didChangeConfiguration', settings)
234+
endfunction
235+
236+
237+
" handlers for notifications
238+
239+
let s:handlers = {
240+
\ 'fsharp/notifyWorkspace': 'fsharp#handle_notifyWorkspace',
241+
\ }
242+
243+
function! s:registerAutocmds()
244+
if g:fsharp#backend == 'nvim' && g:fsharp#lsp_codelens
245+
augroup FSharp_AutoRefreshCodeLens
246+
autocmd!
247+
autocmd CursorHold,InsertLeave <buffer> lua vim.lsp.codelens.refresh()
248+
augroup END
249+
endif
250+
if g:fsharp#backend != 'disable'
251+
augroup FSharp_OnCursorMove
252+
autocmd!
253+
autocmd CursorMoved *.fs,*.fsi,*.fsx call fsharp#OnCursorMove()
254+
augroup END
255+
endif
256+
endfunction
257+
258+
function! fsharp#initialize()
259+
echom '[FSAC] Initialized'
260+
if g:fsharp#backend == 'languageclient-neovim'
261+
call LanguageClient_registerHandlers(s:handlers)
262+
endif
263+
call fsharp#updateServerConfig()
264+
call s:registerAutocmds()
265+
endfunction
266+
267+
268+
" nvim-lsp specific functions
269+
270+
" handlers are picked up by ionide.setup()
271+
function! fsharp#get_handlers()
272+
return s:handlers
203273
endfunction
204274

275+
let s:callbacks = {}
276+
277+
function! fsharp#register_callback(fn)
278+
if g:fsharp#backend != 'nvim'
279+
return -1
280+
endif
281+
let rnd = reltimestr(reltime())
282+
let s:callbacks[rnd] = a:fn
283+
return rnd
284+
endfunction
285+
286+
function! fsharp#resolve_callback(key, arg)
287+
if g:fsharp#backend != 'nvim'
288+
return
289+
endif
290+
if has_key(s:callbacks, a:key)
291+
let Callback = s:callbacks[a:key]
292+
call Callback(a:arg)
293+
call remove(s:callbacks, a:key)
294+
endif
295+
endfunction
296+
297+
298+
" .NET/F# specific operations
299+
205300
function! s:findWorkspace(dir, cont)
206301
let s:cont_findWorkspace = a:cont
207302
function! s:callback_findWorkspace(result)
@@ -237,13 +332,20 @@ endfunction
237332

238333
let s:workspace = []
239334

335+
function! fsharp#handle_notifyWorkspace(payload) abort
336+
let content = json_decode(a:payload.content)
337+
if content.Kind == 'projectLoading'
338+
echom "[FSAC] Loading" content.Data.Project
339+
let s:workspace = uniq(sort(add(s:workspace, content.Data.Project)))
340+
elseif content.Kind == 'workspaceLoad' && content.Data.Status == 'finished'
341+
echom printf("[FSAC] Workspace loaded (%d project(s))", len(s:workspace))
342+
call fsharp#updateServerConfig()
343+
endif
344+
endfunction
345+
346+
240347
function! s:load(arg)
241-
let s:loading_workspace = a:arg
242-
function! s:callback_load(_)
243-
echo "[FSAC] Workspace loaded: " . join(s:loading_workspace, ', ')
244-
let s:workspace = s:workspace + s:loading_workspace
245-
endfunction
246-
call s:workspaceLoad(a:arg, function("s:callback_load"))
348+
call s:workspaceLoad(a:arg, v:null)
247349
endfunction
248350

249351
function! fsharp#loadProject(...)
@@ -254,23 +356,15 @@ function! fsharp#loadProject(...)
254356
call s:load(prjs)
255357
endfunction
256358

257-
function! fsharp#loadWorkspaceAuto()
258-
if &ft == 'fsharp'
259-
call fsharp#updateServerConfig()
260-
if g:fsharp#automatic_workspace_init
261-
echom "[FSAC] Loading workspace..."
262-
let bufferDirectory = fnamemodify(resolve(expand('%:p')), ':h')
263-
call s:findWorkspace(bufferDirectory, function("s:load"))
264-
endif
265-
endif
359+
function! fsharp#showLoadedProjects()
360+
for proj in s:workspace
361+
echo "-" proj
362+
endfor
266363
endfunction
267364

268365
function! fsharp#reloadProjects()
269366
if len(s:workspace) > 0
270-
function! s:callback_reloadProjects(_)
271-
call s:prompt("[FSAC] Workspace reloaded.")
272-
endfunction
273-
call s:workspaceLoad(s:workspace, function("s:callback_reloadProjects"))
367+
call s:workspaceLoad(s:workspace, v:null)
274368
else
275369
echom "[FSAC] Workspace is empty"
276370
endif
@@ -288,7 +382,7 @@ function! fsharp#showSignature()
288382
if exists('result.result.content')
289383
let content = json_decode(result.result.content)
290384
if exists('content.Data')
291-
echom substitute(content.Data, '\n\+$', ' ', 'g')
385+
echo substitute(content.Data, '\n\+$', ' ', 'g')
292386
endif
293387
endif
294388
endfunction
@@ -306,26 +400,30 @@ function! fsharp#showF1Help()
306400
echo result
307401
endfunction
308402

403+
function! s:hover()
404+
if g:fsharp#backend == 'languageclient-neovim'
405+
call LanguageClient#textDocument_hover()
406+
elseif g:fsharp#backend == 'nvim'
407+
lua vim.lsp.buf.hover()
408+
endif
409+
endfunction
410+
309411
function! fsharp#showTooltip()
310412
function! s:callback_showTooltip(result)
311413
let result = a:result
312414
if exists('result.result.content')
313415
let content = json_decode(result.result.content)
314416
if exists('content.Data')
315-
call LanguageClient#textDocument_hover()
417+
call s:hover()
316418
endif
317419
endif
318420
endfunction
319421
" show hover only if signature exists for the current position
320422
call s:signature(expand('%:p'), line('.') - 1, col('.') - 1, function("s:callback_showTooltip"))
321423
endfunction
322424

323-
let s:script_root_dir = expand('<sfile>:p:h') . "/../"
324-
let s:fsac = fnamemodify(s:script_root_dir . "fsac/fsautocomplete.dll", ":p")
325-
let g:fsharp#languageserver_command =
326-
\ ['dotnet', s:fsac,
327-
\ '--background-service-enabled'
328-
\ ]
425+
426+
" FSAC update utils
329427

330428
function! s:update_win()
331429
echom "[FSAC] Downloading FSAC. This may take a while..."
@@ -357,6 +455,9 @@ function! fsharp#updateFSAC(...)
357455
endif
358456
endfunction
359457

458+
459+
" FSI integration
460+
360461
let s:fsi_buffer = -1
361462
let s:fsi_job = -1
362463
let s:fsi_width = 0
@@ -385,7 +486,6 @@ endfunction
385486
function! fsharp#openFsi(returnFocus)
386487
if bufwinid(s:fsi_buffer) <= 0
387488
let fsi_command = s:get_fsi_command()
388-
" Neovim
389489
if exists('*termopen') || exists('*term_start')
390490
let current_win = win_getid()
391491
execute g:fsharp#fsi_window_command
@@ -429,7 +529,7 @@ function! fsharp#openFsi(returnFocus)
429529
if a:returnFocus | call s:win_gotoid_safe(current_win) | endif
430530
return s:fsi_buffer
431531
else
432-
echom "[FSAC] Your Vim does not support terminal".
532+
echom "[FSAC] Your (neo)vim does not support terminal".
433533
return 0
434534
endif
435535
endif
@@ -517,6 +617,7 @@ function! fsharp#sendAllToFsi()
517617
return fsharp#sendFsi(text)
518618
endfunction
519619

620+
520621
let &cpo = s:cpo_save
521622
unlet s:cpo_save
522623

autoload/puppet/align.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ if polyglot#init#is_disabled(expand('<sfile>:p'), 'puppet', 'autoload/puppet/ali
22
finish
33
endif
44

5-
function! puppet#align#IndentLevel(lnum)
5+
function! puppet#align#IndentLevel(lnum) abort
66
return indent(a:lnum) / &shiftwidth
77
endfunction
88

9-
function! puppet#align#LinesInBlock(lnum)
9+
function! puppet#align#LinesInBlock(lnum) abort
1010
let lines = []
1111
let indent_level = puppet#align#IndentLevel(a:lnum)
1212

autoload/puppet/ctags.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ endif
1010
let s:ctags_options_dir = expand('<sfile>:p:h:h:h') . '/ctags/'
1111

1212
" Return full path to option file for ctags application
13-
function! puppet#ctags#OptionFile()
13+
function! puppet#ctags#OptionFile() abort
1414

15-
if puppet#ctags#Type() == 'universal'
15+
if puppet#ctags#Type() ==? 'universal'
1616
let l:ctags_options = 'puppet_u.ctags'
1717
else
1818
let l:ctags_options = 'puppet.ctags'
@@ -22,13 +22,13 @@ endfunction
2222

2323
" Return type of installed ctags application,
2424
" can be 'universal' or 'exuberant'
25-
function! puppet#ctags#Type()
25+
function! puppet#ctags#Type() abort
2626

2727
if !s:ctags_type
2828
let l:version = system('ctags --version')
29-
if l:version =~ 'Universal Ctags'
29+
if l:version =~? 'Universal Ctags'
3030
let s:ctags_type = 'universal'
31-
elseif l:version =~ 'Exuberant Ctags'
31+
elseif l:version =~? 'Exuberant Ctags'
3232
let s:ctags_type = 'exuberant'
3333
else
3434
echoerr 'Unknown version of Ctags'

compiler/puppet-lint.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ endif
66
" Compiler: puppet-lint
77
" Maintainer: Doug Kearns <[email protected]>
88

9-
if exists("current_compiler")
9+
if exists('current_compiler')
1010
finish
1111
endif
12-
let current_compiler = "puppet-lint"
12+
let current_compiler = 'puppet-lint'
1313

14-
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
14+
if exists(':CompilerSet') != 2 " older Vim always used :setlocal
1515
command -nargs=* CompilerSet setlocal <args>
1616
endif
1717

0 commit comments

Comments
 (0)