[fpc-pascal] Pascal Language Server

Ryan Joseph genericptr at gmail.com
Thu Apr 23 15:45:58 CEST 2020



> On Apr 23, 2020, at 8:20 PM, Arjan Adriaanse <arjan at adriaan.se> wrote:
> 
> Perhaps not all the used generics features are available yet in older
> FPC versions.  I use the most recent release candidate from
> ftp://ftp.freepascal.org/pub/fpc/beta/3.2.0-rc1/ [2], but will
> investigate if older versions also work.

Lazbuild used FPC 3.0.4. How do I make lazbuild choose the trunk instead of 3.0.4?

The first thing to address is TCompletion.Process and how it interacts with code tools. For example:

    URI := ParseURI(textDocument.uri);
    Code := CodeToolBoss.FindFile(URI.Path + URI.Document);
    X := position.character;
    Y := position.line;
    Line := Code.GetLine(Y);
    GetIdentStartEndAtPosition(Line, X + 1, PStart, PEnd);
    CodeToolBoss.IdentifierList.Prefix := Copy(Line, PStart, PEnd - PStart);

How LSP is intended to work is that a text buffer which contains the current state of the file is sent to the server and then this buffer is parsed. I think what the code above does is only operate on the file on disk. This maybe be fine for certain completions but it will be static until the user saves the file in the client. Worse yet is that the text offset we receive from the client is going to be out of sync.

Here's an example request:

{
  "method" : "textDocument/didChange",
  "jsonrpc" : "2.0",
  "params" : {
    "textDocument" : {
      "uri" : "file:///Users/ryanjoseph/Desktop/FPCLS-Test/parser_test.pas",
      "version" : 1
    },
    "contentChanges" : [
      {
        "text" : "..."
      }
    ]
  }
}

and a hover request which shows the problem. Line 10 is from the didChange request, not line 10 from the file on disk.

{
  "method" : "textDocument/hover",
  "jsonrpc" : "2.0",
  "id" : 3,
  "params" : {
    "textDocument" : {
      "uri" : "file:///Users/ryanjoseph/Desktop/FPCLS-Test/parser_test.pas"
    },
    "position" : {
      "line" : 10,
      "character" : 13
    }
  }
}

Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list