|
23 | 23 |
|
24 | 24 | interface |
25 | 25 |
|
| 26 | +uses CustomCodeTool, CodeToolManager, CodeCache; |
| 27 | + |
26 | 28 | function MergePaths(Paths: array of string): string; |
27 | 29 | function GetConfigDirForApp(AppName, Vendor: string; Global: Boolean): string; |
28 | 30 | function URIToFileNameEasy(const UriStr: String): String; |
29 | 31 |
|
| 32 | +{ Return prefix for error message describing filename, line, column |
| 33 | + from ECodeToolError, if any. } |
| 34 | +function PositionForErrorPrefix(const E: ECodeToolError): String; overload; |
| 35 | + |
| 36 | +{ Return prefix for error message describing filename, line, column |
| 37 | + from TCodeToolManager, if any. } |
| 38 | +function PositionForErrorPrefix(const CodeToolBoss: TCodeToolManager): String; overload; |
| 39 | + |
30 | 40 | implementation |
31 | 41 |
|
32 | 42 | uses |
33 | | - SysUtils, URIParser, ujsonrpc; |
| 43 | + SysUtils, URIParser, |
| 44 | + ujsonrpc; |
34 | 45 |
|
35 | 46 | function MergePaths(Paths: array of string): string; |
36 | 47 | var |
@@ -94,6 +105,63 @@ function URIToFileNameEasy(const UriStr: String): String; |
94 | 105 | ); |
95 | 106 | end; |
96 | 107 |
|
| 108 | +const |
| 109 | + { Error prefix to display filename (may be ''), line, column. |
| 110 | + Note: line endings (#10, #13 or both) are ignored inside this, at least by VS Code. |
| 111 | + And \r \n are not interpreted as line endings, at least by VS Code. |
| 112 | + So we cannot make a newline break here. } |
| 113 | + SErrorPrefix = '%s(%d,%d): '; |
| 114 | + |
| 115 | +{ Return prefix for error message describing position (line, column) |
| 116 | + from ECodeToolError, if any. } |
| 117 | +function PositionForErrorPrefix(const E: ECodeToolError): String; |
| 118 | + |
| 119 | + function PosSet(const Pos: TCodeXYPosition): Boolean; |
| 120 | + begin |
| 121 | + Result := (Pos.X <> 0) and (Pos.Y <> 0); |
| 122 | + end; |
| 123 | + |
| 124 | + function PosToStr(const Pos: TCodeXYPosition): String; |
| 125 | + var |
| 126 | + CodeFileName: String; |
| 127 | + begin |
| 128 | + if Pos.Code <> nil then |
| 129 | + CodeFileName := ExtractFileName(Pos.Code.Filename) |
| 130 | + else |
| 131 | + CodeFileName := ''; |
| 132 | + Result := Format(SErrorPrefix, [CodeFileName, Pos.Y, Pos.X]); |
| 133 | + end; |
| 134 | + |
| 135 | +begin |
| 136 | + if E.Sender <> nil then |
| 137 | + begin |
| 138 | + if PosSet(E.Sender.ErrorNicePosition) then |
| 139 | + Exit(PosToStr(E.Sender.ErrorNicePosition)); |
| 140 | + if PosSet(E.Sender.ErrorPosition) then |
| 141 | + Exit(PosToStr(E.Sender.ErrorPosition)); |
| 142 | + end; |
| 143 | + Result := ''; |
| 144 | +end; |
| 145 | + |
| 146 | +function PositionForErrorPrefix(const CodeToolBoss: TCodeToolManager): String; |
| 147 | +var |
| 148 | + CodeFileName: String; |
| 149 | +begin |
| 150 | + Result := ''; |
| 151 | + if (CodeToolBoss.ErrorLine <> 0) and |
| 152 | + (CodeToolBoss.ErrorColumn <> 0) then |
| 153 | + begin |
| 154 | + if CodeToolBoss.ErrorCode <> nil then |
| 155 | + CodeFileName := ExtractFileName(CodeToolBoss.ErrorCode.Filename) |
| 156 | + else |
| 157 | + CodeFileName := ''; |
| 158 | + Result := Format(SErrorPrefix, [ |
| 159 | + CodeFileName, |
| 160 | + CodeToolBoss.ErrorLine, |
| 161 | + CodeToolBoss.ErrorColumn |
| 162 | + ]); |
| 163 | + end; |
| 164 | +end; |
97 | 165 |
|
98 | 166 | end. |
99 | 167 |
|
0 commit comments