arthwang / vsc-prolog

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

`.` pulls clause to beginning of line #19

Open phaistos opened 6 years ago

phaistos commented 6 years ago

Typing a . often pulls the clause to the beginning of the line.

useless(X, Z) :-
    Y is X * 2 + 14,
Z is Y + 2.

and it gets confused by clpfd contraints, like in (both pulls the body clause back and doesn't highlight the .. properly):

useless(X, Z) :-
X in 1..10

In other cases it works fine:

useless(X, Z) :-
    Y is X * 2 + 14,
    Z is sqrt(Y).

Can i just turn autoformatting off entirely for prolog documents while still getting linting and documentation of library functions?

(Linux Mint 19, VSC 1.26.0 and plugin 0.8.17, swipl 7.6.4)

arthwang commented 6 years ago

Yeah, you can disable formatting without affecting other functionalities. Maybe I'd improve formatting somedays. Sorry for the inconvenience.

alvitawa commented 6 years ago

@arthwang How? "prolog.format.enabled": false doesn't change this behaviour.

arthwang commented 6 years ago

I'm sorry it's a bug. Please update to see if it's ok now.

phaistos commented 6 years ago

Update fixed it for me, Arthur. Thank you for your effort.

alvitawa commented 6 years ago

@arthwang Thank you, it is much better now. Although there is still a weird thing it does when pressing enter and then a dot after typing a head (prime(N) :- **press enter here** **now press dot**). It copies the head to the body (With the formatting setting disabled). But that's not a very big issue in my opinion.

arthwang commented 6 years ago

Oh yeah, that's a design. 'dot repeat' is inspired by emacs prolog plugin. It repeats last clause head since there are many such situations. What's more, in recursive clauses, it copies the head with arguments updated smartly. try: test(N) :-N =< 0, !. ('dot' here will copy 'test(N)' in place) test(N) :- N1 is N - 1, writeln(N1), (enter '.' here, you will get 'test(N1).' )
Image that if you have more than 5 arguments, 'dot' will save you a lot of typings.