Recent

Author Topic: OmniPascal: Visual Studio Code Pascal Extension  (Read 26299 times)

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
OmniPascal: Visual Studio Code Pascal Extension
« on: November 25, 2015, 03:11:05 pm »
In the event you haven't noticed, last week someone posted an announcement of a Free Pascal/Lazarus extension to Visual Studio Code:

http://www.omnipascal.com/

I installed it but so far I can't get the code insight working correctly.

Wosi

  • New Member
  • *
  • Posts: 21
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #1 on: November 30, 2015, 07:18:32 pm »
What are your problems? Are they already listed here? https://bitbucket.org/Wosi/omnipascalissues/issues
There are currently problems in dpr/lpr files which be fixed with the next update.
« Last Edit: November 30, 2015, 07:26:03 pm by Wosi »

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #2 on: November 30, 2015, 07:31:18 pm »
Wosi, try posting better instructions for Free Pascal users. When I installed sure I got syntax coloring, but I received no code insight. That is, when typing Memo. (ctrl + space or whatever) I received no drop down list of available properties on TMemo. To work as a proper minimalistic IDE it's going to need to do that, allow you to navigate to declarations (ctrl + click or something thereof on an identifier and bring you to the declaration), and provide compile messages error highlighting and possibly breakpoints/debug.

As it is right now, I saw none of that worked, which makes your extension + Visual Studio Code not much more than a text editor with colors. Maybe I did something wrong, but you provided no instructions for us Free Pascal users to make those things work.

Also, you may want to consider dynamic help, that is pressing F1 on identifiers and launching the appropriate help page. See this article I posted Today for an example of how that works in Lazarus.

http://www.getlazarus.org/articles/documentation/
« Last Edit: November 30, 2015, 07:33:29 pm by sysrpl »

Wosi

  • New Member
  • *
  • Posts: 21
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #3 on: December 01, 2015, 12:49:32 pm »
I'm absolute with you: The instructions on the website are currently poor. I should post a "Getting started" article on blog.omnipascal.com. I'll do it as soon as I find the time.

For the moment I'd like to provide some basic instructions here on how you get OmniPascal run with FPC:

 - Check out the source code for FPC and Lazarus into one basic folder. For simplicity I used fpcup which checks out both projects into "C:\development".
 - In Visual Studio Code go to File -> Preferences -> User Settings and add the entry
  "objectpascal.delphiInstallationPath": "C:\\development"
 - Close VSCode and open the root folder of a project in VSCode (via right click or via command line: "code C:\ProjectFolder")
 - Now you should get code completions for TMemo etc.

Limitations:
 - OmniPascal runs currently on Windows only. Mac and Linux support will come in 2016.
 - The parser library (DelphiAST) can't work with FPC related language features like the constref keyword. Units using these FPC related things don't get parsed properly.

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #4 on: December 02, 2015, 09:55:07 am »
Here is a fix for DelphiAST to handle constref properly:

function TmwBasePasLex.Func100: TptTokenKind;
begin
  Result := ptIdentifier;
  if KeyComp('Automated') then FExID := ptAutomated else
    if KeyComp('Smallint') then FExID := ptSmallint else
      if KeyComp('Constref') then FExID := ptConst;
end;

In unit unit SimpleParser.Lexer.pas starting at Line 1074 ending at Line 1080.

The logic: constref is essentially exchangeable with const with regards to parameters. The difference being constref advises to compiler to always use the address rather than a value (a possible copy) and then an address. So for all language purposes generally they are same (ignoring the minor possible side effects which should only be execution speed given well mannered code). As such, constref as related to a simple code insight tool can be considered the same as const.

Wosi

  • New Member
  • *
  • Posts: 21
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #5 on: December 02, 2015, 11:49:52 am »
Thanks a lot for providing the code!
Unfortunately the problem is much bigger than the constref keyword itself.
I have already implemented it for DelphiAST in the way you did. See this pull request.
When I opened the pull request I already knew it would be a nasty way to include the constref keyword that way, so we started a discussion. Now I'm happy with the project owner's decision not to merge it.
When a Delphi user creates something like this:

Code: Pascal  [Select][+][-]
  1. procedure AddReference(ConstRef: Pointer)

DelphiAST would throw an error on valid Delphi code. The project itself has no support for switching dialects on runtime. Before applying FPC related keywords we have to change DelphiAST to become more flexible.

Btw. the constref keyword is not the only thing DelphiAST has problems when parsing Free Pascal code. That's why even my own fork has currently no support for constref. 
Before refactoring DelphiAST on my own I want to focus on making OmniPascal more stable for Delphi users. As long as FPC users work with {$MODE Delphi} they can already use OmniPascal beside some restrictions regarding basic libraries.

Don't get me wrong: I really want to support FPC in the future!

P.S: Did you get OmniPascal run with the instructions from my last post?

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #6 on: December 02, 2015, 02:40:33 pm »
Omni, to be honest I've been busy with Thanksgiving and now preparing a special Raspberry Pi edition of Free Pascal and Lazarus. I'll probably get back to your project sometime after you add in better Linux/FPC support (next year). Keep up the good work.

Oh and regarding the patch problem, you can probably still use it, just include an option to specify which compiler:

Code: Pascal  [Select][+][-]
  1. type
  2.   TLexerCompiler = (compDelphi, compFreePascal);
  3.  
  4. property Compiler: TLexerCompiler read FCompiler write FCompiler default compDelphi;
  5.  
  6. function TmwBasePasLex.Func100: TptTokenKind;
  7. begin
  8.   Result := ptIdentifier;
  9.   if KeyComp('Automated') then FExID := ptAutomated else
  10.     if KeyComp('Smallint') then FExID := ptSmallint else
  11.       if (Compiler = compFreePascal) and KeyComp('Constref') then FExID := ptConst;
  12. end;
  13.  

In this way something like:

Code: Pascal  [Select][+][-]
  1. procedure AddReference(ConstRef: Pointer)

Will not be an issue.

Wosi

  • New Member
  • *
  • Posts: 21
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #7 on: December 02, 2015, 03:28:30 pm »
As I've mentioned before the constref keyword isn't the only change that needs to be made. It's much more work than using this one liner to have FPC support. Handling constref as const is simply wrong. It would definitely generate bugs later e.g. when you want to create a warning when definition and implementation don't fit together.
Using if statements all around the code in order to handle different dialects (e.g. Turbo Pascal, Delphi1, DelphiXE, FreePascalV3 etc.) would lead to a monster that nobody can maintain. There are some architectural changes to be made in order to prevent creating monsters. I'd love to provide full FPC support soon but I don't see it now.

Quote
now preparing a special Raspberry Pi edition of Free Pascal and Lazarus
Great news!

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #8 on: December 02, 2015, 04:15:41 pm »
Code: Pascal  [Select][+][-]
  1. procedure blaat2 (constref constref : integer);
  2. begin
  3.   writeln(constref);
  4. end;
  5.  
  6.  
  7. var a : integer;
  8. begin
  9.   a:=42;
  10.   blaat2(a);
  11. end.

compiles and works fine :-)

Wosi

  • New Member
  • *
  • Posts: 21
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #9 on: July 07, 2017, 06:13:08 pm »
OmniPascal is now available for Linux, Mac and Windows. It's the first release that does not work exclusively on Windows.
See the release here: http://blog.omnipascal.com/omnipascal-0-14-0-mac-and-linux-support/

Benjiro

  • Guest
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #10 on: July 07, 2017, 08:31:46 pm »
OmniPascal is now available for Linux, Mac and Windows. It's the first release that does not work exclusively on Windows.
See the release here: http://blog.omnipascal.com/omnipascal-0-14-0-mac-and-linux-support/

Installed it yesterday on Windows VSC and it works great. Just updated to 0.14. Nice job ...

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #11 on: July 07, 2017, 09:35:38 pm »
OmniPascal is now available for Linux, Mac and Windows. It's the first release that does not work exclusively on Windows.
See the release here: http://blog.omnipascal.com/omnipascal-0-14-0-mac-and-linux-support/
Thank you for giving me a reason to use VSCode (I'm a Linux user, knowing OmniPascal wasn't available for Linux was a showstopped for me). It was kinda sluggish the last time I use it, mainly because I was still using HDD. Now I use SSD, it feels a lot faster even without ten thousands of files. Automatic task generator is indeed useful, especially since it can be generated from a .lpi, the only problem is if it contains IDE macros because they don't get expanded. Looking for more features in the future, keep up the good work.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #12 on: July 07, 2017, 10:00:34 pm »
Code: Pascal  [Select][+][-]
  1. procedure blaat2 (constref constref : integer);
Good to see my original version of Blaat (~1996) seems to be maintained and even got a version update? :o :-X :-\ %) O:-) 8-) True to its original intention it is still.....
Nice job!

Note that is a bug: constref is a keyword, just like (var var).
Code: Pascal  [Select][+][-]
  1. program test;
  2. {$MODE OBJFPC}
  3. procedure blaat3(constref constref);
  4. begin
  5. end;
  6. begin
  7. end.

Should never compile, but it does.....Reported as 32123, what a beautiful number  8-) Original Blaat knew nothing bout constref of course...
Re-phrased and re-reported as 32124 because Jonas closed it. It is a bug.
« Last Edit: July 07, 2017, 10:58:17 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Wosi

  • New Member
  • *
  • Posts: 21
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #13 on: August 28, 2017, 10:19:28 am »
OmniPascal 0.15.0 released. The most important change for Free Pascal developers will probably be the more tolerant parser for language constructs in mode ObjFPC. In previous versions the parser stopped on the first occurence of the word "generic", "specialization" or "constref".
This leads to much better code completion in FPC projects.

See the change log for more information:
http://blog.omnipascal.com/omnipascal-0-15-0-overloaded-and-generic-methods/

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: OmniPascal: Visual Studio Code Pascal Extension
« Reply #14 on: August 28, 2017, 10:55:38 am »
first test OK. Very welcome!
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018