[fpc-pascal] Pascal Language Server

Ryan Joseph genericptr at gmail.com
Fri Apr 24 08:47:17 CEST 2020

> On Apr 24, 2020, at 12:46 PM, Michael Van Canneyt <michael at freepascal.org> wrote:
> I fixed TCustomJSONRPCDispatcher not to add a Null in case of V2. But V1 needs it.
> see https://www.jsonrpc.org/specification_v1
> Committed in revision 45047.

Nice, it was a bug. :)

So the Sublime Text people explained there was a special panel to get errors so I am seeing them now. Also it's important to flush the stderr pipe after writing to it or the messages will come out of order.

However, I'm still not able to get completions despite this being the one feature which is claimed to be supported. I don't know if this is because of more errors or the completions are not what I think they are. Here is the code tools related function which gets completions at the current text offset.

What does this do exactly? If there is an identifier "DoThis" in the current scope (say a function name) does this return "DoThis" if the cursor is after the word "Do"? Previously it was said "IdentifierCompletion" does this but I haven't looked into the code tools yet.

function TCompletion.Process(var Params: TCompletionParams): TCompletionList;
  Code: TCodeBuffer;
  X, Y, PStart, PEnd, Count, I: Integer;
  Line: string;
  Completions: TCompletionItems;
  Identifier: TIdentifierListItem;
  Completion: TCompletionItem;
begin with Params do
    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);

    Completions := TCompletionItems.Create;
    if CodeToolBoss.GatherIdentifiers(Code,X + 1,Y + 1) then
      Count := CodeToolBoss.IdentifierList.GetFilteredCount;
      for I := 0 to Count - 1 do
        Identifier := CodeToolBoss.IdentifierList.FilteredItems[I];
        Completion := TCompletionItem(Completions.Add);
        Completion.insertText := Identifier.Identifier;
        Completion.insertTextFormat := TInsertTextFormat.PlainText;
    end else begin
      if CodeToolBoss.ErrorMessage<>'' then
        writeln(stderr, 'Parse error: ',CodeToolBoss.ErrorMessage)
        writeln(stderr, 'Error: no context');

    Result := TCompletionList.Create;
    Result.items := Completions;

	Ryan Joseph

More information about the fpc-pascal mailing list