csharp-compilation.el (5011B)
1 ;;; csharp-compilation.el --- compilation support for C# -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2020-2021 Free Software Foundation, Inc. 4 5 ;; Author : Theodor Thornhill <theo@thornhill.no> 6 ;; Maintainer : Jostein Kjønigsen <jostein@gmail.com> 7 ;; Theodor Thornhill <theo@thornhill.no> 8 ;; Created : September 2020 9 ;; Modified : 2020 10 ;; Version : 1.1.1 11 ;; Keywords : c# languages oop mode 12 ;; X-URL : https://github.com/emacs-csharp/csharp-mode 13 14 ;; This program is free software; you can redistribute it and/or modify 15 ;; it under the terms of the GNU General Public License as published by 16 ;; the Free Software Foundation, either version 3 of the License, or 17 ;; (at your option) any later version. 18 19 ;; This program is distributed in the hope that it will be useful, 20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 ;; GNU General Public License for more details. 23 24 ;; You should have received a copy of the GNU General Public License 25 ;; along with this program. If not, see <http://www.gnu.org/licenses/>. 26 27 28 (require 'compile) 29 30 ;; When invoked by MSBuild, csc’s errors look like this: 31 ;; subfolder\file.cs(6,18): error CS1006: Name of constructor must 32 ;; match name of class [c:\Users\user\project.csproj] 33 34 (defun csharp--compilation-error-file-resolve () 35 "Resolve an msbuild error to a (filename . dirname) cons cell." 36 ;; http://stackoverflow.com/a/18049590/429091 37 (cons (match-string 1) (file-name-directory (match-string 4)))) 38 39 (defconst csharp-compilation-re-msbuild-error 40 (concat 41 "^[[:blank:]]*\\(?:[[:digit:]]+>\\)?" 42 "\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?): " 43 "error [[:alnum:]]+: [^\r\n]+\\[\\([^]\r\n]+\\)\\]$") 44 "Regexp to match compilation error from msbuild.") 45 46 (defconst csharp-compilation-re-msbuild-warning 47 (concat 48 "^[[:blank:]]*\\(?:[[:digit:]]+>\\)?" 49 "\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?): " 50 "warning [[:alnum:]]+: [^\r\n]+\\[\\([^]\r\n]+\\)\\]$") 51 "Regexp to match compilation warning from msbuild.") 52 53 ;; Notes on xbuild and devenv commonalities 54 ;; 55 ;; These regexes were tailored for xbuild, but apart from the concurrent 56 ;; build-marker ("1>") they share exactly the same match-markers. 57 ;; 58 ;; If we don't exclude the match-markers explicitly, these regexes 59 ;; will also be used to match for devenv as well, including the build-marker 60 ;; in the file-name, causing the lookup to fail. 61 ;; 62 ;; So if we don't want devenv to fail, we actually need to handle it in our 63 ;; xbuild-regexes, but then we automatically get devenv-support for free. 64 65 (defconst csharp-compilation-re-xbuild-error 66 (concat 67 "^[[:blank:]]*\\(?:[[:digit:]]+>\\)?" 68 "\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?" 69 ;; handle weird devenv output format with 4 numbers, not 2 by having optional 70 ;; extra capture-groups. 71 "\\(?:,\\([0-9]+\\)\\)*): " 72 "error [[:alnum:]]+: .+$") 73 "Regexp to match compilation error from xbuild.") 74 75 (defconst csharp-compilation-re-xbuild-warning 76 (concat 77 "^[[:blank:]]*\\(?:[[:digit:]]+>\\)?" 78 "\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?" 79 ;; handle weird devenv output format with 4 numbers, not 2 by having optional 80 ;; extra capture-groups. 81 "\\(?:,\\([0-9]+\\)\\)?*): " 82 "warning [[:alnum:]]+: .+$") 83 "Regexp to match compilation warning from xbuild.") 84 85 (defconst csharp-compilation-re-dotnet-error 86 "\\([^\r\n]+\\) : error [A-Z]+[0-9]+:") 87 88 (defconst csharp-compilation-re-dotnet-warning 89 "\\([^\r\n]+\\) : warning [A-Z]+[0-9]+:") 90 91 (defconst csharp-compilation-re-dotnet-testfail 92 (concat 93 "[[:blank:]]+Stack Trace:\n" 94 "[[:blank:]]+at [^\n]+ in \\([^\n]+\\):line \\([0-9]+\\)")) 95 96 97 (eval-after-load 'compile 98 (lambda () 99 (dolist 100 (regexp 101 `((dotnet-testfail 102 ,csharp-compilation-re-dotnet-testfail 103 1 2) 104 (xbuild-error 105 ,csharp-compilation-re-xbuild-error 106 1 2 3 2) 107 (xbuild-warning 108 ,csharp-compilation-re-xbuild-warning 109 1 2 3 1) 110 (msbuild-error 111 ,csharp-compilation-re-msbuild-error 112 csharp--compilation-error-file-resolve 113 2 114 3 115 2 116 nil 117 (1 compilation-error-face) 118 (4 compilation-error-face)) 119 (msbuild-warning 120 ,csharp-compilation-re-msbuild-warning 121 csharp--compilation-error-file-resolve 122 2 123 3 124 1 125 nil 126 (1 compilation-warning-face) 127 (4 compilation-warning-face)) 128 (dotnet-error 129 ,csharp-compilation-re-dotnet-error 130 1) 131 (dotnet-warning 132 ,csharp-compilation-re-dotnet-warning 133 1 nil nil 1))) 134 (add-to-list 'compilation-error-regexp-alist-alist regexp) 135 (add-to-list 'compilation-error-regexp-alist (car regexp))))) 136 137 (provide 'csharp-compilation) 138 139 ;;; csharp-compilation.el ends here