vscode xHarbourLanguage support for Harbour and xHarbour (
Contents
RequirementsYou need a working
A wrapper only needs to compile whatever file it's given, in that file's own
directory — several features below (validation, Language features
Diagnostics / validationTwo independent mechanisms feed the Problems panel:
Aliasing features (fork-specific)These settings exist for codebases that lean on preprocessor macros
(
|
| Mode | Foo(x) |
Foo:Exec(x) |
|---|---|---|
either (default) |
allowed | allowed |
suffixOnly |
flagged as Error | allowed |
bareOnly |
allowed | flagged as Error |
This never applies to standard RTL functions (Len:Exec() wouldn't make
sense to require) — only to functions your workspace actually defines.
Because Foo:Exec(...) isn't real xHarbour syntax for calling a plain
function — the compiler sees a bare identifier before : and, unable to
tell whether it's Foo the function or an undeclared memvar, emits
Warning W0001 Ambiguous reference — the compiler-backed validator
specifically suppresses that one warning for identifiers immediately
followed by :<a configured suffix>(, while leaving every other ambiguous
reference on the same or other lines untouched.
harbour.aliases.commandRules
Declares #command/#xcommand-style macro rules once, in settings, instead
of pasting a #command line at the top of every .prg:
"harbour.aliases.commandRules": [
{ "match": "DEFAULT <v> := <x>", "replace": "Default( <v>, <x> )" }
]
is equivalent to having this at the top of every file compiled in that workspace:
#command DEFAULT <v> := <x> => Default( <v>, <x> )
Each rule is written to a generated .ch file next to the source file being
compiled and passed to the compiler with -u+<file> on every
validate/build — so it works even if harbour.compilerExecutable is a
container wrapper that only mounts that one directory. The first word of
match (DEFAULT above) is also registered automatically as a
customKeyword, so you don't need a separate entry for it.
Commands
| Command | Title | What it does |
|---|---|---|
harbour.getDbgCode |
Harbour: Get debugger code | Opens the source of the in-process debugger library (dbg_lib.prg) as a new untitled document — save it into your project (or, better, compile it into a library you link against) to enable debugging. |
harbour.setupCodeFormat |
Harbour: setup code style | Opens a webview to configure the document formatter settings interactively, with a live preview. |
Settings reference
Compiler / validation
| Setting | Default | Description |
|---|---|---|
harbour.compilerExecutable |
"harbour" |
Path (or wrapper script) used for validation and build tasks. |
harbour.validating |
true |
Run the compiler-backed validator on open/save. |
harbour.warningLevel |
1 (0–3) |
Compiler -w level used for validation. |
harbour.extraIncludePaths |
[] |
Extra -I paths; supports ${workspaceFolder}. |
harbour.extraOptions |
"" |
Free-form extra compiler flags. |
harbour.workspaceDepth |
2 |
Subfolder depth the language server scans for .prg/.ch/.c/.h files to index for cross-file features (hover, go to definition, checkUndefinedFunctions). 0 = only files you have open. |
harbour.checkUndefinedFunctions |
false |
See Diagnostics. |
harbour.decorator |
true |
Decorate matching if/endif, for/next, while/endwhile, etc. |
Aliases — see above.
| Setting | Default |
|---|---|
harbour.aliases.customKeywords |
[] |
harbour.aliases.callSuffixes |
[] |
harbour.aliases.callSuffixMode |
"either" |
harbour.aliases.commandRules |
[] |
Formatter — set via harbour.setupCodeFormat, or directly:
| Setting | Default |
|---|---|
harbour.formatter.indent.funcBody |
true |
harbour.formatter.indent.variables |
true |
harbour.formatter.indent.logical |
true |
harbour.formatter.indent.cycle |
true |
harbour.formatter.indent.switch |
true |
harbour.formatter.indent.case |
true |
harbour.formatter.replace.not |
"use !" ("ignore" / "use .not." / "use !") |
harbour.formatter.replace.asterisk |
"use //" ("ignore" / "use //" / "use *" / "use &&") |
harbour.formatter.replace.amp |
"use //" ("ignore" / "use //" / "use &&") |
Code formatting
Run Harbour: setup code style to open a live-preview editor for the
harbour.formatter.* settings above — check the boxes/pick the options you
want and the sample on the right updates immediately; changes are written
straight to your settings.
Debugging
The extension ships a harbour-dbg debug adapter that talks to a small
in-process debugger library over a socket (default port 6110).
- Run Harbour: Get debugger code, save the file into your project (or
compile it into a library and link it in), and compile your program
with debug info (
-b). - Add a launch configuration — the command palette's "Add configuration"
offers ready-made snippets for launch, attach-by-path, and
attach-by-picking-a-running-process. Example
launch.json:
{
"type": "harbour-dbg",
"request": "launch",
"name": "Launch current program",
"program": "${workspaceFolder}/myapp",
"workingDir": "${workspaceFolder}/",
"sourcePaths": ["${workspaceFolder}"],
"stopOnEntry": true
}
request can be "launch" or "attach" (by program path or by
process id — "${command:pickProcess}" opens a picker of running
matching processes). See the protocol the debugger and the extension speak
to each other in debugger.md if you need to build a
compatible client.
Build tasks
Two task types are contributed:
Harbour— runsharbour.compilerExecutabledirectly on one file.output:"portable"(.hrb) or"C code"(c-type:compact/normal/verbose/real C Code).HBMK2— runshbmk2(found next toharbour.compilerExecutable) withplatform/compiler/extraArgs/debugSymbols, and an optionalsetupBatch(or per-OSwindows/linux/osxoverrides) to source environment variables before building — handy for MSVC'svcvars*.bator similar toolchain setup scripts.
Example tasks.json entry:
{
"label": "build",
"type": "HBMK2",
"input": "${file}",
"extraArgs": ["-gtcgi", "-w3"],
"group": { "kind": "build", "isDefault": true }
}
Snippets
A small set of statement snippets (for, for each, do while, etc.) is
contributed for the harbour language — see
harbour.code-snippets.
Building the extension from source
npm install # single node_modules for both the
# extension host and the language
# server (src/client, src/server)
npx webpack --mode production # builds dist/extension.js,
# dist/debugger.js, dist/hb_server.js
npx vsce package --no-dependencies # -> vscode-xharbour-lang.vsix
code --install-extension vscode-xharbour-lang.vsix
npm run prelanch (webpack --mode development) is the pre-launch task
for F5 (Run Extension) in this repo's own .vscode/launch.json.
License
This project is GPL-3.0-or-later (see LICENSE) — the
original server package it's built on was GPL-licensed, and a combined
work built on GPL code stays GPL regardless of how much is added or
rewritten on top of it. The original client package was MIT-licensed;
that text is preserved unmodified in
LICENSE-MIT-client-original.txt for
attribution. Full details in NOTICE.md.