Logtalk for VSCodeA VSCode extension that provides language support for Logtalk. Forked from the original plugin by Arthur Wang. Requires Logtalk 3.94.0 or later and a supported Prolog backend. As this extension uses supporting code that's part of the Logtalk distribution, use of the latest Logtalk version is strongly recommended. 🙏 Sponsored by Permion and GitHub Sponsors. Installation | Features | Configuration | Known Issues | Development | Acknowledgements | Licence InstallationThis extension can be installed directly from VSCode, from its Marketplace, or by downloading its This extension must be configured before it can be used. Notably, the following settings are required:
For details, see Configuration. This extension includes a walkthrough that can be accessed from the VSCode "Welcome" page after installing the extension. It can also be accessed from the command palette using the command "Welcome: Open Walkthrough...". The walkthrough guides you in configuring the extension and checking that basic functionality is working. Features
Syntax highlighting
Indentation, snippets, and auto-completion
Note: Relations between entities use choice snippets: The snippets for entity opening directives and predicate scope directives are all triggered by natural prefix, i.e. Refer to the table below for other snippets:
Formatting supportExperimental support for the "Format Document" and "Format Selection" commands is provided. The formatting rules follow the Logtalk coding style guidelines. Currently, the following formatting rules are supported:
You can verify the changes before saving them using the "File: Compare Active File with Saved" command, which also allow selectively undoing formatting changes. Linter
Quick fixes are provided for some errors and warnings. When applying quick fixes, notably those that delete and insert code, the positions of the warnings and errors later in the file may not be updated, thus preventing further quick fixes to be applied or applied correctly. In this case, save your changes and re-run the linter by using the "Make - Reload" command (note that this command can be called automatically when saving a file using the CommandsMost commands, notably those that run the developer tools, require the code to be loaded, typically by opening the project loader file and selecting the "Load File" menu or context menu item. Project commandsProject (workspace) commands can be triggered from the command palette by typing 'Logtalk' in the input box to pop up the list of all commands of this extension. In this case, the commands resort to the first workspace root folder in the case of multi-root workspaces. Alternatively, these commands can be triggered from the explorer/context menu via right-click (Ctrl+click on Windows and Linux, Cmd+click on macOS) in a Logtalk source file in the Explorer.
The "Create Project" command is usually called from the command palette. It asks for the folder where to copy the renamed sample files. The "Load Project" command looks for a The "Scan Project Dead Code", "Compute Project Metrics", "Generate Project Documentation", and "Generate Project Diagrams" commands require that the project code is already loaded. Quick fixes are provided for some dead code warnings. The output of the "Run Project Testers" and "Run Project Doclets" commands is displayed in the "OUTPUT" pane "Logtalk Testers & Doclets" channel. There are also "Test Documentation Cache" add "Refresh Documentation Cache" commands that can be used for testing and refreshing the documentation cache used by the Logtalk chat participant. These commands can only be called from the command palette. Directory and source file commandsThese commands can be triggered from the editor/context menu via right-click in the editor area. These commands can also be triggered from the command palette assuming there's an active editor window.
The "Load Directory" command looks for a The "Run Tests" command adds failed tests to the "PROBLEMS" pane. Quick fixes are provided for some test definition warnings. The "Scan Dead Code" command adds dead code warnings to the "PROBLEMS" pane. Quick fixes are provided for some dead code warnings. Jupyter commandsThese commands allow opening Logtalk source files and Markdown files as Jupyter notebooks, plus pairing and syncing notebook representations.
These commands are only available when Jupytext 1.16.7 or a later version is installed. See also the "logtalk.jupytext.path" setting below. Integrated terminal process commandsThese commands don't depend on the directory of a file selected by right-clicking in a workspace file or in an active editor window but only on the Logtalk process running in the integrated terminal. They can be triggered from the editor/context menu via right-click in the editor area or from the command palette.
Extension logging commandsThese commands are only available from the command palette. They are meant for helping with debugging and troubleshooting the extension.
Code NavigationCode navigation features require the code to be loaded, typically by using the "Load Project" command or by opening the project loader file and using the "Load File" command from the editor/context menu. Additionally, code must be compiled with the Go to DeclarationRight-click on a predicate (or non-terminal) name and select the "Go to Declaration" context menu item to go to the predicate (or non-terminal) scope directive. Go to DefinitionRight-click on a predicate (or non-terminal) name in a goal or predicate directive and select the "Go to Definition" context menu item to go to the first clause defining the predicate. Note that some definitions may only be resolved at runtime (e.g., in a message to self goal or when dynamic predicates are used). When a definition is not found, try in alternative to go to the declaration and then to the implementations. Go to Type DefinitionEntities (objects, protocols, and categories) are interpreted as types. Right-click on an entity name and select the "Go to Type Definition" context menu item to go to the entity opening directive. Go to ReferencesRight-click on a predicate (or non-terminal) name in a scope directive, Right-click on an entity name in an entity opening directive to find references to it in other entity opening directives (i.e., entities in an implementing, importing, complementing, extending, instantiating, or specializing relation with the selected entity), Go to ImplementationsRight-click on a predicate (or non-terminal) name in a scope directive and select the "Go to Implementations" or "Find All Implementations" context menu items. Note that you can go to a predicate scope directive by right-clicking in the predicate name in a goal and selecting the "Go to Declaration" context menu item. Right-click on a protocol name in its entity opening directive to find implementations of the protocol. Note that you can go to an entity opening directive by right-clicking in an entity name and selecting the "Go to Type Definition" context menu item. Go to Symbol in Editor...Symbols include entity identifiers in entity opening directives, predicate (and non-terminal) indicators in predicate scope directives, first predicate clause, and first non-terminal rule. Note that VSCode doesn't support customization of symbol kind names and icons, thus forcing adapting the pre-defined names and icons. This feature doesn't require the code to be loaded. Go to Symbol in Workspace...Symbols include entity identifiers in entity opening directives, predicate (and non-terminal) indicators in predicate scope directives, first predicate clause, and first non-terminal rule. Note that VSCode doesn't support customization of symbol kind names and icons, thus forcing adapting the pre-defined names and icons. This feature doesn't require the code to be loaded. Show Call HierarchyRight-click on a predicate (or non-terminal) name in a goal or in a clause head and select the "Show Call Hierarchy" context menu item to browse callers and callees of the selected predicate (or non-terminal). Note that callers and callees that can only be resolved at runtime (e.g., in a message to self goal or when dynamic predicates are used) may not be returned. Show Type HierarchyRight-click on an entity name and select the "Show Type Hierarchy" context menu item to browse ancestors and descendants of the selected entity. Here, ancestor is interpreted as any entity from which the selected entity inherits, and descendant is interpreted as any entity that inherits from the selected entity. Refactoring supportSeveral refactoring operations are supported. Users should commit their work before using this feature and preview the changes (when available) before applying them (see also the Code extractionAn "Extract protocol" refactoring operation is available when the user right-clicks on an object or category name in their opening entity directive and uses the "Refactor" context menu item or the "Refactor" command palette item. The name of the protocol is derived from the name of the selected entity. The user is asked to confirm the file name and file location. The extracted code includes all predicate declarations for the selected entity. The extracted code is always copied verbatim, with no changes to the indentation or whitespace. A "Replace magic number with predicate call" refactoring operation is available when the user selects a number in a rule body and uses the "Refactor" context menu item or the "Refactor" command palette item. The user is asked to enter the name of the predicate to be created and its scope. The predicate is created with the number as its single argument and added to the entity. The selected number is replaced with a variable derived from the predicate name and the rule body is updated with a call to the new predicate inserted after the clause head. Three other code extraction refactoring operations are supported when the user selects one or more lines and uses the "Refactor" context menu item or the "Refactor" command palette item:
Resolve include/1 directiveWhen the user selects a region of code that contains an Symbol renamingEntity, predicate, and non-terminal rename support is available. To rename a predicate (non-terminal), right-click on the predicate (non-terminal) name in a predicate directive, fact, rule head, or goal and select the "Rename Symbol" context menu item. To rename an entity, right-click on the entity name and use the "Go to Type Definition" context menu item to go to the entity opening directive. Then, right-click on the entity name and select the "Rename Symbol" context menu item. Entity parameters refactoringTo add a new parameter to an object (or category), right-click on the object (or category) name in its opening directive and select the "Add parameter to object/category" context menu item. To reorder the parameters of an object (or category), right-click on the object (or category) name in its opening directive and select the "Reorder object/category parameters" context menu item. To remove a parameter from an object (or category), right-click on the object (or category) name in its opening directive and select the "Remove parameter from object/category" context menu item. New parameters must use parameter variable syntax (i.e., Predicate and non-terminal argument refactoringTo add a new argument to a predicate (or non-terminal), right-click on the predicate name in a directive, goal, or clause head and select the "Add argument to predicate/non-terminal" context menu item and enter the new argument name and position. To reorder the arguments of a predicate (or non-terminal), right-click on the predicate name in a directive, goal, or clause head and select the "Reorder predicate/non-terminal arguments" context menu item and enter the new argument order. To remove an argument from a predicate (or non-terminal), right-click on the predicate name in a directive, goal, or clause head and select the "Remove argument from predicate/non-terminal" context menu item and enter the argument position. Known issues
Debugging supportWhen debugging in the integrated terminal using the This extension provides a button with a Logtalk icon at the top-right corner to toggle debugging (equivalent to the Breakpoints and log points can be added and removed using the "Run" menu breakpoint items. Clicking at the left of a line number in an editor window, in the same line as a clause head, creates a clause breakpoint represented by a red dot. Control-clicking in this red dot allows the breakpoint to be removed, edited, or disabled. But, although VSCode supports it, a Logtalk breakpoint cannot be a combination of log point and different types of breakpoints. If you edit a breakpoint, you must keep its singular type. Function breakpoints are interpreted as predicate (or non-terminal) spy points by entering a predicate indicator (or a non-terminal indicator) or as context spy points by entering a Changes to spy points via user-typed queries in the integrated terminal are not reflected in the VSCode display of current breakpoints. A particular case is when, at a leashed port, you enter the VSCode usability issues that affect debugging support:
Hover contentsHover contents is provided for built-in directives, built-in predicates, and built-in methods. Chat ParticipantExperimental. The Requirements:
Usage: Type
The slash commands work best with keywords. For example, Examples:
Features:
The chat participant automatically detects your Logtalk version from ConfigurationThe user can configure settings via the VSCode menu Settings are divided between required and optional settings. If you're migrating from an old version of this extension, you may need to delete the old settings (from the Required settingsLogtalk home and user paths
No defaults (VSCode doesn't support using environment variables to define settings). Must be set to the Prolog backend
No default. Possible values are Optional settingsIn most cases, the required settings are enough for full extension functionality. But they assume default installations for Logtalk and the Prolog backends. On Windows, they also assume the default installation of PowerShell 7. When that's not the case, the optional settings listed below allow overriding the defaults that are derived from the required settings. On Windows, use forward slashes in settings that require paths. Use the On a POSIX system (e.g., macOS or Linux), use the For settings that specify scripts, see their man pages for their available options. Logtalk executable
Absolute path to the Logtalk executable or integration script and its arguments. The
On POSIX systems (e.g., macOS or Linux), the Example using the legacy array format (assuming a POSIX system, using SWI-Prolog as the backend, with the integration scripts installed at
Example using the dictionary format for multiple backends (assuming a POSIX system with integration scripts installed at
On Windows systems, use the absolute path to the PowerShell 7 executable and set the arguments to load the Logtalk integration script. For example (assuming the default Logtalk installation) and using SWI-Prolog as the backend:
Example using the dictionary format on Windows for multiple backends:
Logtalk project testers
Absolute path to the
On Windows systems, these settings must be set differently. For example (assuming the default Logtalk installation) and using SWI-Prolog as the backend:
Logtalk project doclets
Absolute path to the
On Windows systems, these settings must be set differently. For example (assuming the default Logtalk installation) and using SWI-Prolog as the backend:
Logtalk project documentation
Absolute path to the documentation script and its arguments for converting the XML files generated by the Logtalk
On Windows systems, these settings must be set differently. For example (assuming the default Logtalk installation):
Logtalk project diagrams
Absolute path to the script for converting the
On Windows systems, these settings must be set differently. For example (assuming the default Logtalk installation):
Diagrams script for converting the Timeout for waiting to run conversion scripts
The number of milliseconds to wait before running the scripts that convert Code metrics and test results code lens
Enables displaying inline test results (including code coverage when collected) using code lens in both the test object and the tested entity source files opened in the editor. It also enables displaying inline entity cyclomatic complexity after computing code metrics. The tests and metrics data is persistent and can be updated by re-running tests and re-computing metrics (e.g., by simply clicking in the inline data). This setting can be toggled using the "Toggle Code Lens" command. Jupytext path
Absolute path to the Run Logtalk make on save
Automatically call the "Logtalk: Make - Reload" command when saving a Logtalk source file. Known IssuesCode issues detected when running the "Make - Check" or "Make - Circular" commands are displayed in the integrated terminal but not added to the "PROBLEMS" pane. But when an issue is reported in a source file, you can right-click (Ctrl+click on Windows and Linux, Cmd+click on macOS) in the file path to navigate to the issue location. On Windows systems, the file paths on the "PROBLEMS" pane may not be relative to the workspace directory depending on the Prolog backend. This is a consequence of some backends "normalizing" file paths in a way that breaks VSCode computing of the relative paths. E.g., paths are relative when using GNU Prolog but absolute when using SWI-Prolog or SICStus Prolog. On Windows systems, some Prolog backends such as ECLiPSe and XSB are not usable due to file path representation issues. If you're migrating from the old "VSC-Logtalk" extension, you may see duplicated context menu items even after uninstalling it. If that happens, delete any extension leftovers in the VSCode triggers the "Go to Definition" computations if the cursor happens to be in the middle of some text when pressing the command (macOS) or control (Windows, Linux) keys to type any keyboard command shortcut without waiting for or requiring cursor movement. It also doesn't allow disabling this "feature". This extension implements mitigation measures to avoid most accidental "Go to Definition" computations. DevelopmentDeveloped and tested with Logtalk 3.94.0 and VSCode 1.103 on macOS 14.7 and Windows 10 with Node 24.6. After running See the CHANGELOG.md file for the most recent changes. Contributions and bug reports are most welcome. Publishing
AcknowledgementsThis extension started as a fork of the VSC-Logtalk extension by Arthur Wang. Due to Arthur's current unavailability and since-deprecated modules, this extension has been adopted by new maintainers. Renaming the fork was necessary to allow publishing to the VSCode Marketplace and avoid conflicts with the original extension. Arthur Wang (Original Author)"The original author of this extension thanks Professor Paulo Moura, who is the author of Logtalk, for his patient help and support. Syntax highlighting, some snippets, and some commands are integrated from his distro of Logtalk." LicenseThis extension is published under the MIT license. |