csharp-compilation.el (5182B)
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:]]+X \\(?:.+\n\\)" 94 "[[:blank:]]+Error Message:\n" 95 "[[:blank:]]+\\(?:.+\n\\)" 96 "\\(?:^Expected: \\(?:.+\n\\)\\)?" 97 "\\(?:^Actual: \\(?:.+\n\\)\\)?" 98 "[[:blank:]]+Stack Trace:\n" 99 "[[:blank:]]+at [^\n]+ in \\([^\n]+\\):line \\([0-9]+\\)")) 100 101 102 (eval-after-load 'compile 103 (lambda () 104 (dolist 105 (regexp 106 `((dotnet-testfail 107 ,csharp-compilation-re-dotnet-testfail 108 1 2) 109 (xbuild-error 110 ,csharp-compilation-re-xbuild-error 111 1 2 3 2) 112 (xbuild-warning 113 ,csharp-compilation-re-xbuild-warning 114 1 2 3 1) 115 (msbuild-error 116 ,csharp-compilation-re-msbuild-error 117 csharp--compilation-error-file-resolve 118 2 119 3 120 2 121 nil 122 (1 compilation-error-face) 123 (4 compilation-error-face)) 124 (msbuild-warning 125 ,csharp-compilation-re-msbuild-warning 126 csharp--compilation-error-file-resolve 127 2 128 3 129 1 130 nil 131 (1 compilation-warning-face) 132 (4 compilation-warning-face)) 133 (dotnet-error 134 ,csharp-compilation-re-dotnet-error 135 1) 136 (dotnet-warning 137 ,csharp-compilation-re-dotnet-warning 138 1 nil nil 1))) 139 (add-to-list 'compilation-error-regexp-alist-alist regexp) 140 (add-to-list 'compilation-error-regexp-alist (car regexp))))) 141 142 (provide 'csharp-compilation) 143 144 ;;; csharp-compilation.el ends here