Skip to content

BeRo1985/vscode-language-pascal

 
 

Repository files navigation

Pascal for Visual Studio Code

This extension adds support for the Pascal Language to Visual Studio Code. It works with Delphi and FreePascal/Lazarus and supports:

  • Colorization
  • Snippets
  • Format Code
  • Task Build
  • Code Navigation
    • Go to Symbol
    • Go to Definition
    • Peek Definition
    • Find All References

Installation

Press F1 in VSCode, type ext install and then look for Language Pascal.

Usage

Colorization

Full syntax highlight for Pascal

syntax

Snippets

Almost 40 snippets available:

snippets

Format Code

Standardise your Pascal code! The extension uses external tools (engines) to format the code, so you must install them prior to use the Format Document and Format Selection commands.

If you intend to format pieces of selected texts instead of the entire file, you should use FreePascal PToP, because the Jedi Code Format only works for entire files.

Available settings

  • Choose the engine to be used (required)
    // ptop means FreePascal PToP
    "pascal.formatter.engine": "ptop"
    
    // jcf means Jedi Code Format 
    "pascal.formatter.engine": "jcf"
  • Indicates the engine app path (required)
    "pascal.formatter.enginePath": "C:\\FPC\\2.6.4\\bin\\i386-win32\\ptop.exe" 
  • Indicates the configuration file for the selected engine (optional)
    "pascal.formatter.engineParameters": "C:\\FPC\\2.6.4\\bin\\i386-win32\\default.cfg"

Code Navigation

  • Go to Symbol
  • Go to Definition
  • Peek Definition
  • Find All References

Navigate to any language element (methods, attributes, classes, interfaces, and so on) inside Pascal files.

It uses GNU Global, a source code tagging system, which means that it has some limitations if you compare with an AST parsing.

Installing and Configuring GNU Global

  1. You have to install 4 tools:
  1. Update your %PATH% Environment Variable (System)

Let's say you extract GNU Global and CTags in C:\gnu folder. The two new entries in %PATH% should be:

  • GNU Global: C:\gnu\glo653wb\bin
  • Excuberant Tags: C:\gnu\ctags58\ctags58

Also make sure Python is in %PATH%

  1. Create 2 new Environment Variables (System)

GNU Global uses CTags + Python Pygments as plugin in order to recognizes Pascal source code, so you have to configure them.

  • GTAGSCONF: C:\gnu\glo653wb\share\gtags\gtags.conf
  • GTAGSLABEL: pygments

py-envvar

NOTE: For now, it was tested only on Windows, but since these tools are multiplatform (in fact, it comes from Unix), it should work on Linux and Mac.

Available commands

Code Formatter

The extension seamlessly integrates with the Format Document and Format Selection commands Visual Studio Code.

format-code

There is also:

  • Pascal: Edit Formatter Parameters Opens/Generate the parameters file for the selected engine

Code Navigation

To enable Code Navigation, the extension depends on GNU Global and Exuberant Tags and for that, you must run gtags on the Root folder, so the tags are created. In order to make life easier, two commands where added:

  • Pascal: Generate Tags: Use this to create or reset the tags in the current project. You just have to do it once.
  • Pascal: Update Tags: Use this to update the tags for current project. You should use this command to update the references when any source code is updated.

Available Settings

New in version 0.9.0

  • Controls if the extension should automatically generate tags in projects opened for the first time
    "pascal.tags.autoGenerate": true

For huge projects, it may take some time to generate the tags. If you don't want that, just set pascal.tags.autoGenerate: false in that project.

Task Build

Use this Task Examples, so you can:

  • Compile Delphi and FreePascal Projects:
  • Navigate to Errors/Warnings/Hints, using the native View / Errors and Warnings command

compile

Building Tasks

If you want to build tasks (Task: Run Task Build) you can use the snippets below.

Delphi

Update two tags:

  • DCC32.EXE_PATH: The compiler location
  • YOUR_DELPHI_PROJECT.DPR: The project being built.
    {
		"version": "0.1.0",
		"windows": {
			"command": "DCC32.EXE_PATH"
		},
		"isShellCommand": true,
		"showOutput": "always",
		"args": ["YOUR_DELPHI_PROJECT.DPR"],
		"problemMatcher": {
			"owner": "external",
			"pattern": {
				"regexp": "^([\\w]+\\.(pas|dpr|dpk))\\((\\d+)\\)\\s(Fatal|Error|Warning|Hint):(.*)",
				"file": 1,
				"line": 3,
				"message": 5
			}
		}
    }

FreePascal

Update two tags:

  • FPC_BIN_PATH: The full compiler location. If its PATH is already in Environment Variables, simply use FPC_BIN filename
  • YOUR_FREEPASCAL_PROJECT_OR_FILE: The project/file being built.
    {
		"version": "0.1.0",
		"windows": {
			"command": "FPC_BIN_PATH"
		},
		"linux": {
			"command": "FPC_BIN_PATH"
		},
		"isShellCommand": true,
		"showOutput": "always",
		"args": ["YOUR_FREEPASCAL_PROJECT_OR_FILE"],
		"problemMatcher": {
			"owner": "external",
			"pattern": {
				"regexp": "^([\\w]+\\.(p|pp|pas))\\((\\d+)\\,(\\d+)\\)\\s(Fatal|Error|Warning|Note):(.*)",
				"file": 1,
				"line": 3,
				"column": 4,
				"message": 6
			}
		}
    }

License

MIT © Alessandro Fragnani


Paypal Donations a ☕ if you enjoy using this extension 👍

About

Pascal language extension for Visual Studio Code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%