I've published a VS Code extension for SWI-Prolog support

1,850 views
Skip to first unread message

Arthur Wang

unread,
Aug 14, 2017, 9:48:33 AM8/14/17
to SWI-Prolog
Hi All,

The features implemented: 

Environment developed and tested:  swipl 7.4.2,  vscode 1.15, on debian 9.0 (stretch).

I'd like to thank Professor Jan Wielemaker for his many helps when I consulted here on this forum during the development of the extension.

Evaluation, bug reporting, suggestions and PR are all welcome!


Wish vscode users of swipl enjoy it :)

Arthur Wang

Wouter Beek

unread,
Aug 14, 2017, 3:52:50 PM8/14/17
to Arthur Wang, SWI-Prolog
Hi Arthur,

Based on the extensive description in the project's README file this
looks to me like a _very_ good editing mode for SWI-Prolog.
Especially the ability to look up the documentation of a predicate in
a popup looks amazing to me. I always have a browser tab with the
SWI-Prolog web site open next to my editor in which I type in search
queries for predicates I'm looking at, which is quite cumbersome.

The built-in Prolog mode in GNU Emacs (my daily editor, alas) is
absolute rubbish. It does not even do syntax coloring or indentation
right. The two editors that I have used in the past (jEdit and Vim)
had only slightly better Prolog support. None of them even came near
supporting advanced features like auto-completion and coding
templates, which your package does deliver. Notice that these
editors/modes have been around for decades, but yours surpasses them
greatly.

Thanks to your work, one of the newest text editors around, Visual
Studio Code, may well be the best text editor for writing Prolog code
today. This is very impressive work. Are you considering a
submission to ICLP about this? IMO the community would benefit from a
focus on supporting the actual programmer in writing logic programs.

Keep up the good work!

---
Best regards,
Wouter Beek.
> --
> You received this message because you are subscribed to the Google Groups
> "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to swi-prolog+...@googlegroups.com.
> Visit this group at https://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

Arthur Wang

unread,
Aug 14, 2017, 10:01:26 PM8/14/17
to SWI-Prolog, rthr...@gmail.com, w.g.j...@vu.nl
Hi Wouter,
Thank you very much for your praise to my work of VSC-Prolog. 
I like prolog language very much, but unsatisfied with its development
tools for long time. Now I'm working in a project with swipl as backend and
TypeScript as front end language.  I'm amazed by the Intellisense of VS Code 
that makes programming in TypeScript with great joy. I can no longer put up with 
being annoyed while programming in swipl in emacs. It's the motivation for me
to develop VSC-Prolog: we really need a suitable environment for programming
in prolog. Now I finished it although there are lots to be improved. I can write prolog
codes nearly like TypeScript in VS Code :)

在 2017年8月15日星期二 UTC+8上午3:52:50,Wouter Beek写道:
Hi Arthur,

Based on the extensive description in the project's README file this
looks to me like a _very_ good editing mode for SWI-Prolog.
Especially the ability to look up the documentation of a predicate in
a popup looks amazing to me.  I always have a browser tab with the
SWI-Prolog web site open next to my editor in which I type in search
queries for predicates I'm looking at, which is quite cumbersome.

The built-in Prolog mode in GNU Emacs (my daily editor, alas) is
absolute rubbish.  It does not even do syntax coloring or indentation
right.  The two editors that I have used in the past (jEdit and Vim)
had only slightly better Prolog support.  None of them even came near
supporting advanced features like auto-completion and coding
templates, which your package does deliver.  Notice that these
editors/modes have been around for decades, but yours surpasses them
greatly.

Thanks to your work, one of the newest text editors around, Visual
Studio Code, may well be the best text editor for writing Prolog code
today.  This is very impressive work.  Are you considering a
submission to ICLP about this?  IMO the community would benefit from a

Of course I'm very glad to contribute my work to the community; I've gained  a 
lot from the community for years. But I found that the date of call for paper submission 
of ICLP has exceeded. What can I do?

With best regards,

Arthur Wang

Wouter Beek

unread,
Aug 15, 2017, 5:40:46 AM8/15/17
to Arthur Wang, SWI-Prolog
Hi Arthur,

There is always another ICLP, or some other LP event.

AFAIK the only thing that comes close to the features your mode
current provides is PDT, which is built on top of Eclipse:
https://github.com/pdt-git/public

Some of the features are also present in SWISH and the built-in PCE
Emacs editor.

I imagine that your mode, PDT, and SWISH in part rely on the same
backend features in SWI-Prolog. It would be interesting to see what
these backend features are and to compare how they are utilized in
different front-ends.

---
Cheers,
Wouter.

On Tue, Aug 15, 2017 at 4:01 AM, Arthur Wang <rthr...@gmail.com> wrote:
> Hi Wouter,
> Thank you very much for your praise to my work of VSC-Prolog.
> I like prolog language very much, but unsatisfied with its development
> tools for long time. Now I'm working in a project with swipl as backend and
> TypeScript as front end language. I'm amazed by the Intellisense of VS Code
> that makes programming in TypeScript with great joy. I can no longer put up
> with
> being annoyed while programming in swipl in emacs. It's the motivation for
> me
> to develop VSC-Prolog: we really need a suitable environment for programming
> in prolog. Now I finished it although there are lots to be improved. I can
> write prolog
> codes nearly like TypeScript in VS Code :)
>
> 在 2017年8月15日星期二 UTC+8上午3:52:50,Wouter Beek写道:
>>
>> Hi Arthur,
>>
>> Based on the extensive description in the project's README file this
>> looks to me like a _very_ good editing mode for SWI-Prolog.
>> Especially the ability to look up the documentation of a predicate in
>> a popup looks amazing to me. I always have a browser tab with the
>> SWI-Prolog web site open next to my editor in which I type in search
>> queries for predicates I'm looking at, which is quite cumbersome.
>>
>> The built-in Prolog mode in GNU Emacs (my daily editor, alas) is
>> absolute rubbish. It does not even do syntax coloring or indentation
>> right. The two editors that I have used in the past (jEdit and Vim)
>> had only slightly better Prolog support. None of them even came near
>> supporting advanced features like auto-completion and coding
>> templates, which your package does deliver. Notice that these
>> editors/modes have been around for decades, but yours surpasses them
>> greatly.
>>
>> Thanks to your work, one of the newest text editors around, Visual
>> Studio Code, may well be the best text editor for writing Prolog code
>> today. This is very impressive work. Are you considering a
>> submission to ICLP about this? IMO the community would benefit from a
>
>
> Of course I'm very glad to contribute my work to the community; I've gained
> a
> lot from the community for years. But I found that the date of call for
> paper submission
> of ICLP has exceeded. What can I do?
>
> With best regards,
>
> Arthur Wang
>
>

Arthur Wang

unread,
Aug 15, 2017, 6:14:42 AM8/15/17
to SWI-Prolog, rthr...@gmail.com, w.g.j...@vu.nl
Hi Wouter,

在 2017年8月15日星期二 UTC+8下午5:40:46,Wouter Beek写道:
Hi Arthur,

There is always another ICLP, or some other LP event.
Ok, I'll keep eyes on the relative events. 

AFAIK the only thing that comes close to the features your mode
current provides is PDT, which is built on top of Eclipse:
https://github.com/pdt-git/public

Some of the features are also present in SWISH and the built-in PCE
Emacs editor.

I haven't done researches on other approaches' mechanisms. What I did 
is to utilize the functionalities provided by swipl itself as more as possible 
and then implemented the protocols and conventions of VS Code extension.
I think that I've fulfiled my intention, satisfied with the result. I'll spend time to
improve and extend new functions if it's accepted by the community.

Many thanks for your supports.

Arthur Wang

Jan Burse

unread,
Aug 15, 2017, 8:17:26 AM8/15/17
to SWI-Prolog
What would interest me, would be some refactoring
capable IDE. Means you cannot only jump to a definition
of a predicate,

you can also:
- find all uses of a predicate
- rename a predicate name
    - and it will automatically rename the definition
    - and it will also automatically rename the many uses

For example if you have clauses in Prolog text:

app([X|Y],Z,[X|T]) :- app(Y,Z,T).
app([], X, X).

And then you say refactor app->append, it would
replace the above by:

append([X|Y],Z,[X|T]) :- append(Y,Z,T).
append([], X, X).

But why would we need refactoring, and not simply
substitute the text "app" by "append"? Well there are
the following reasons:

- Simple: Syntactic reasons, we might have word
   boundaris, or string litterals etc.. so not every
   "app" is the predicate name "app". Etc...
- Harder: It could be that there is an app functor
   used with arity 3, and another app functor used with
   arity 4, but we want only replace app/3. Etc...

All the big IDEs, Eclipse, NetBeans and IntelliJ, can
do such refactoring, and thats the only reason I buy
a license for these tools (IntelliJ).

I have a prototype of a refactoring IDE for Prolog,
as a web application and via an SQL backend. But
it is too slow and it can't do OO Prolog.

OO Prolog is difficult in refactoring, you need some
extra (i envision something simpler than a Mercury Prolog
type system). I am still researching in this matter, and

the above SQL backend is a throw away prototype.
Can this new thingy VS Code do refactoring(*)? An
IDE without refactoring is kind of a stupid thing...

Bye

(*)
http://wiki.netbeans.org/Refactoring

Jan Burse

unread,
Aug 15, 2017, 8:20:44 AM8/15/17
to SWI-Prolog
Vicious idea just now. Refactoring is just a "Code
formatter", which would also replace some things,
instead only format things. He He.

Jan Burse

unread,
Aug 15, 2017, 8:25:30 AM8/15/17
to SWI-Prolog
An intermediate challenge is refactoring for a Prolog syntax/
semantic, that has a module system. I think this is more feasible,
if all the meta-predicate declarations are in place, a lot can be done.


Am Dienstag, 15. August 2017 14:17:26 UTC+2 schrieb Jan Burse:
> OO Prolog is difficult in refactoring, you need some
> extra (i envision something simpler than a Mercury Prolog
> type system). I am still researching in this matter, and

Wouter Beek

unread,
Aug 15, 2017, 8:50:56 AM8/15/17
to Jan Burse, SWI-Prolog
Hi Jan,

There is a repository that supplies Prolog refactoring:
https://github.com/edisonm/refactor

I have never used it myself.

---
Cheers,
Wouter.

Email: wou...@triply.cc
WWW: http://triply.cc
Tel: +31647674624

On Tue, Aug 15, 2017 at 2:25 PM, Jan Burse <burs...@gmail.com> wrote:
> An intermediate challenge is refactoring for a Prolog syntax/
> semantic, that has a module system. I think this is more feasible,
> if all the meta-predicate declarations are in place, a lot can be done.
>
> Am Dienstag, 15. August 2017 14:17:26 UTC+2 schrieb Jan Burse:
>> OO Prolog is difficult in refactoring, you need some
>> extra (i envision something simpler than a Mercury Prolog
>> type system). I am still researching in this matter, and
>
> Am Dienstag, 15. August 2017 14:20:44 UTC+2 schrieb Jan Burse:
>>

Jan Burse

unread,
Aug 15, 2017, 8:56:43 AM8/15/17
to SWI-Prolog
Hi,

Ok, interesting. I guess the challenge is a seamless integration
with an IDE. IntelliJ made a good job here, and their product
is even getting a little bit more intelligent, robust and faster

from release to release. Eclipse does also have refactoring,
but some don't like it. Lost a little bit track of Eclipse, and also
of their social variant https://jazz.net/

Anyway, step by step.

Bye

Jan Wielemaker

unread,
Aug 15, 2017, 9:05:20 AM8/15/17
to Jan Burse, SWI-Prolog
Have a look at http://www.swi-prolog.org/pack/list?p=refactor. I'm
afraid it isn't ready for the big audience, but it does have some
strong points in the sense that you can write down Prolog rules to
guide your refactoring. There is an ICLP TC paper about it.

Also library(prolog_codewalk) can do some interesting work finding
dependencies in large code bases. It basically enumerates all
call-graph edges for the loaded program and can tell you about the
source location of each edge up to the character positions.
Unfortunately the last step doesn't always work due to source
transformations.

Cheers --- Jan


On 15/08/17 14:25, Jan Burse wrote:
> An intermediate challenge is refactoring for a Prolog syntax/
> semantic, that has a module system. I think this is more feasible,
> if all the meta-predicate declarations are in place, a lot can be done.
>
> Am Dienstag, 15. August 2017 14:17:26 UTC+2 schrieb Jan Burse:
>> OO Prolog is difficult in refactoring, you need some
>> extra (i envision something simpler than a Mercury Prolog
>> type system). I am still researching in this matter, and
>
> Am Dienstag, 15. August 2017 14:20:44 UTC+2 schrieb Jan Burse:
>
> Vicious idea just now. Refactoring is just a "Code
> <https://github.com/arthwang/vsc-prolog#code-formatter>
> formatter",
> <https://github.com/arthwang/vsc-prolog#code-formatter>which would
> also replace some things,
> instead only format things. He He.
>
> Am Dienstag, 15. August 2017 14:17:26 UTC+2 schrieb Jan Burse:
>
> the above SQL backend is a throw away prototype.
> Can this new thingy VS Code do refactoring(*)? An
> IDE without refactoring is kind of a stupid thing...
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.

Arthur Wang

unread,
Aug 15, 2017, 9:11:22 AM8/15/17
to swi-p...@googlegroups.com
Hi Wouter and Jan,
Thank you for your proposals and information.  VS Code does
support an interface to 'find all references to a symbol' that maybe 
act as the base for refactoring. Let me study the utility you mentioned
to see if it's possible to merge in as backend. Ok?

Arthur Wang

在 2017年8月15日星期二 UTC+8下午8:56:43,Jan Burse写道:

Jan Burse

unread,
Aug 15, 2017, 10:40:05 AM8/15/17
to SWI-Prolog
Hi,

One problem I see, one shouldnt do flying trapeze,
without a safety net. The IDE I know has two levels of
safety net, its just the VCS (version control system(s)):

- Local VCS: The IDE I know has a local VCS, its a
    noname, its done by the IDE itself, and its done
    persistently on the harddisk, I can do local rollback

   of changes. For some sync points I can even exit and
   enter the IDE again, and doit later via the local history.
   Extremly neat, and eats some harddisk space.

- Remote VCS: The IDE I know supports a couple of
    remote VCS additionally to the local VCS, so I can
    hook into Git, SVN, etc..

So in the rare or not so rare cases i am not happy with
a refactoring, I either press Ctrl-Z (Undo), it does the local
rollback, or in the worst case, I get my files back from
the remote VCS.

The local Undo is quite powerful. I have seen the IDE
doing a rollback of 1000 files, that were changed by
a refactoring. Mostlikely VS Code is also offering such
facility, I dunno, even if its from Microsoft

some say Microsoft will only survive the next 2 years,
and then they completely disappear, I dunno, anyway,
somehow in my opinion refactoring and good rollback
facility need to be precent at the same time,

otherwise you can make the end-user really angry...

Jan Wielemaker

unread,
Aug 15, 2017, 10:48:18 AM8/15/17
to Arthur Wang, SWI-Prolog
On 15/08/17 15:11, Arthur Wang wrote:
> Hi Wouter and Jan,
> Thank you for your proposals and information. VS Code does
> support a interface to 'find all references to a symbol' that maybe
> act as the basic for refactoring. Let me study Wouter's utility to see
> if it's possible to merge in as backend. Ok?

I composed a little gist that finds references from the Prolog database.
See https://gist.github.com/JanWielemaker/dd8c8e378bcfc00ba48022a9fbcef07f

This is more for interactive use. It has all the ingredients for making
a more machine friendly version.

Enjoy --- Jan
> <https://groups.google.com/group/swi-prolog>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.

Jan Burse

unread,
Aug 15, 2017, 10:55:34 AM8/15/17
to SWI-Prolog
One last remark (spinning ideas, sorry). Such an IDE could be
also used to edit RDF. The https://arxiv.org/abs/1608.00989 paper
constains a mention of some RDF consult tests. I grabed one of the

RDF files (the danish protocols), via cliopatra, but I guess I did the
wrong export. I did an XML and not a turtle export. So I got a 380 MB file,
and the IDE I know even refused to open it. Does the paper test

XML or Turtle format? Anyway, for such cases of refactoring, the
Web and SQL prototype is more useful. But its also a throw away
prototype, it didn't have rollback I just notice. Does Cliopatra have

refactoring AND rollback somewhere? A little complicated to
design if its over the Web and if collaborative editing is also present.
I would like to read papers (I guess there are) about this problem...

Arthur Wang

unread,
Aug 15, 2017, 8:52:23 PM8/15/17
to SWI-Prolog, rthr...@gmail.com


在 2017年8月15日星期二 UTC+8下午10:48:18,Jan Wielemaker写道:
On 15/08/17 15:11, Arthur Wang wrote:
> Hi Wouter and Jan,
> Thank you for your proposals and information.  VS Code does
> support a interface to 'find all references to a symbol' that maybe
> act as the basic for refactoring. Let me study Wouter's utility to see
> if it's possible to merge in as backend. Ok?

I composed a little gist that finds references from the Prolog database.
See https://gist.github.com/JanWielemaker/dd8c8e378bcfc00ba48022a9fbcef07f

Wonderful, i'll have a try at once :)
Thank you Jan!

Arthur Wang
 

Arthur Wang

unread,
Aug 15, 2017, 9:11:39 PM8/15/17
to SWI-Prolog
Hi,
"By default, VS Code has the Git source control provider enabled but you can install and switch to another SCM provider.  " ---- VS Code document
In my experinces, I can rollback to any versions if I stage changes and commit often enough.

Best regards,

Arthur Wang

在 2017年8月15日星期二 UTC+8下午10:40:05,Jan Burse写道:

Arthur Wang

unread,
Aug 15, 2017, 9:52:41 PM8/15/17
to SWI-Prolog


在 2017年8月15日星期二 UTC+8下午10:55:34,Jan Burse写道:
One last remark (spinning ideas, sorry). Such an IDE could be
also used to edit RDF. The https://arxiv.org/abs/1608.00989 paper
constains a mention of some RDF consult tests. I grabed one of the

RDF files (the danish protocols), via cliopatra, but I guess I did the
wrong export. I did an XML and not a turtle export. So I got a 380 MB file,
and the IDE I know even refused to open it. Does the paper test

There are really a lot of issue reports complaining big file handling ability in
VS Code.  I've found it responses remarkablly slow even when i edit 30k lines
text file. But IMO we use VS Code just as an programming ide, not a text
 document editor. Am i right?

With regards,

Arthur Wang

Edison Mera

unread,
Aug 16, 2017, 4:28:55 AM8/16/17
to Wouter Beek, Jan Burse, SWI-Prolog
Hi,
Yes indeed, such refactoring tool can be used to do several things, I have been improving it continuously since our ICLP TC paper, but it does not have yet a graphical interface, although it is usable. If you want to look at it, you can check the refactor/tests/refactor.plt unit test that contains examples that cover some implemented scenarios.
For instance, to rename app/3 to append/3, you can run:

replace_term_id(app(A,B,C),append(A,B,C), [file(pathtomyfile)]).
rshow.
rcommit.

rshow will show a diff with the proposed changes, and rcommit will make those changes permanent (always keep a backup or avoid to apply the changes in a repository with uncommitted changes).
You can create very sophisticated refactoring rules combining the basic term rewriter, for instance, that is how are implemented the scenarios contained in the module ref_scenarios.pl, or the predicate file_to_module/2 that basically convert an included file (:- include directive) into a module (:- use_module...), taking care of which needs to be imported into the converted file, etc...
A strong point of such tool is that it is able to work in very big repositories in a reasonable time without crashing, we are talking of about half million of lines of code, which is the size of the system I work with.
Best Regards,


> Visit this group at https://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+unsubscribe@googlegroups.com.

Edison Mera

unread,
Aug 16, 2017, 4:34:52 AM8/16/17
to Wouter Beek, Jan Burse, SWI-Prolog
I said half, million, well, actually is more than one million :)

Arthur Wang

unread,
Aug 16, 2017, 6:23:55 AM8/16/17
to SWI-Prolog, wou...@triply.cc, burs...@gmail.com
Thank you Edison,
I'll try to import your programs as the backend of VSC-Prolog refactoring. 
Hope it work well.

With best wishes.

Arthur Wang


在 2017年8月16日星期三 UTC+8下午4:28:55,Edison Mera写道:

> Visit this group at https://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.

Willem van Dijk

unread,
Apr 12, 2018, 8:55:33 PM4/12/18
to SWI-Prolog
Hi Arthur,

I was wondering if you ever had any comments from people using VSC with your extension and SWI on Linux. I installed SWI, tested it (swipl [likes]), checked the configuration of your extension with my settings, which are identical, setting the file extension in VSC to Prolog... and it doesn't work, nothing.

I'm missing a step, something, I don't know. Is there a step-by-step installation guide or a check list so I can see what I did wrong?

Thanks very much,

Willem van Dijk

Wolfram Diestel

unread,
Apr 30, 2018, 5:31:22 AM4/30/18
to SWI-Prolog
Hi Arthur,

recently I started to use VSC with your very well done Prolog extension. I like it very much.

Now I even managed to install VSC and Prolog on a Windows client without admin rights using PortableApps. Unfortunately there seems to be one issue executing the current source in the terminal window - it doesn't seem to autoload any library. I pointed the executable path to swipl.exe

Is this a limitation of SWI's PortableApp or do I need to setup the executablePath in another way?

Any idea? I would be glad to get any hint on the issue.

Thank you,
   Wolfram.


Am Montag, 14. August 2017 15:48:33 UTC+2 schrieb Arthur Wang:
...
... 

Wolfram Diestel

unread,
Apr 30, 2018, 8:04:24 AM4/30/18
to SWI-Prolog
Hello,

I solved the problem now adding the missing libraries in a my-swipl.ini file:

"prolog.terminal.runtimeArgs": ["-f","C:\\Users\\...\\SWI-PrologPortable\\App\\SWI-Prolog\\customize\\my-swipl.ini"]

Regards,
   Wolfram.
Reply all
Reply to author
Forward
0 new messages