-
Notifications
You must be signed in to change notification settings - Fork 168
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
Add OmniSharpBuild commands #386
Comments
The build command was added so that I could SSH to machines and build remotely. It was also useful back in the day for working on OSX but building on a Windows VM. I was possibly the only user who ever did this :) I guess the same thing would also have been possible using
|
Good to know, thanks! I do think it'll be very useful to have an easy integration with the multiple servers we have now. I suspect I'll start with a personal config and merge it in here when it works well ... unless someone else beats me to it! |
I'm still not sure what the best way to incorporate Building into OmniSharp-vim is, but for anyone interested, this is how I currently do it, using function! MakeSolution() abort
let makeprg = 'msbuild /nologo /v:q /property:GenerateFullPaths=true /clp:ErrorsOnly '
let sln = fnamemodify(OmniSharp#FindSolutionOrDir(), ':.')
echomsg makeprg . sln
call asyncdo#run(1, makeprg . sln)
endfunction Then in nnoremap <silent> <buffer> <Space>mk :call MakeSolution()<CR> Edit 2019-01-31: Updated |
That is how I did it: if exists("current_compiler")
finish
endif
let current_compiler = "msbuild"
let $PATH.=';'.shellescape('C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\').';'
setlocal makeprg=msbuild\ /nologo\ /v:q\ /property:GenerateFullPaths=true\ /clp:ErrorsOnly
setlocal errorformat=\ %#%f(%l\\\,%c):\ %m Then in compiler msbuild Then I added this to function! MakeSolution() abort
let sln = shellescape(fnamemodify(OmniSharp#FindSolutionOrDir(), ':.'))
call feedkeys(':make' . sln)
endfunction
nnoremap <silent> <buffer> <Space>mk :call MakeSolution()<CR>
" automatically open quickfix window after build is completed
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost l* nested lwindow The neat thing about this is that the quickfix window popups with the builderrors and you can jump to the location using the quickfix list. |
I needed a way to build a specific .csproj and not every project in the .sln so I wrote this. I'm no Vim or C# wizard so..., feel free to refine. |
That's a nice writeup, @rene-descartes2021. If you want to only include projects which are part of the current solution in your tab-completion function, OmniSharp-vim already has a list of them: let host = OmniSharp#GetHost().job
let projects = OmniSharp#proc#GetJob(host.sln_or_dir).projects It's actually a good idea to add command completion functions for the running servers, and the projects in those servers, to OmniSharp-vim. That would allow custom commands for building, publishing, nuget restoring, testing etc. Edit OmniSharp#CompleteRunningSln Adding |
Ok I revised the writeup to include that. Falling back on a recursive search if OmniSharp-vim server hadn't loaded yet. Probably a better way to do things than I did.
My attention now is on debugger integration. Vimspector appears to be the best option. It needs a debug configuration, which appears to be a .vimspector.json file in the root of the project. Example for configuration for C# (which points to the built executable e.g. The My interest in this is I'm writing a C# layer for a distributable vim configuration. But I guess this proposed debugger integration could instead go into your nickspoons/vim-sharpenup. Just trying to wrap my mind around the best way to make things convenient for the end-user. |
OmniSharp-vim doesn't cache all of the data it receives from OmniSharp-roslyn. If there are server values we would like to be able to access from OmniSharp-vim, we can add values to that {
"name": "ProjectName",
"path": "/full/path/to/Project.csproj"
} However we could add e.g. 'target', which we do get from OmniSharp-roslyn: {
"name": "ProjectName",
"path": "/full/path/to/Project/Project.csproj",
"target": "/full/path/to/Project/bin/Debug/net5.0/Project.dll"
} Then you could use that target to generate a To see what we get from the server, configure OmniSharp-vim to use debug-level logging ( |
@rene-descartes2021 I've given your example in the wiki a go, and it works well after tweaking a bit. I won't edit it myself but here's my version of the function: function! WriteVimspectorConfig() abort
let projects = OmniSharp#GetHost().job.projects
let config = { 'configurations': {} }
for project in projects
let config.configurations[project['name']] = {
\ 'adapter': 'netcoredbg',
\ 'configuration': {
\ 'request': 'launch',
\ 'program': project['target'],
\ 'args': [],
\ 'stopAtEntry': v:true
\ }
\}
endfor
let sln_or_dir = OmniSharp#GetHost().sln_or_dir
let slndir = sln_or_dir =~? '\.sln$' ? fnamemodify(sln_or_dir, ':h') : sln_or_dir
let filename = slndir . s:dir_separator . '.vimspector.json'
call writefile([json_encode(config)], filename)
endfunction The differences are:
It's a really useful little snippet, added to my config, thanks! |
Whoops, yes I was hung up on how to get it to complete when called on OmniSharpReady, then got sidetracked. Maybe calling it manually is best. |
@rene-descartes2021 have a look at #734. @jpfeiffer16 has integrated Vimspector with OmniSharp-vim for debugging tests, it's excellent. And debugging tests is much more complicated than debugging executables, so it should be pretty simple to integrate debugging non-test projects. |
I see the new I managed to get |
So now I'm looking at updating the C# CompilerSet in Vim. The one presently in Vim/Neovim uses I also noticed the mcs CompilerSet, for Mono C#, which curiously doesn't set the makeprg. EDIT: I now see that there are msbuild and xbuild CompilerSets. Hmm. I presume those CompilerSets should be removed, the cs CompilerSet should use EDIT: There is the argument that the cs/mcs CompilerSets should be unchanged in calling csc/mcs to compile a *.cs file directly, for backwards-compatibility and if csc is exposed again. And a dotnet CompilerSet made, which is set implicitly if on $PATH, otherwise xbuild/msbuild if on $PATH. I suppose this makes the most sense all things considered. The sheerun/vim-polyglot Vim plugin looks like a promising way to distribute the updated C# CompilerSet, EDIT: and implicitly setting the CompilerSet in What I have for my
I think the
I have lines for both AsyncRun and AsyncDo in the wiki, using Making a couple OmniSharp-vim functions to build a sln or csproj which assume a particular sln or csproj seems do-able. EDIT: Which would invoke the current CompilerSet via AsyncRun/AsyncDo, and a third OmniSharp-vim function which compiles the particular *.cs file, temporarily using the existing cs/msc CompilerSets, (even though the csc frontend might not work at present). /EDIT. More user friendly than the :Make in the wiki, which is a bit cluttered in the autocompletion when there are many possible csproj to build. I'll put something together. |
@rene-descartes2021 I actually maintain most of the C# runtime files for vim, over at https://github.com/nickspoons/vim-cs. This is currently just the Note that we'll need to try to contact the previous maintainers for their permission to take over maintainership, I don't expect they'll mind though, as the compilers haven't been touched for years. Of course, all we can do there is set the compilers to |
During the recent refactorings, we have removed support for the legacy server, OmniSharp-server. As part of this, the
:OmniSharpBuild
commands have also been removed - OmniSharp-roslyn does not have/build
endpoints so these leftovers have been confusing to have lying around.We can also now have multiple servers running simultaneously, and the old
:OmniSharpBuild
implementation would not have been able to handle this situation.Now we need to add some nice build functionality back in. I don't think this needs to involve the server - in my opinion the simplest version of this can be a call to
:make
, with a sensible'makeprg'
and'errorformat'
, which builds the solution associated with the currently active file:OmniSharp#FindSolution()
It would be nice to detect whether the correct
'makeprg'
should usemsbuild
,xbuild
ordotnet build
but I'm not sure if that's something we sensibly can detect, or should just use ag:
/b:
variable.This should make use of vim8/neovim jobs, with the same
dispatch
/vimplug
fallbacks as we use to run the server.Alternatively, we can simply provide sensible mappings in the
README
and:help
, and suggest how users can use ':make' or integrate with e.g. AsyncRun or AsyncDoAny ideas or PRs welcome!
The text was updated successfully, but these errors were encountered: