Reputation: 33
I configured a task in VSCode to compile a Delphi 2005 dpk. It is working and returning the errors on the "problems view", but it is not showing that errors in the file.
I think it is happening because when I click on an error, I get the error message:
Unable to open 'sr075pro.pas': File not found (...projectfolder\sr075pro.pas)
But the file is in ...projectfolder\webservices\sr075pro.pas
.
I can't find a way to tell to the task that the file is in a subfolder. I tried to use the "relative" option on the "fileLocation" tag without sucess.
The error returned:
Compiling sa_webservices...
Borland Delphi Version 13.0 Copyright (c) 1983,99 Inprise Corporation
sr075pro.pas(99) Error: Undeclared identifier: 'ni'
sa_webservices.dpk(802) Fatal: Could not compile used unit 'sr075pro.pas'
My task configuration:
{
"version": "0.1.0",
"name": "Compilar",
"command": "C:\\Compilers\\compile.bat",
"suppressTaskName": true,
"isShellCommand": true,
"isBuildCommand": true,
"tasks": [
{
"taskName": "Compile sa_webservices",
"isBuildCommand": false,
"isTestCommand": false,
"showOutput": "always",
"args": [
"sa_webservices"
],
"problemMatcher": {
"owner": "external",
"fileLocation": "relative",
"pattern": {
"regexp": "^([\\w]+\\.(pas|dpr|dpk))\\((\\d+)\\)\\s(Fatal|Error|Warning|Hint):(.*)",
"file": 1,
"line": 3,
"message": 5
}
}
}
My compile.bat:
@echo off
@P:
@set arg1=%1
shift
...
if "%arg1%" == "sa_webservices" set arg2="webservices"
...
echo Compiling %arg1%...
cd\%arg2%
dcc32.exe -H -W -Q %arg1%.dpk
Upvotes: 3
Views: 1210
Reputation: 182551
It might be easier to find files in the problemMatcher in vscode 1.74, see file location search: v1.74 release notes. There is a new option search
for the fileLocation
property:
New file location method;
search
Previously, problem matchers needed to know exactly where to look for the problematic files, via the
fileLocation
property. The supported methods wereabsolute
,relative
, orautoDetect
(i.e., check for relative paths first and opt to absolute paths in case of failure).However, in workspaces that need to invoke various scripts residing in nested sub-directories, the developers could have a hard time setting up their tasks; since such scripts seldom report file paths in a unified manner (e.g., relative to the workspace's base directory).
To help alleviate the problem, a new file location method, named
search
, is introduced in this version. With this method, a deep file system search will be initiated to locate any captured path. See the example below on how to setup thesearch
file location method (although, all parameters are optional):// ... "fileLocation": [ "search", { "include": [ // Optional; defaults to ["${workspaceFolder}"] "${workspaceFolder}/src", "${workspaceFolder}/extensions" ], "exclude": [ // Optional "${workspaceFolder}/extensions/node_modules" ] } ], // ... } ``` ⚠️ Of course, users should be wary of the possibly **heavy file system searches** (e.g., looking inside `node_modules` directories) and set the `exclude` property with discretion.
Upvotes: 1
Reputation: 45343
Your task configuration is wrong. First of all you don't close all brackets but I guess it's a mistake made by copying and pasting it here on StackOverflow. Otherwise the task configuration wouldn't have worked at all.
Now to the real problem: DCC32 produces hints and warnings containing relative file paths. These paths are relative to the project file. In your task configuration you define the compiler's output to contain relative paths by setting
"fileLocation": "relative"
Visual Studio Code doesn't know how to build the correct absolute path from the relative paths given by the compiler message. So it guesses your current ${workspaceRoot}
(in your case it's projectfolder
) would be the absolute path.
This explains why you see errors and warnings which contain wrong file paths. In order to get the correct paths you'll need to tell VSCode the correct path to combine the relative paths with.
You do this by simply adding the correct path to the fileLocation
entry in you tasks.json
:
"fileLocation": ["relative", "${workspaceRoot}\\webservices"]
The entire tasks.json looks like that:
{
"version": "0.1.0",
"name": "Compilar",
"command": "C:\\Compilers\\compile.bat",
"suppressTaskName": true,
"isShellCommand": true,
"isBuildCommand": true,
"tasks": [
{
"taskName": "Compile sa_webservices",
"isBuildCommand": false,
"isTestCommand": false,
"showOutput": "always",
"args": [
"sa_webservices"
],
"problemMatcher": {
"owner": "external",
"fileLocation": ["relative", "${workspaceRoot}\\webservices"],
"pattern": {
"regexp": "^([\\w]+\\.(pas|dpr|dpk))\\((\\d+)\\)\\s(Fatal|Error|Warning|Hint):(.*)",
"file": 1,
"line": 3,
"message": 5
}
}
}
]
}
Upvotes: 1