{"id":2352,"date":"2019-11-15T20:41:34","date_gmt":"2019-11-16T01:41:34","guid":{"rendered":"http:\/\/codinggorilla.com\/?p=2352"},"modified":"2020-01-11T05:30:00","modified_gmt":"2020-01-11T10:30:00","slug":"a-note-on-getting-gnu-emacs-working-with-omnisharp-roslyn-lsp-server","status":"publish","type":"post","link":"http:\/\/165.227.223.229\/index.php\/2019\/11\/15\/a-note-on-getting-gnu-emacs-working-with-omnisharp-roslyn-lsp-server\/","title":{"rendered":"A note on getting Gnu Emacs working with Omnisharp-Roslyn LSP server"},"content":{"rendered":"\n<p>After wasting a bit of time the last few days, I figured out how to get the Gnu Emacs editor to work with the Omnisharp-Roslyn LSP server for C#. Finding the right solution required a lot of trial and error work because I work mainly on Windows, and that is completely sacrilegious.<\/p>\n\n\n\n<p><!--more--><\/p>\n\n\n\n<p>First off: Why Emacs? Sorry, but I grew up with Emacs and vi, starting in the early &#8217;80s. Emacs was decent, and it still is. It comes in handy on the command line for a GUI-less Linux server. <\/p>\n\n\n\n<p>There are two Gnu Emacs clients. One is written by OmniSharp before LSP existed, at  <a href=\"https:\/\/github.com\/OmniSharp\/omnisharp-emacs\">https:\/\/github.com\/OmniSharp\/omnisharp-emacs<\/a> . This client works fine, but the short instructions at  <a href=\"http:\/\/www.omnisharp.net\/#integrations\">http:\/\/www.omnisharp.net\/#integrations<\/a>  are completely bogus. The other is  <a href=\"https:\/\/github.com\/emacs-lsp\/lsp-mode\/\">https:\/\/github.com\/emacs-lsp\/lsp-mode\/<\/a> . This is what I use below. Like the instructions for omnisharp-emacs, the instructions here are terrible. But, it does work. All operations, like &#8220;go to definition&#8221; are defined as functions that begin with &#8220;lsp-&#8220;, available through the M-x command, e.g., M-x lsp-find-references.<\/p>\n\n\n\n<ol><li>Download Gnu Emacs from  <a href=\"https:\/\/www.gnu.org\/software\/emacs\/download.html\">https:\/\/www.gnu.org\/software\/emacs\/download.html<\/a> , specifically the latest at  <a href=\"http:\/\/ftp.wayne.edu\/gnu\/emacs\/windows\/\">http:\/\/ftp.wayne.edu\/gnu\/emacs\/windows\/<\/a> . Do not install <a href=\"https:\/\/www.msys2.org\/\">MSYS2<\/a>, run pacman as per instructions. While I could get MSYS2 working, the paths are all messed up due to filtering out of Windows binaries, to the point of being useless. In addition, I tried to use the Bash LSP server, but that required npm to be installed&#8211;which there isn&#8217;t in MSYS2 (though in Node.js, etc, etc, etc). Again, do not go down this road.<\/li><li>Clone the repository  <a href=\"https:\/\/github.com\/OmniSharp\/omnisharp-roslyn\">https:\/\/github.com\/OmniSharp\/omnisharp-roslyn<\/a> . Start VS2019, open the file OmniSharp.sln, then build the executable, and make a note of the full path to OmniSharp.exe.<\/li><li>Create an init.el file for Emacs. It should be at c:\/Users\/etcetcetc\/AppData\/Roaming\/.emacs.d\/init.el. You can check the location by opening Gnu Emacs, then in the start-up screen, click on &#8220;Open Home Directory&#8221;. This file should contain this:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">(require 'package)\n (let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))\n                     (not (gnutls-available-p))))\n        (proto (if no-ssl \"http\" \"https\")))\n   (when no-ssl\n     (warn \"\\\n Your version of Emacs does not support SSL connections,\n which is unsafe because it allows man-in-the-middle attacks.\n There are two things you can do about this warning:\n Install an Emacs version that does support SSL and be safe.\n Remove this warning from your init file so you won't see it again.\"))\n ;; Comment\/uncomment these two lines to enable\/disable MELPA and MELPA Stable as desired\n (add-to-list 'package-archives (cons \"melpa\" (concat proto \":\/\/melpa.org\/packages\/\")) t)\n ;;(add-to-list 'package-archives (cons \"melpa-stable\" (concat proto \":\/\/stable.melpa.org\/packages\/\")) t)\n (when (&lt; emacs-major-version 24)\n ;; For important compatibility libraries like cl-lib\n (add-to-list 'package-archives (cons \"gnu\" (concat proto \":\/\/elpa.gnu.org\/packages\/\")))))\n (package-initialize) \n ;; Added by Package.el.  This must come before configurations of\n ;; installed packages.  Don't delete this line.  If you don't want it,\n ;; just comment it out by adding a semicolon to the start of the line.\n ;; You may delete these explanatory comments.\n (package-initialize)\n ;;(custom-set-variables\n  ;; custom-set-variables was added by Custom.\n  ;; If you edit it by hand, you could mess it up, so be careful.\n  ;; Your init file should contain only one such instance.\n  ;; If there is more than one, they won't work right.\n ;; '(package-selected-packages (quote (omnisharp lsp-mode))))\n (custom-set-faces\n  ;; custom-set-faces was added by Custom.\n  ;; If you edit it by hand, you could mess it up, so be careful.\n  ;; Your init file should contain only one such instance.\n  ;; If there is more than one, they won't work right.\n  '(default ((t (:family \"Courier New\" :foundry \"outline\" :slant normal :weight normal :height 161 :width normal)))))\n (package-refresh-contents)\n (package-install 'flycheck)\n (global-flycheck-mode)\n (require 'lsp-mode)\n (add-hook 'csharp-mode-hook #'lsp)\n ;;(package-install 'omnisharp)\n ;;(add-hook 'csharp-mode-hook 'omnisharp-mode)\n ;;\n ;;\n (defcustom lsp-clients-csharp-language-server-path\n   (expand-file-name \"c:\/users\/etcetcetc\/documents\/omnisharp-roslyn\/bin\/debug\/omnisharp.stdio.driver\/net472\/OmniSharp.exe\")\n   \"The path to the OmnisSharp Roslyn language-server.\"\n   :group 'lsp-csharp\n   :type '(string :tag \"Single string value\"))\n (custom-set-variables\n  ;; custom-set-variables was added by Custom.\n  ;; If you edit it by hand, you could mess it up, so be careful.\n  ;; Your init file should contain only one such instance.\n  ;; If there is more than one, they won't work right.\n  '(package-selected-packages (quote (flycheck omnisharp lsp-mode))))<\/pre>\n\n\n\n<p>You will need to change the location of the Omnisharp-roslyn server executable which you built in step 2 in this init.el file.<\/p>\n\n\n\n<p>Start Gnu Emacs and open a C# file and follow the instructions. All operations begin with M-x lsp-.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After wasting a bit of time the last few days, I figured out how to get the Gnu Emacs editor to work with the Omnisharp-Roslyn LSP server for C#. Finding the right solution required a lot of trial and error work because I work mainly on Windows, and that is completely sacrilegious.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/2352"}],"collection":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/comments?post=2352"}],"version-history":[{"count":0,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/2352\/revisions"}],"wp:attachment":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/media?parent=2352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/categories?post=2352"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/tags?post=2352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}