Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Michael Van Canneyt



On Thu, 23 Apr 2020, Ryan Joseph via fpc-pascal wrote:


yes! Pascal *badly* needs this to be productive outside of Lazarus. I use 
Sublime Text and frequently now VSCode but not having good code tools is 
getting painful.


VSCode has omnipascal ?
(The TMS Web core VS Code studio plugin uses this, and it seems pretty complete)



In fact I already started a language server some months ago (and since been 
busy with out stuff) but I think you've made more progress than me so I'll help 
to develop yours if you would like. I was even asking on the list about Lazarus 
code tools and was showed how to FPC's official parser works.

Please let me know what else needs to be done and I'll see if I can contribute.


Very nice !

I suppose this can be used as a back-end for Atom and VS Code as well then ? 
That would be really cool !


A good excuse to dive into Atom package development using pas2js :-)

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 23, 2020, at 2:08 PM, Michael Van Canneyt  
> wrote:
> 
> VSCode has omnipascal ?
> (The TMS Web core VS Code studio plugin uses this, and it seems pretty 
> complete)

yes it does but they don't support ObjFPC mode syntax very well which means 
things like the "generic" keyword and "is nested" to name a couple, break the 
parser and render the entire document invalid.

It's also closed source and likely to be for profit eventually which is a deal 
break imo. A language server for FPC is too important to be allowed to be 
within a single companies control.

> 
>> 
>> In fact I already started a language server some months ago (and since been 
>> busy with out stuff) but I think you've made more progress than me so I'll 
>> help to develop yours if you would like. I was even asking on the list about 
>> Lazarus code tools and was showed how to FPC's official parser works.
>> 
>> Please let me know what else needs to be done and I'll see if I can 
>> contribute.
> 
> Very nice !
> 
> I suppose this can be used as a back-end for Atom and VS Code as well then ? 
> That would be really cool !

yes exactly. See the docs 
https://microsoft.github.io/language-server-protocol/specifications/specification-3-14.
 I think currently he supports just code completion but there's a whole lot 
more.

LSP is a good idea and thankfully backed by a large company but it's painfully 
slow because the client needs to send the entire document in plain text to the 
server which then needs to be parse the entire thing, and this happens every 
time the document changes at all. That means with every keystroke the document 
is parsed and analyzed. The FPC parser doesn't support this anyways but the 
protocol doesn't even support sending partial changed text offsets. I talked in 
length with the LSP people at Sublime Text and this is just how it's going to 
be for now. 

LSP is very new however so expect it to improve in the future.

> 
> A good excuse to dive into Atom package development using pas2js :-)
> 

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal
Arjan, I briefly skimmed over your code and it looks like instead of using the 
"DocParser" unit that I was using the parse the files, you're directly using 
the Lazarus "CodeToolBoss" which I don't have any experience with.

I think it was Michael actually who instructed me to use this parser but I also 
think he said the Lazarus code tools use this under the hood.

What are the implications of using the code tools as opposed to implementing 
the parser directly? If you have documents you could direct me to about the 
code tool units that would be helpful. I have an ok understand of LSP now and I 
want to make sure the code tools is able to supply everything we need.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Michael Van Canneyt



On Thu, 23 Apr 2020, Ryan Joseph via fpc-pascal wrote:


Arjan, I briefly skimmed over your code and it looks like instead of using the 
"DocParser" unit that I was using the parse the files, you're directly using the Lazarus 
"CodeToolBoss" which I don't have any experience with.

I think it was Michael actually who instructed me to use this parser but I also 
think he said the Lazarus code tools use this under the hood.


I don't think I did the latter part, since the codetoolboss is not using the
fcl-passrc.

There are several parsers:

* docparser - not linked to FPC/Lazarus.
  (I can't comment on the completeness, but I would suppose it's very complete)

* fcl-passrc - used in pas2js so very complete.

* I suppose the JCF has its own parser.

* lazarus codetoolboss - used in Lazarus IDE.


Probably the lazarus codetoolboss is best suited for the job since it is
designed to work with incomplete sources. The others are all designed to work
with completed and known-to-be-correct sources. 
e.g. fcl-passrc normally stops on the first error.




What are the implications of using the code tools as opposed to
implementing the parser directly?  If you have documents you could direct
me to about the code tool units that would be helpful.  I have an ok
understand of LSP now and I want to make sure the code tools is able to
supply everything we need.


I think the decision to use the codetoolboss is the best, see above as to why.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Michael Van Canneyt



On Thu, 23 Apr 2020, Ryan Joseph via fpc-pascal wrote:





On Apr 23, 2020, at 2:08 PM, Michael Van Canneyt  wrote:

VSCode has omnipascal ?
(The TMS Web core VS Code studio plugin uses this, and it seems pretty complete)


yes it does but they don't support ObjFPC mode syntax very well which means things like the 
"generic" keyword and "is nested" to name a couple, break the parser and render 
the entire document invalid.

It's also closed source and likely to be for profit eventually which is a deal 
break imo. A language server for FPC is too important to be allowed to be 
within a single companies control.


I also noticed this !

This is exactly why I prefer not to use it, and why I applaud this native 
implementation :-)

As for the missing ability to send partial updates:
that's up to the "big company" to fix.

Come to think of it, I suppose this is one more reason why 'modern' web 
development
consists out of 1000-s of small files with essentially 1 function... 
To keep LSP happy :)


Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 23, 2020, at 3:00 PM, Michael Van Canneyt  
> wrote:
> 
> I think the decision to use the codetoolboss is the best, see above as to why.

Very well. I assume the code tools parses the entire project and keeps the 
symbols in a database? That was something I was going to have to implement 
myself so it's good to not have to now.

I'm using the parser with "TPasElement" so I think that's fcl-passrc. It's a 
shame to have so many competing parsers but yours looked really solid to me.

Here the basics which code tools needs needs to provide:

1) Basic identifier completions like function, class, types names etc... these 
should be scope sensitive based on the document offset we receive from LSP.

2) Function parameter completions.

3) Class/record member completions.

4) Identifier references, i.e return all locations "DoThis" was called in the 
current workspace. (Workspace is the LSP term for the project). Code tools thus 
needs to parse all files in the workspace upon initialization.

5) Go to definition/declaration in workspace.

I would like to implement "code lens" which shows the context of a symbol in a 
popup window but I think only VScode supports this feature and it's no common 
so code tools may not be able to retrieve.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Michael Van Canneyt



On Thu, 23 Apr 2020, Ryan Joseph via fpc-pascal wrote:





On Apr 23, 2020, at 3:00 PM, Michael Van Canneyt  wrote:

I think the decision to use the codetoolboss is the best, see above as to why.


Very well. I assume the code tools parses the entire project and keeps the 
symbols in a database? That was something I was going to have to implement 
myself so it's good to not have to now.

I'm using the parser with "TPasElement" so I think that's fcl-passrc. It's a 
shame to have so many competing parsers but yours looked really solid to me.


Well, it is solid, but its target is to compile.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Mattias Gaertner via fpc-pascal

> Ryan Joseph via fpc-pascal  hat am 23. April 
> 2020 um 10:14 geschrieben:
> 
> 
> > On Apr 23, 2020, at 3:00 PM, Michael Van Canneyt  
> > wrote:
> > 
> > I think the decision to use the codetoolboss is the best, see above as to 
> > why.
> 
> Very well. I assume the code tools parses the entire project and keeps the 
> symbols in a database? That was something I was going to have to implement 
> myself so it's good to not have to now.
> 
> I'm using the parser with "TPasElement" so I think that's fcl-passrc. It's a 
> shame to have so many competing parsers but yours looked really solid to me.

These parsers are optimized for different purposes.
fcl-passrc is for parsing like a compiler. It parses everything everytime and 
has neither functions to alter code nor code completion.
codetools is for parsing only needed unit interfaces/implementations and when a 
file changes, parse only things that have changed. And it provides many code 
completions. 


> Here the basics which code tools needs needs to provide:
> 
> 1) Basic identifier completions like function, class, types names etc... 
> these should be scope sensitive based on the document offset we receive from 
> LSP.

IdentifierCompletion


> 2) Function parameter completions.

FindCodeContext
see lazarus/ide/codecontextform.pas for an example.


> 3) Class/record member completions.

I guess you mean identifier completion after a dot.
 
> 4) Identifier references, i.e return all locations "DoThis" was called in the 
> current workspace. (Workspace is the LSP term for the project). Code tools 
> thus needs to parse all files in the workspace upon initialization.

FindReferences

 
> 5) Go to definition/declaration in workspace.

FindDeclaration
 
> I would like to implement "code lens" which shows the context of a symbol in 
> a popup window but I think only VScode supports this feature and it's no 
> common so code tools may not be able to retrieve.

What do you mean with "context"? Codetools can give you all kind of context.

Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 23, 2020, at 3:49 PM, Mattias Gaertner via fpc-pascal 
>  wrote:
> 
>> 
>> 3) Class/record member completions.
> 
> I guess you mean identifier completion after a dot.

Exactly. Fields or methods and helpers even if possible. I assume that exists.

Btw, the names you're giving like "FindDeclaration" where can I find these? 
Maybe there's a wiki or unit header I can look at.

> 
>> I would like to implement "code lens" which shows the context of a symbol in 
>> a popup window but I think only VScode supports this feature and it's no 
>> common so code tools may not be able to retrieve.
> 
> What do you mean with "context"? Codetools can give you all kind of context.

For example VScode lets you hover over a symbol name like TObject and a window 
will popup that shows the declaration in code, like a mini-editor that goes to 
the line where the declaration starts in that file. It's basically the same as 
opening a new tab/window but it's more for really quick references. I'm not 
sure how it's implemented in LSP but maybe you could return the line number and 
file name and the client does the rest.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Mattias Gaertner via fpc-pascal

> Ryan Joseph via fpc-pascal  hat am 23. April 
> 2020 um 10:58 geschrieben:
> 
> 
> > On Apr 23, 2020, at 3:49 PM, Mattias Gaertner via fpc-pascal 
> >  wrote:
> > > 3) Class/record member completions.
> > I guess you mean identifier completion after a dot.
> 
> Exactly. Fields or methods and helpers even if possible. I assume that exists.
> 
> Btw, the names you're giving like "FindDeclaration" where can I find these? 
> Maybe there's a wiki or unit header I can look at.

https://wiki.freepascal.org/Codetools
And then look at the examples in lazarus/components/codetools/examples.


> > > I would like to implement "code lens" which shows the context of a symbol 
> > > in a popup window but I think only VScode supports this feature and it's 
> > > no common so code tools may not be able to retrieve.
> > What do you mean with "context"? Codetools can give you all kind of context.
> 
> For example VScode lets you hover over a symbol name like TObject and a 
> window will popup that shows the declaration in code, like a mini-editor that 
> goes to the line where the declaration starts in that file. It's basically 
> the same as opening a new tab/window but it's more for really quick 
> references. I'm not sure how it's implemented in LSP but maybe you could 
> return the line number and file name and the client does the rest.

FindDeclaration gives you the line and column. You can also get the source span 
of the declaration.
And there is FindSmartHint, which returns a brief text for a declaration 
including some context like type/var/const, private/public, parent class, etc.

Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Michael Van Canneyt



On Thu, 23 Apr 2020, Mattias Gaertner via fpc-pascal wrote:




Ryan Joseph via fpc-pascal  hat am 23. April 
2020 um 10:58 geschrieben:


> On Apr 23, 2020, at 3:49 PM, Mattias Gaertner via fpc-pascal 
 wrote:
> > 3) Class/record member completions.
> I guess you mean identifier completion after a dot.

Exactly. Fields or methods and helpers even if possible. I assume that exists.

Btw, the names you're giving like "FindDeclaration" where can I find these? 
Maybe there's a wiki or unit header I can look at.


https://wiki.freepascal.org/Codetools
And then look at the examples in lazarus/components/codetools/examples.



> > I would like to implement "code lens" which shows the context of a symbol 
in a popup window but I think only VScode supports this feature and it's no common so code 
tools may not be able to retrieve.
> What do you mean with "context"? Codetools can give you all kind of context.

For example VScode lets you hover over a symbol name like TObject and a window 
will popup that shows the declaration in code, like a mini-editor that goes to 
the line where the declaration starts in that file. It's basically the same as 
opening a new tab/window but it's more for really quick references. I'm not 
sure how it's implemented in LSP but maybe you could return the line number and 
file name and the client does the rest.


FindDeclaration gives you the line and column. You can also get the source span 
of the declaration.
And there is FindSmartHint, which returns a brief text for a declaration 
including some context like type/var/const, private/public, parent class, etc.


Seems like exactly the code lens functionality :-)

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Luca Olivetti

El 23/4/20 a les 10:05, Michael Van Canneyt ha escrit:



Come to think of it, I suppose this is one more reason why 'modern' web 
development
consists out of 1000-s of small files with essentially 1 function... To 
keep LSP happy :)


Unless it's java, then every one of those 1000 files will be 2000 lines 
long just to spit out an "Hello world" :-D


SCNR (I've been assigned a project java related).

Bye
--
Luca

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Arjan Adriaanse
Glad to know this is needed and thank you for your interest.

I made some initial issues I could think of on the repository page at
https://github.com/arjanadriaanse/pascal-language-server/issues [1].
Anyone is free to pick these up or create new issues, for example
feature requests.  Regardless of these issues, any pull requests are
welcome and you can also email me patches.

Apart from that, having a client for Visual Studio Code is useful for
many people, which would be a separate project.

Also, any feedback on my existing code is welcome, especially since
this is my first Pascal project.

Regards,

Arjan

[1] https://github.com/arjanadriaanse/pascal-language-server/issues

On Thu, 23 Apr 2020 13:37:47 +0700
Ryan Joseph via fpc-pascal  wrote:

> yes! Pascal *badly* needs this to be productive outside of Lazarus. I
> use Sublime Text and frequently now VSCode but not having good code
> tools is getting painful.
> 
> In fact I already started a language server some months ago (and
> since been busy with out stuff) but I think you've made more progress
> than me so I'll help to develop yours if you would like. I was even
> asking on the list about Lazarus code tools and was showed how to
> FPC's official parser works.
> 
> Please let me know what else needs to be done and I'll see if I can
> contribute.
> 
> Thanks, really.
> 
> > On Apr 23, 2020, at 7:13 AM, Arjan Adriaanse 
> > wrote:
> > 
> > I am new to Pascal programming and since I like using Emacs, I
> > wanted to try to improve its support for editing Pascal code.  I
> > decided to implement an LSP server which text editors can use as
> > back-end for providing IDE features.  The server is implemented in
> > Free Pascal and uses the CodeTools package for doing the actual
> > work.
> > 
> > The implementation is still incomplete and unstable but so far I
> > managed to get code completion working.  Apart from improving
> > stability and adding features, I am sure there are more possible
> > improvements, since this is my first Pascal project.  The project
> > can be found at
> > https://github.com/arjanadriaanse/pascal-language-server [1], any
> > help and feedback is welcome.
> > 
> > A module is provided for using the server from Emacs, but it should
> > be straightforward to add support for other LSP clients such as
> > Visual Studio Code.
> > 
> > Regards,
> > 
> > Arjan
> > 
> > [1] https://github.com/arjanadriaanse/pascal-language-server
> > ___
> > fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal  
> 
> Regards,
>   Ryan Joseph
> 
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



pgpqgXdy2HFyK.pgp
Description: OpenPGP digital signature
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Sven Barth via fpc-pascal
Arjan Adriaanse  schrieb am Do., 23. Apr. 2020, 08:33:

> I am new to Pascal programming and since I like using Emacs, I wanted
> to try to improve its support for editing Pascal code.  I decided to
> implement an LSP server which text editors can use as back-end for
> providing IDE features.  The server is implemented in Free Pascal and
> uses the CodeTools package for doing the actual work.
>
>
I had already written this in the forum, but I definitely welcome this.
Good work! Hopefully we can get it stable and complete.

What might be interesting as well for Lazarus might be LSP client support.
Not for Pascal, but this way we could make us of other language's LSPs to
provide code completion for it in Lazarus as well. :)

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Michael Van Canneyt



On Thu, 23 Apr 2020, Sven Barth via fpc-pascal wrote:


Arjan Adriaanse  schrieb am Do., 23. Apr. 2020, 08:33:


I am new to Pascal programming and since I like using Emacs, I wanted
to try to improve its support for editing Pascal code.  I decided to
implement an LSP server which text editors can use as back-end for
providing IDE features.  The server is implemented in Free Pascal and
uses the CodeTools package for doing the actual work.



I had already written this in the forum, but I definitely welcome this.
Good work! Hopefully we can get it stable and complete.

What might be interesting as well for Lazarus might be LSP client support.
Not for Pascal, but this way we could make us of other language's LSPs to
provide code completion for it in Lazarus as well. :)


Good idea. Saves Mattias some work ;-)

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 23, 2020, at 6:29 PM, Arjan Adriaanse  wrote:
> 
> Also, any feedback on my existing code is welcome, especially since
> this is my first Pascal project.

You did a nice job structuring it I think and providing a template to scale up 
from. What language(s) are you coming from and why did you decide to make a 
language server for Pascal if you're not a Pascal user? Just curious.

I wrote my list of missing protocol implementations so that is what I'll be 
focusing on initially.



I'm trying to build this now using lazbuild on macOS and get some strange 
errors including:

lsp.pas:154:12: error: Identifier not found "specialize"

How could this be? {$mode objfpc} is declared right at the top.

Another curios one is:

lsp.pas:134:33: error: Incompatible types: got "" expected ""

I'm not usually a Lazarus user but I think lazbuild should work. Here's the 
command I use:

lazbuild "./pasls.lpi" --cpu=x86_64 --widgetset=cocoa

I use the cocoa widgetset on Mac because I get errors otherwise. That shouldn't 
be related though.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Arjan Adriaanse
On Thu, 23 Apr 2020 19:37:02 +0700
Ryan Joseph via fpc-pascal  wrote:

> You did a nice job structuring it I think and providing a template to
> scale up from. What language(s) are you coming from and why did you
> decide to make a language server for Pascal if you're not a Pascal
> user? Just curious.

Thank you. I am coming from Java/.NET/Python/Haskell and was
introduced to Free Pascal when porting this Delphi game to Linux:
https://github.com/arjanadriaanse/Lemmix [1]

The project was started mainly to get more familiar with the language
and to eventually be less restricted to the use of the Lazarus IDE.

> I'm trying to build this now using lazbuild on macOS and get some
> strange errors including:
> 
> lsp.pas:154:12: error: Identifier not found "specialize"
> 
> How could this be? {$mode objfpc} is declared right at the top.
> 
> Another curios one is:
> 
> lsp.pas:134:33: error: Incompatible types: got " procedure(TObject;TObject;PPropInfo;TJSONObject;UTF8String;var
> TObject) of object;Register>" expected " procedure(TObject;TObject;PPropInfo;TJSONObject;UTF8String;var
> TObject);Register>"

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.

Regards,

Arjan

[1] https://github.com/arjanadriaanse/Lemmix
[2] ftp://ftp.freepascal.org/pub/fpc/beta/3.2.0-rc1/


pgpwOYYjKhO_Y.pgp
Description: OpenPGP digital signature
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 23, 2020, at 8:20 PM, Arjan Adriaanse  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

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Mattias Gaertner via fpc-pascal
On Thu, 23 Apr 2020 20:45:58 +0700
Ryan Joseph via fpc-pascal  wrote:

> > On Apr 23, 2020, at 8:20 PM, Arjan Adriaanse 
> > 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?

Help:
lazbuild -h

lazbuild --compiler=/usr/lib/fpc/3.3.1/ppcx64

 
> 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.

Codetools checks used files and automatically reloads them.


> 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" : "..."
>   }
> ]
>   }
> }

If LSP updates parser_test.pas, then codetools will notice.

If LSP only sends changes, then you have to apply these changes to
codetools codebuffers:
Code.Insert/Delete/Replace/Move

Modified codebuffers are not auto updated from disk, until you Revert or
Save.

 
> 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
> }
>   }
> }

Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Arjan Adriaanse
On Thu, 23 Apr 2020 20:45:58 +0700
Ryan Joseph via fpc-pascal  wrote:

> > On Apr 23, 2020, at 8:20 PM, Arjan Adriaanse 
> > 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?

Use the compiler option, for example:

lazbuild --compiler=/usr/lib/fpc/3.2.0/ppcx64 pasls.lpi

> 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.

The CodeToolBoss actually keeps a cache of files which are loaded at
the 'textDocument/didOpen' notification. When the user changes text at
the client side, even without saving, a 'textDocument/didChange'
notification is sent which is used to update the cache. The
CodeToolBoss seems to only use the file path as identifier, but the
contents of the files and changes are provided by the client.

Regards,

Arjan


pgpyHDQlDX7PD.pgp
Description: OpenPGP digital signature
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 23, 2020, at 9:11 PM, Mattias Gaertner via fpc-pascal 
>  wrote:
> 
> If LSP updates parser_test.pas, then codetools will notice.
> 
> If LSP only sends changes, then you have to apply these changes to
> codetools codebuffers:
> Code.Insert/Delete/Replace/Move
> 
> Modified codebuffers are not auto updated from disk, until you Revert or
> Save.

This is what we need to do then otherwise nothing will work. LSP for some 
insane reason doesn't even provide a changed text, just the full document every 
time. I guess we need to use Replace every time. I talked with the Sublime Text 
people and they since isn't even supported from their API so even if LSP 
supported it there will be clients that don't provide the information anyways.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Mattias Gaertner via fpc-pascal
On Thu, 23 Apr 2020 20:45:58 +0700
Ryan Joseph via fpc-pascal  wrote:

> > On Apr 23, 2020, at 8:20 PM, Arjan Adriaanse 
> > 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);

Btw, I guess you mean LoadFile, not FindFile.

Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 23, 2020, at 9:11 PM, Arjan Adriaanse  wrote:
> 
> The CodeToolBoss actually keeps a cache of files which are loaded at
> the 'textDocument/didOpen' notification. When the user changes text at
> the client side, even without saving, a 'textDocument/didChange'
> notification is sent which is used to update the cache. The
> CodeToolBoss seems to only use the file path as identifier, but the
> contents of the files and changes are provided by the client.

Excellent, I didn't see that yet.

Ugh, I rebuild using trunk 3.3.1 and now get this error:

/Users/ryanjoseph/Developer/lazarus/lcl/./include/custompage.inc:139:34: error: 
Operator is not overloaded: "Class Of TCustomTabControl" and "Boolean"

I guess we need to use 3.2 and nothing else. I didn't even know 3.2 existed so 
I need to download it.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 23, 2020, at 9:11 PM, Arjan Adriaanse  wrote:
> 
> lazbuild --compiler=/usr/lib/fpc/3.2.0/ppcx64 pasls.lpi

is there a macOS installer for 3.2? I found a link to a FTP server but I don't 
see this exists. Maybe fix that bug in trunk is the better idea. My lazarus 
sources are old also so perhaps this was fixed?

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal

I just tried update my lazarus sources using "svn up" and now I'm getting 
another strange error when using lazbuild.

/Users/ryanjoseph/Developer/lazarus/components/ideintf/ideintf.pas:11:3: fatal: 
Can't find unit LazarusPackageIntf used by IDEIntf

Do I need to do something else to get the sources updated?

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Arjan Adriaanse
Not sure about an installer for macOS, but you should be able to build
FPC 3.2.0 from the source found here
ftp://ftp.freepascal.org/pub/fpc/beta/3.2.0-rc1/source/ [1] using your
older compiler. Also note that I use the latest Lazarus release 2.0.8,
because older versions did not seem to build using this FPC version.

Regards,

Arjan

[1] ftp://ftp.freepascal.org/pub/fpc/beta/3.2.0-rc1/source/

On Thu, 23 Apr 2020 21:28:08 +0700
Ryan Joseph via fpc-pascal  wrote:

> > On Apr 23, 2020, at 9:11 PM, Arjan Adriaanse 
> > wrote:
> > 
> > lazbuild --compiler=/usr/lib/fpc/3.2.0/ppcx64 pasls.lpi  
> 
> is there a macOS installer for 3.2? I found a link to a FTP server
> but I don't see this exists. Maybe fix that bug in trunk is the
> better idea. My lazarus sources are old also so perhaps this was
> fixed?
> 
> Regards,
>   Ryan Joseph
> 
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



pgpi93WGncKtb.pgp
Description: OpenPGP digital signature
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Nico Neumann via fpc-pascal
You also need to update your Lazarus version:
https://github.com/graemeg/lazarus/commit/0bf882fb5b71fb3288ef5571998617fe8a5d3cd0

Am Do., 23. Apr. 2020 um 15:22 Uhr schrieb Ryan Joseph via fpc-pascal <
fpc-pascal@lists.freepascal.org>:

>
>
> > On Apr 23, 2020, at 9:11 PM, Arjan Adriaanse  wrote:
> >
> > The CodeToolBoss actually keeps a cache of files which are loaded at
> > the 'textDocument/didOpen' notification. When the user changes text at
> > the client side, even without saving, a 'textDocument/didChange'
> > notification is sent which is used to update the cache. The
> > CodeToolBoss seems to only use the file path as identifier, but the
> > contents of the files and changes are provided by the client.
>
> Excellent, I didn't see that yet.
>
> Ugh, I rebuild using trunk 3.3.1 and now get this error:
>
> /Users/ryanjoseph/Developer/lazarus/lcl/./include/custompage.inc:139:34:
> error: Operator is not overloaded: "Class Of TCustomTabControl" and
> "Boolean"
>
> I guess we need to use 3.2 and nothing else. I didn't even know 3.2
> existed so I need to download it.
>
> Regards,
> Ryan Joseph
>
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Mattias Gaertner via fpc-pascal
On Thu, 23 Apr 2020 21:41:34 +0700
Ryan Joseph via fpc-pascal  wrote:

> I just tried update my lazarus sources using "svn up" and now I'm
> getting another strange error when using lazbuild.
> 
> /Users/ryanjoseph/Developer/lazarus/components/ideintf/ideintf.pas:11:3:
> fatal: Can't find unit LazarusPackageIntf used by IDEIntf
> 
> Do I need to do something else to get the sources updated?

You have old ppu files.

For example:
make distclean all

Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 23, 2020, at 9:51 PM, Mattias Gaertner via fpc-pascal 
>  wrote:
> 
> You have old ppu files.
> 
> For example:
> make distclean all

ok, did this and now getting:

/Users/ryanjoseph/Developer/lazarus/components/lazdebuggergdbmi/gdbmidebugger.pp(63,16)
 Fatal: (10022) Can't find unit PropEdits used by GDBMIDebugger

svn up says "At revision 63051."

Never an easy time building lazarus for me. :)

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Mattias Gaertner via fpc-pascal
On Thu, 23 Apr 2020 21:54:58 +0700
Ryan Joseph via fpc-pascal  wrote:

> > On Apr 23, 2020, at 9:51 PM, Mattias Gaertner via fpc-pascal
> >  wrote:
> > 
> > You have old ppu files.
> > 
> > For example:
> > make distclean all  
> 
> ok, did this and now getting:
> 
> /Users/ryanjoseph/Developer/lazarus/components/lazdebuggergdbmi/gdbmidebugger.pp(63,16)
> Fatal: (10022) Can't find unit PropEdits used by GDBMIDebugger

Please post the last couple of lines, e.g. starting at the last
ppcx64 call.

 
> svn up says "At revision 63051."
> 
> Never an easy time building lazarus for me. :)

Do you have local modifications?


Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 23, 2020, at 10:07 PM, Mattias Gaertner via fpc-pascal 
>  wrote:
> 
> Please post the last couple of lines, e.g. starting at the last
> ppcx64 call.
> 

/bin/cp -f Makefile.compiled units/x86_64-darwin/nogui/IDEIntf.compiled
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C 
components/lazdebuggergdbmi LCL_PLATFORM=nogui
/bin/rm -f units/x86_64-darwin/nogui/lazdebuggergdbmi.ppu
/usr/local/bin/ppcx64 -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -dLCL -dLCLnogui 
-gw -Fu../../packager/units/x86_64-darwin -Fu../lazutils/lib/x86_64-darwin 
-Fu../buildintf/units/x86_64-darwin -Fu../../lcl/units/x86_64-darwin 
-Fu../debuggerintf/lib/x86_64-darwin -Fu../../lcl/units/x86_64-darwin/nogui 
-Fu../lazcontrols/lib/x86_64-darwin/nogui 
-Fu../ideintf/units/x86_64-darwin/nogui -Fu. 
-Fu/usr/local/lib/fpc/3.0.4/units/x86_64-darwin/rtl -FE. 
-FUunits/x86_64-darwin/nogui -dx86_64 lazdebuggergdbmi.pas
Hint: (11030) Start of reading config file /etc/fpc.cfg
Hint: (11031) End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 3.0.4 [2018/09/30] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
(1002) Target OS: Darwin for x86_64
(3104) Compiling lazdebuggergdbmi.pas
(3104) Compiling gdbmidebugger.pp
/Users/ryanjoseph/Developer/lazarus/components/lazdebuggergdbmi/gdbmidebugger.pp(63,16)
 Fatal: (10022) Can't find unit PropEdits used by GDBMIDebugger
Fatal: (1018) Compilation aborted
make[1]: *** [lazdebuggergdbmi.ppu] Error 1
make: *** [lazbuild] Error 2


> 
>> svn up says "At revision 63051."
>> 
>> Never an easy time building lazarus for me. :)
> 
> Do you have local modifications?

I did have some but I thought I got them merged in correctly. Perhaps not? I 
see the missing filling sitting right there:

/Users/ryanjoseph/Developer/lazarus/components/ideintf/propedits.pp

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Issues with svn?

2020-04-23 Thread Martin

I suddenly start receiving errors:
B:\FPC\SVN\build_fixes_3_2\fpcsrc
Error running context: An existing connection was forcibly closed by the 
remote

 host.
B:\FPC\SVN\build_fixes_3_2\fpcdocs
Unable to connect to a repository at URL
 'https://svn.freepascal.org/svn/fpcdocs/trunk'
Error running context: An existing connection was forcibly closed by the 
remote

 host.

Are there any known issues?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Issues with svn?

2020-04-23 Thread Michael Van Canneyt



On Thu, 23 Apr 2020, Martin wrote:


I suddenly start receiving errors:
B:\FPC\SVN\build_fixes_3_2\fpcsrc
Error running context: An existing connection was forcibly closed by the 
remote

 host.
B:\FPC\SVN\build_fixes_3_2\fpcdocs
Unable to connect to a repository at URL
 'https://svn.freepascal.org/svn/fpcdocs/trunk'
Error running context: An existing connection was forcibly closed by the 
remote

 host.

Are there any known issues?
___


I just tried an update. Worked fine here ?

Router issue somewhere ?

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Sven Barth via fpc-pascal

Am 23.04.2020 um 16:28 schrieb Ryan Joseph via fpc-pascal:



On Apr 23, 2020, at 9:11 PM, Arjan Adriaanse  wrote:

lazbuild --compiler=/usr/lib/fpc/3.2.0/ppcx64 pasls.lpi

is there a macOS installer for 3.2? I found a link to a FTP server but I don't 
see this exists. Maybe fix that bug in trunk is the better idea. My lazarus 
sources are old also so perhaps this was fixed?


You can find the macOS installer here. Despite it's name it also 
contains the x86_64-darwin one.


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Christo Crause via fpc-pascal
On Thu, 23 Apr 2020, 21:43 Ryan Joseph via fpc-pascal, <
fpc-pascal@lists.freepascal.org> wrote:

> ok, did this and now getting:
>
> /Users/ryanjoseph/Developer/lazarus/components/lazdebuggergdbmi/gdbmidebugger.pp(63,16)
> Fatal: (10022) Can't find unit PropEdits used by GDBMIDebugger
>
> svn up says "At revision 63051."
>
> Never an easy time building lazarus for me. :)
>
> Regards,
> Ryan Joseph
>

I usually revert to brute force troubleshooting in these instances: pass -
va to the compiler. A lot of information, but usually the problem is close
to the end so scanning the output in reverse should often reveal what is
wrong.

>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Debug-Adapter-Protocol support for fpDebug

2020-04-23 Thread Joost van der Sluis

Hi all,

I didn't want to share this yet, but it is related to the Pascal 
Language Server so maybe some of you might be interested.


I'm working on the support of the debug-adapter-protocol for fpDebug. 
It's quite easy to implement, as there already is a json-based tcp/ip 
interface. (https://microsoft.github.io/debug-adapter-protocol)


I want to use it to debug fpc-applications with Visual Studio Code.

It's a little bit difficult as fpDebug is in the Lazarus repository. It 
was placed there because fpc's releases were not often enough. But maybe 
it should become a separate package now. Lazarus can use is as a 
dependency. We'll see.


Regards,

Joost.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal

OK, I just downloaded the laz sources and rebuilt from scratch (as usual) and 
it's building with the 3.3.1 now.

I'm testing the server in Sublime Text and first thing I get is:

LSP: invalid response payload {'id': 1, 'result': {'capabilities': 
{'completionProvider': {'triggerCharacters': None, 'allCommitCharacters': None, 
'resolveProvider': False}, 'textDocumentSync': {'openClose': True, 'change': 
1}}}, 'jsonrpc': '2.0', 'error': None}

I assume this is the response from the initialize message being malformed. What 
client were you testing in when developing? 


Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 24, 2020, at 9:52 AM, Ryan Joseph  wrote:
> 
> LSP: invalid response payload {'id': 1, 'result': {'capabilities': 
> {'completionProvider': {'triggerCharacters': None, 'allCommitCharacters': 
> None, 'resolveProvider': False}, 'textDocumentSync': {'openClose': True, 
> 'change': 1}}}, 'jsonrpc': '2.0', 'error': None}

Just tested on my language server and the problem is you provided a null error 
key, which is not in the protocol.

I've never seen the fpjsonrpc unit before so I don't know where this got 
inserted but it needs to be removed.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 24, 2020, at 10:23 AM, Ryan Joseph  wrote:
> 
> Just tested on my language server and the problem is you provided a null 
> error key, which is not in the protocol.
> 
> I've never seen the fpjsonrpc unit before so I don't know where this got 
> inserted but it needs to be removed.

I think we need to override a method to remove the null error, like this:

function TLSPDispatcher.FormatResult(Const AClassName, AMethodName: 
TJSONStringType;
Const Params,ID, Return : TJSONData) : TJSONData;

begin
  Result:=TJSONObject.Create([
'result',Return,
TransactionProperty,ID.Clone
]);
  if jdoJSONRPC2 in options then
TJSONObject(Result).Add('jsonrpc','2.0');
end;


but I'm still not getting any results from Sublime Text. The bigger problem now 
however is that I'm not seeing stderr message in Sublime Text so I have no idea 
what's going on. There's apparently a new discord server for the LSP package so 
I'm going to ask questions here if you want to follow along (see link below). 
So anyways, I give up until I can get error messages. :) My server is socket 
based so I could run it in an terminal to see the output but I have no 
experience with stdio servers. If you have any means try Sublime Text for 
yourself and see if you can figure it out. The editor your using must be 
working though 

https://discordapp.com/channels/280102180189634562/645268178397560865

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Michael Van Canneyt



On Fri, 24 Apr 2020, Ryan Joseph via fpc-pascal wrote:



OK, I just downloaded the laz sources and rebuilt from scratch (as usual) and 
it's building with the 3.3.1 now.

I'm testing the server in Sublime Text and first thing I get is:

LSP: invalid response payload {'id': 1, 'result': {'capabilities': 
{'completionProvider': {'triggerCharacters': None, 'allCommitCharacters': None, 
'resolveProvider': False}, 'textDocumentSync': {'openClose': True, 'change': 
1}}}, 'jsonrpc': '2.0', 'error': None}

I assume this is the response from the initialize message being malformed. What 
client were you testing in when developing?


I believe the OP was using Emacs.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Michael Van Canneyt



On Fri, 24 Apr 2020, Ryan Joseph via fpc-pascal wrote:





On Apr 24, 2020, at 10:23 AM, Ryan Joseph  wrote:

Just tested on my language server and the problem is you provided a null error 
key, which is not in the protocol.

I've never seen the fpjsonrpc unit before so I don't know where this got 
inserted but it needs to be removed.


I think we need to override a method to remove the null error, like this:

function TLSPDispatcher.FormatResult(Const AClassName, AMethodName: 
TJSONStringType;
Const Params,ID, Return : TJSONData) : TJSONData;

begin
 Result:=TJSONObject.Create([
   'result',Return,
   TransactionProperty,ID.Clone
   ]);
 if jdoJSONRPC2 in options then
   TJSONObject(Result).Add('jsonrpc','2.0');
end;


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.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pascal Language Server

2020-04-23 Thread Ryan Joseph via fpc-pascal


> On Apr 24, 2020, at 12:46 PM, Michael Van Canneyt  
> 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;
var
  URI: TURI;
  Code: TCodeBuffer;
  X, Y, PStart, PEnd, Count, I: Integer;
  Line: string;
  Completions: TCompletionItems;
  Identifier: TIdentifierListItem;
  Completion: TCompletionItem;
begin with Params do
  begin
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
begin
  Count := CodeToolBoss.IdentifierList.GetFilteredCount;
  for I := 0 to Count - 1 do
  begin
Identifier := CodeToolBoss.IdentifierList.FilteredItems[I];
Completion := TCompletionItem(Completions.Add);
Completion.insertText := Identifier.Identifier;
Completion.detail:=Identifier.Node.DescAsString;
Completion.insertTextFormat := TInsertTextFormat.PlainText;
  end;
end else begin
  if CodeToolBoss.ErrorMessage<>'' then
writeln(stderr, 'Parse error: ',CodeToolBoss.ErrorMessage)
  else
writeln(stderr, 'Error: no context');
end;

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


Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal