Adding XData.Web.Dataset to a project breaks LSP/CodeInsight

After adding XData.Web.Dataset to the uses clause of a clean, new WebCore project makes CodeInsight / CodeCompletion kaputt.

Steps:

  • Create a new WebCore project

  • Add a TWebLabel and TWebButton to its form

  • Type this code:

procedure TForm196.WebButton1Click(Sender: TObject);
begin
  WebLabel1.Caption := 'Hello World';
  WebLabel1.Font.Size := 20;
end;

You get full Code Completion as expected.

  • add XData.Web.Dataset to that form's uses clause

--> Code Completion immediately stops working.

  • remove that uses again -> code completion works again

This is Delphi 11.3 / WebCore 2.2.3.0 (I've noticed that with a few earlier versions already, not new that is)

Note: I am using an XData server with my current project and thus use all these TXDataWeb components and wondered why Code Completion is gone. So started digging, which component or unit would be responsible and was able to nail it down to that single unit. Other units may be affected, but I did not dig any further for now

Hi Olaf,

I tried here, but couldn't reproduce the issue. Here is the full source code of the unit I used:

unit Unit3;

interface

uses
  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls,
  XData.Web.Dataset;

type
  TForm3 = class(TWebForm)
    WebButton1: TWebButton;
    WebLabel1: TWebLabel;
    procedure WebButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.WebButton1Click(Sender: TObject);
begin
  WebLabel1.Caption := 'Hello World';
  WebLabel1.Font.Size := 20;
end;

end.

And here is a try to use the code completion:

Also, have you tried maybe reposition XData.Web.Dataset in the uses list, maybe moving it more to the beginning, so other units get precedence over it?

Hi Wagner, thanks for looking into this.

I an attempt to understand what's going on, I reduced the test case to a minimalistic one, which still shows the issue:

program CodeInsightBreaker;

{$APPTYPE CONSOLE}

{$R *.res}


uses
  browserconsole,
  XData.Web.Dataset;

type
  TFoo = class(TObject)
  private
    FName: string;
  public
    property Name: string read FName write FName;
  end;

var
  LFoo: TFoo;

begin
  Writeln('Hello World!');
  LFoo := TFoo.Create;
  LFoo.Name := 'Bar';
  LFoo.Free;
end.

I noticed, that XData.Web.Dataset is not taken from the WebCore installation (as I though first), but from the XData installation I have on that machine as well. My XData version is 5.6 and not 5.12 which would be current. Can this be the source of the issue?

I will run the XData update today...

@Olaf_Monien, please check:

I suppose my test is right? Just created a TMS Web Console application, pasted your code, and tried some random code completion.

In this case, yes, please try to use latest version to see if the problem still happens.

I'll do the XData update later today and report back.

This is how it looks here

XData.Web.Dataset is in the uses - only live templates show up. Nothing else.

This is without XData.Web.Dataset is in the uses - all works as expected.

Hi Wagner,
I updated XData to 5.12, but no change regarding my issue.

I tracked this down to the actual unit now. I went through all the uses in XData.Web.Dataset.pas and found the actual culprit: Bcl.Json.Attributes.pas

Once that one is in the uses, CodeInsight breaks. It uses Bcl.Json.Converters.pas internally, which appears to be actual source of the problem:

unit Bcl.Json.Attributes;

{$I Bcl.inc}

interface

uses
  Generics.Collections,
  {$IFNDEF PAS2JS}
  Bcl.JSON.Converters,
  {$ENDIF}
  Classes;

It's ifdef'ed as {$IFNDEF PAS2JS} on purpose I guess, because I can not even compile Bcl.JSON.Converters separately (see code below). See the screenshot, which reports an LSP Server Error, when you hover the curser over Bcl.JSON.Converters - which is probably the reason, why Codeinsight breaks for the whole project.

If define PAS2JS manually on project level, everything works fine - even with my "real" project.

program Project213;

{$APPTYPE CONSOLE}

{$R *.res}


uses
  browserconsole
    , Bcl.Json.Attributes // <-- compiles fine, but breaks CodeInsight
//   , Bcl.Json.Converters // <-- can't find unit "Bcl.JSON.Converters"
    ;

begin
  Writeln('Hello World!');
end.

I believe your Delphi library path (not TMS Web Core library path) is then incomplete, i.e., it doesn't include the directory where Bcl.Json.Attributes unit is located? Which is <xdata>\source\core ( should be TMS XData installation folder)?

In the meantime, I updated XData (including Biz Core of course) and WebCore to their very recent versions.

The breaking CodeInsight is no longer reproducible with the minimalistic demo, so something must have changed.

Apparently, within WebCore, Bcl.JSON.Converters is not supposed to be used/compiled. That PAS2JS define is not set on project level, so the LSP won't see it - thus needs to compile it, which failed before my updates, and thus probably made LSP break, while the Pas2Js compiled everything just fine.

I have one single form/unit in my WebCore project where CodeCompletion is still broken though. Only in that one single unit. All others work. No error message, no nothing. I'll investigate and come back :-)

unit Bcl.Json.Attributes;

{$I Bcl.inc}

interface

uses
  Generics.Collections,
  {$IFNDEF PAS2JS}
  Bcl.JSON.Converters, //only the LSP will "compile" that
  {$ENDIF}
  Classes;

Olaf, as I said, maybe your library path is wrong?
Installing XData from the installer should not cause that problem, so maybe when you reinstalled, the installer properly updated the library path and now it works.

Yes, Web Core (Pas2JS) should not compile Bcl.Json.Converters, but "Delphi" should. By "Delphi" in quotes I mean the IDE, and that's where code completion comes from. So, for code completion to work in Web Core, the application must be compilable also by DCC32. That's why you should have a correct Win32 library path, so it can find Bcl.Json.Converters. It looks like it was not the case before.

1 Like

Yes, something must have been broken - I double-checked all paths etc., before doing the upgrade, but I couldn't find anything. It works now - thanks for your patience. Getting your head around that compiler-duality and the PAS2JS define takes a moment :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.