Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for cake. #433

Closed
JohanBjoerklund opened this issue Dec 6, 2018 · 12 comments
Closed

Support for cake. #433

JohanBjoerklund opened this issue Dec 6, 2018 · 12 comments

Comments

@JohanBjoerklund
Copy link

OmniSharp-roslyn has support for cake since version v1.32.1, but I can't seem to make it work.

Tried on Windows 10, using all versions of OmniSharp-roslyn since v1.32.1.

Using any of the commands in a cake file, like OmniSharpGetCodeActions() yields an error like:
ERROR: unknown url type: '/v2/getcodeactions/'.

Trying to manually start the server with OmniSharpStartServer() from a .cake file gives:
E488: Trailing characters.

Config:

let g:OmniSharp_server_path = expand('~/.omnisharp/omnisharp-roslyn/') . 'OmniSharp.exe'
let g:OmniSharp_selector_ui = 'ctrlp'
let g:OmniSharp_timeout = 5
let g:OmniSharp_proc_debug = 1


augroup omnisharp_commands
  autocmd!

  " Show type information automatically when the cursor stops moving
  " autocmd CursorHold *.cs call OmniSharp#TypeLookupWithoutDocumentation()

  " The following commands are contextual, based on the cursor position.
  autocmd FileType cs nnoremap <buffer> gd :OmniSharpGotoDefinition<CR>
  autocmd FileType cs nnoremap <buffer> <leader>fi :OmniSharpFindImplementations<CR>
  autocmd FileType cs nnoremap <buffer> <leader>fs :OmniSharpFindSymbol<CR>
  autocmd FileType cs nnoremap <buffer> <leader>fu :OmniSharpFindUsages<CR>

  " Finds members in the current buffer
  autocmd FileType cs nnoremap <buffer> <Leader>fm :OmniSharpFindMembers<CR>

  " Cursor can be anywhere on the line containing an issue
  autocmd FileType cs nnoremap <buffer> <Leader>x  :OmniSharpFixIssue<CR>
  autocmd FileType cs nnoremap <buffer> <Leader>fx :OmniSharpFixUsings<CR>
  autocmd FileType cs nnoremap <buffer> <Leader>tt :OmniSharpTypeLookup<CR>
  autocmd FileType cs nnoremap <buffer> <Leader>dc :OmniSharpDocumentation<CR>
  autocmd FileType cs nnoremap <buffer> <C-\> :OmniSharpSignatureHelp<CR>
  autocmd FileType cs inoremap <buffer> <C-\> <C-o>:OmniSharpSignatureHelp<CR>

  " Navigate up and down by method/property/field
  autocmd FileType cs nnoremap <buffer> <C-k> :OmniSharpNavigateUp<CR>
  autocmd FileType cs nnoremap <buffer> <C-j> :OmniSharpNavigateDown<CR>
augroup END

" Contextual code actions (uses fzf, CtrlP or unite.vim when available)
nnoremap <Leader><Space> :OmniSharpGetCodeActions<CR>

" Run code actions with text selected in visual mode to extract method
xnoremap <Leader><Space> :call OmniSharp#GetCodeActions('visual')<CR>

" Rename with dialog
nnoremap <Leader>nm :OmniSharpRename<CR>
" Rename without dialog - with cursor on the symbol to rename: `:Rename newname`
command! -nargs=1 Rename :call OmniSharp#RenameTo("<args>")

nnoremap <Leader>cf :OmniSharpCodeFormat<CR>

" Start the omnisharp server for the current solution
nnoremap <Leader>ss :OmniSharpStartServer<CR>
nnoremap <Leader>sp :OmniSharpStopServer<CR>

" Add syntax highlighting for types and interfaces
nnoremap <Leader>th :OmniSharpHighlightTypes<CR>
@nickspoons
Copy link
Member

@JohanBjoerklund a lot of the setup in OmniSharp-vim happens in the ftplugin/cs.vim file, which won't be triggered by *.cake files. Could you try :set ft=cs in a cake file before trying any OmniSharp commands and see if that helps?

@JohanBjoerklund
Copy link
Author

With this I get highlighting, but nothing else.

augroup ft_cake
autocmd BufRead,BufNewFile *.cake setlocal filetype=cs
augroup END

@JohanBjoerklund
Copy link
Author

Is there any more information I can provide to help solve this?

@nickspoons
Copy link
Member

I'm sorry I don't know anything about cake, I'm not sure what should/shouldn't work. I have tried to see what happens when opening the build.cake from the OmniSharp-roslyn repo in VSCode for comparison but there doesn't seem to be OmniSharp support there? What are you expecting?

@JohanBjoerklund
Copy link
Author

There is support for cake in vs code, so I guess syntax highlighting and code completion should work.
See dotnet/vscode-csharp#1681

@nickspoons
Copy link
Member

nickspoons commented Dec 19, 2018

Well, vim's syntax highlighting works by filetype and is independent of OmniSharp-vim, so your augroup is correct for that (although an augroup without autocmd! as the first line is a bit pointless) - it will tell vim to use C# syntax (and ftplugins etc.) for .cake files.

As I say, I don't have experience with cake and couldn't see that VSCode did anything with it. Can you provide a minimal example project, and show how/where VSCode provides completion? That will give me (or someone?) something to work from.

@bjorkstromm
Copy link
Member

@JohanBjoerklund @nickspoons .cake file support is in OmniSharp-Roslyn, we support most of the same stuff that’s supported for .cs and .csx. For Cake stuff to actually work, you’ll need to have both Cake and Cake.Bakery installed in your workspace (see test assets for unit tests for example. Basically just restore the packages located in ./tools/packages.config and you’ll be good to go). Please let me know if you have any questions.

@JohanBjoerklund
Copy link
Author

Thanks for the reply.
Bakery is installed and the omnisharp.json points to its install location.
No dice.

omnisharp.json file looks like this.

{                                                        
  "formattingOptions": {                                 
                                                         
  },                                                     
  "cake": {                                              
    "bakeryPath": "C:/Program Files/Cake/Cake.Bakery.exe"
  }                                                      
}

@JohanBjoerklund
Copy link
Author

JohanBjoerklund commented Feb 4, 2019

I managed to get it working by adding an empty global.json in my script folder and add
let g:OmniSharp_prefer_global_sln = 1, and set .cake files to cs to my vimrc.

@patriksvensson
Copy link

@JohanBjoerklund Awesome work. Thanks for finding this 👍

@nickspoons
Copy link
Member

@JohanBjoerklund I've just made a couple of small changes so this will work out of the box:

  1. Added an ftdetect/cake.vim script, so that .cake files have their filetype set to cs
  2. Do not require a solution for .cake files

This is the same way we treat .csx files, and means that you won't need that global.json file or g:OmniSharp_prefer_global_sln in your config any more.

This seems to work fine for me (once the bakery stuff is set up correctly), I get completions. There is no highlighting support from OmniSharp-roslyn for .cake files, I don't know if there is support for anything other than completions?

@JohanBjoerklund
Copy link
Author

Works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants