arthwang / vsc-prolog

A VS Code extension that provides language support for prolog
MIT License
95 stars 21 forks source link

VSC-Prolog

A VS Code extension which provides language support for Prolog (mainly for SWI-Prolog and some features for ECLiPSe).


Features | Configurations | Debugger Settings | Commands & Keybindings | Bug Reporting

Note before installation

This extension can be installed via extensions viewlet of VS Code or 'Extensions: install extension' command from the command palette. The author notices that it is developed and tested in SWI-Prolog 7.4.2, ECLiPSe 6.1 and VS Code 1.15 on Debian 9.0 (stretch). It's tested under Windows 10 but not other environments.

Features

Feature descriptions and usages

Syntax highlighting

Predicate snippets

Information hovers

Hovers show Document information about the predicate under the mouse cursor.

hover

Grammar linter

Edit helpers

Import or Dynamic predicate helper

This feature only works in SWI-Prolog.

Clicking on the squiggle indicating 'undefined predicate' lights the yellow bulb in the left margin besides the line number. A suggesition list is presented when you click the bulb that includes 'add dynamic ' for the undefined predicate or 'import' it if VSC-Prolog finds it could be exported from some module(s). Triggering 'Add dynamic' inserts the predicate indicator into dynamic directive, or creates such a directive if no one exists. 'Add use_module' inserts ':- use_module' directive with the predicate indicator whithin the import list.

import

Export helper

This feature only works in SWI-Prolog.

Move cursor to the head of a clause or a fact to be exported and trigger the command 'Prolog: export predicate under cursor' via command palette or right click the predicate to pop up the Editor/context menu which contains the command. Then VSC-Prolog inserts :- module/2 if module is not defined or adds the predicate indicator to the export list otherwise. After that a message box displays that asks for if adding structured comment for the predicate and comment lines are inserted above the head of the clause if 'yes' chosen, you should edit the comments of course.

export

Recursion helper

Leading dot (only spaces before it) of a line repeat the above nearest predicate or the head of current clause being edited if last line ends with comma, in which case the recursive variable change accordingly as intelligent as possible. recursion

Anonymous variables helper

Typing underscore in front of any parameters makes the parameter an anonymous variable. anonyvar

Load active source file and query goals

Go to definition of predicate under cursor

Show all references of predicate under cursor

Right click a predicate in editor, then trigger the command 'Find all references' from the editor context menu. All references of the predicate will be displayed in a popup panel.

findrefs

Refactor predicate under cursor

Right click a predicate in editor, then trigger the command 'Refactor predicate under cursor' from the editor context menu. VSC-Prolog pops up a message box to ask for user confirmation and then an input box shows off to accept new predicate name that is used to replace the original one in all the references and its definition clause head(s).

If the user selects a builtin or foreign predicate and confirms in the warning box, all the predicate functor names of referencs would be replaced but the definition remains unchanged. This maybe is useful if you want to substitute a predicate with the same arity.

You'd better to commit the current stage of the version control system in VS Code before refactoring action in order to rollback refactoring results easily with one command of 'discard all changes' when the results are not what you expected.

refactoring

Code formatter

This feature only works on linux system.

Code formatting is implemented by calling portray_clause, so the beautification style is depended on portray_clause. Thus some limits should be mentioned.

Requirements

Latest versions of VS code and SWI-Prolog/ECLiPSe installed.

Configurations

Debugger settings

Every project must have a launch.json configuration file under .vscode directory before starting debugging. VSC-Prolog's launch.json schema is excerpted as follows from the package.json of VSC-Prolog project. This file can be edited directly after generated for the first time to debug.

Commands keybindings

keybindings

Known Issues

Release Notes

Bug reporting

Feel free to report bugs or suggestions via issues

Contributions

Pull requests are welcome.

Acknowledgements

I would like to thank the VS Code team of Microsoft for providing this powerful platform. I've read over many source files of extensions shipped with VS Code and other language support extensions such as php, java, etc. I thank Professor Jan Wielemaker who is known as the original author of SWI-Prolog for his many professional and patient helps about SWI-Prolog system when I consulted on SWI-Prolog forum. Some segments of codes of this extension are gratefully borrowed from other resources such as Sublimeprolog tmlanguage syntax yaml file, SWI-Prolog source files, etc. The backend of 'find all references' and 'refactor predicate under cursor' mainly comes from gist code of github of Jan Wielemaker. I thank Joachim Schimpf for his help in supporting for ECLiPe clp.

License

MIT