Skip to content

Commit

Permalink
Added support for C# using OmniSharp
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarkevad committed Jan 28, 2015
1 parent 4d4dab1 commit ffb6acf
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 0 deletions.
129 changes: 129 additions & 0 deletions contrib/lang/csharp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# C# contribution layer for Spacemacs

![logo](img/csharp.png)

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc/generate-toc again -->
**Table of Contents**

- [C# contribution layer for Spacemacs](#c-contribution-layer-for-spacemacs)
- [Description](#description)
- [Packages Included](#packages-included)
- [Install](#install)
- [Key Bindings](#key-bindings)
- [Tests](#tests)
- [Navigation](#navigation)
- [Type information](#type-information)
- [Refactoring](#refactoring)
- [Solution/Project manipulation](#solutionproject-manipulation)
- [Compilation](#compilation)
- [Code manipulation](#code-manipulation)
- [OmniSharp server interaction](#omnisharp-server-interaction)

<!-- markdown-toc end -->

## Description

This layer adds experimental support for C# language using [OmniSharp](https://github.com/OmniSharp/omnisharp-emacs).
The layer requires the OmniSharp server, refer to the install section.

## Packages Included

- [OmniSharp-emacs](https://github.com/OmniSharp/omnisharp-emacs)
- [OmniSharp-server](https://github.com/OmniSharp/omnisharp-server)

## Install

To use this contribution add it to your `~/.spacemacs`

```elisp
(setq-default dotspacemacs-configuration-layers '(csharp)
"List of contribution to load."
)
```

- Compile the OmniSharp server, following the instructions found here: https://github.com/OmniSharp/omnisharp-server

- Then do one of:

a) In `.spacemacs` add the path to OmniSharp to an Emacs variable `(setq omnisharp-server-executable-path "/PATH/TO/OMNISHARP/OmniSharpServer")`

b) Ensure that the binary `OmniSharp` is available in Emacs' `exec-path`.

OmniSharp should now automatically load and start a server when you open a `.cs` file.

## Limitations
It's currently not possible to create C# solutions outside of IDEs such as MonoDevelop,
it's therefore recommended that you install a C# IDE and use that for creating a solution.

Debugging is possible using [SDB](https://github.com/mono/sdb), or by using an IDE.

## Key Bindings

### Tests

Key Binding | Description
----------------------|------------------------------------------------------------
"mta" | Run all tests in project
"mtb" | Run all tests in current file/fixture
"mtt" | Run test under cursor

### Navigation

Key Binding | Description
----------------------|------------------------------------------------------------
"mgg" | Go to definition
"mgG" | Go to definition in other window
"mgu" | Find usages of symbol under cursor using Helm
"mgs" | Find symbols using Helm
"mgi" | Find implementations
"mgr" | Go to region
"mgm" | Go to solution member
"mgM" | Go to solution member in other window
"mgf" | Go to solution file
"mgF" | Go to solution file then member

### Type information

Key Binding | Description
----------------------|------------------------------------------------------------
"mt" | Get type information for symbol under cursor
"mT" | Get type information for symbol under cursor and put it into kill-ring

### Refactoring

Key Binding | Description
----------------------|------------------------------------------------------------
"mrm" | Rename symbol under cursor
"mrr" | Refactor symbol under cursor

### Solution/Project manipulation

Key Binding | Description
----------------------|------------------------------------------------------------
"mpa" | Add the current file to solution
"mpA" | Add files selected in dired to solution
"mpr" | Remove the current file from solution
"mpR" | Removed files selected in dired from solution
"mpl" | Add reference to solution

### Compilation

Key Binding | Description
----------------------|------------------------------------------------------------
"mb" | Build the solution

### Code manipulation

Key Binding | Description
----------------------|------------------------------------------------------------
"mo" | Auto complete overrides
"mi" | Fix usings/imports
"m=" | Format the current buffer

### OmniSharp server interaction

Key Binding | Description
----------------------|------------------------------------------------------------
"mss" | Start the OmniSharp server
"msS" | Stop the OmniSharp server
"msr" | Reload the solution
33 changes: 33 additions & 0 deletions contrib/lang/csharp/extensions.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;;; extensions.el --- csharp Layer extensions File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3

(defvar csharp-pre-extensions
'(
;; pre extension csharps go here
)
"List of all extensions to load before the packages.")

(defvar csharp-post-extensions
'(
;; post extension csharps go here
)
"List of all extensions to load after the packages.")

;; For each extension, define a function csharp/init-<extension-csharp>
;;
;; (defun csharp/init-my-extension ()
;; "Initialize my extension"
;; )
;;
;; Often the body of an initialize function uses `use-package'
;; For more info on `use-package', see readme:
;; https://github.com/jwiegley/use-package
Binary file added contrib/lang/csharp/img/csharp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions contrib/lang/csharp/packages.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
;;; packages.el --- csharp Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3

(defvar csharp-packages
'(omnisharp))

(defvar csharp-excluded-packages '()
"List of packages to exclude.")

(defun csharp/init-omnisharp ()
;; Load omnisharp-mode with csharp-mode, this should start the omnisharp server automatically
(add-hook 'csharp-mode-hook 'omnisharp-mode)
(use-package omnisharp
:defer t
:config (evil-leader/set-key-for-mode 'csharp-mode
;; Tests
"mta" 'omnisharp-unit-test-all
"mtb" 'omnisharp-unit-test-fixture
"mtt" 'omnisharp-unit-test-single

;; Navigation
"mgg" 'omnisharp-go-to-definition
"mgG" 'omnisharp-go-to-definition-other-window
"mgu" 'omnisharp-helm-find-usages
"mgs" 'omnisharp-helm-find-symbols
"mgi" 'omnisharp-find-implementations
"mgr" 'omnisharp-navigate-to-region
"mgm" 'omnisharp-navigate-to-solution-member
"mgM" 'omnisharp-navigate-to-solution-member-other-window
"mgf" 'omnisharp-navigate-to-solution-file
"mgF" 'omnisharp-navigate-to-solution-file-then-file-member

;; Type info
"mt" 'omnisharp-current-type-information
"mT" 'omnisharp-current-type-information-to-kill-ring

;; Refactoring
"mrm" 'omnisharp-rename
"mrr" 'omnisharp-run-code-action-refactoring

;; Solution/project manipulation
"mpa" 'omnisharp-add-to-solution-current-file
"mpA" 'omnisharp-add-to-solution-dired-selected-files
"mpr" 'omnisharp-remove-from-project-current-file
"mpR" 'omnisharp-remove-from-project-dired-selected-files
"mpl" 'omnisharp-add-reference

;; Compile
"mb" 'omnisharp-build-in-emacs ;; Only one compile command so use top-level

;; Code manipulation
"mo" 'omnisharp-auto-complete-overrides
"mi" 'omnisharp-fix-usings
"m=" 'omnisharp-code-format

;; Server manipulation, inspired spacemacs REPL bindings since C# does not provice a REPL
"mss" 'omnisharp-start-omnisharp-server
"msS" 'omnisharp-stop-server
"msr" 'omnisharp-reload-solution)

;; Init omnisharp company backend
(eval-after-load 'company
'(add-to-list 'company-backends 'company-omnisharp))
))

0 comments on commit ffb6acf

Please sign in to comment.