Alexey-T / CudaText

Cross-platform text editor, written in Free Pascal
Mozilla Public License 2.0
2.48k stars 171 forks source link

Wanted the setup of working LSP server for PHP #3901

Closed Alexey-T closed 2 years ago

Alexey-T commented 2 years ago

@johntor wrote in #3899

Bad news from here! I couldn't find an LSP Server for PHP working out of the box. First I tried felixfbecker/php-language-server which seemed promising but was released on 2018 and it is depended on other external projects that have changed over the years and now there are 240 Open issues. I tried to some fixes but it is not reliable and is hard to suggest it to simple users.

Then I tried bmewburn/vscode-intelephense which is very nice and it is working great in VSCode. The second is written in ts and needs a lot of patching to fix it for Cud and will be hard to maintain in the future.

Because I have limited spare time these days to get involved, I have to admit defeat!


from Alexey: wanted the working setup for LSP Client for PHP syntax. Like at the end of https://wiki.freepascal.org/CudaText_plugins

18 LSP Client

    18.1 LSP server for Python
    18.2 LSP server for CSS/SCSS/LESS
    18.3 LSP server for Nim
    18.4 LSP server for Rust
    18.5 LSP server for AutoHotkey
    18.6 LSP server for JavaScript/ReactJS
    18.7 LSP servers for C/C++
    18.8 LSP server for Red
Alexey-T commented 2 years ago

@johntor The author of RJ TextEd has the forum topic about LSP server for PHP. https://www.rj-texted.se/Forum/viewtopic.php?f=23&t=5005 Maybe you can try his steps?

DUOLabs333 commented 2 years ago

This seems like an updated version: https://github.com/zobo/php-language-server

Alexey-T commented 2 years ago

Maybe someone can give 'steps' how to install+setup the server?

johntor commented 2 years ago

All these are based on the same project that I mentioned before. The installation should be easy for every user, which is not! In Sublime you just download a plugin and you are ready to go. Most users want to jump into a tool and get 100% of it without touching any parameter! I'm not one of these but these days I'm so busy so I can not test anything. Keep on and I will be back...

TomBraider42 commented 2 years ago

I tried zobo/php-language-server on Windows and get the "server console window" opened via CudaText. But that's all that happens. I think the server is not initialized. But I don't get any messages what is wrong. There are also some other PHP servers listed on https://langserver.org/.

johntor commented 2 years ago

I tried zobo/php-language-server on Windows and get the "server console window" opened via CudaText. But that's all that happens. I think the server is not initialized. But I don't get any messages what is wrong. There are also some other PHP servers listed on https://langserver.org/.

It is based on felixfbecker/php-language-server

see the first post...

TomBraider42 commented 2 years ago

The zobo project was update 2 months ago and has 5 issues. So i think it should work or nobody is using it. ;) Also Felix Becker works on it.

Alexey-T commented 2 years ago

@veksha I want to donate you e.g. $30 if you help with this issue.

veksha commented 2 years ago

https://github.com/CudaText-addons/cuda_lsp/pull/11 this PR is required for making https://github.com/zobo/php-language-server work with Cuda_LSP. (with --tcp-server=127.0.0.1:12345 switch at least. Stdio mode for this server is not working for me)

  1. configure for Cuda_LSP + zobo/php-language-server lsp_php.json:

    {
    "name": "PHP",
    "lexers": {
        "PHP": "php"
    },
    "tcp_port": 12345,
    }
  2. start lsp server, for example: php bin/php-language-server.php --tcp-server=127.0.0.1:12345

veksha commented 2 years ago

@Alexey-T , @TomBraider42 , @johntor , @DUOLabs333 please test this if you can and report.

PS: I think autocompletion (and diagnostics) is not working, other features seem to work (go to definition, hover, go to references). I will look into it a bit later.

CudaText-addons commented 2 years ago

On Ubuntu 20 I cannot install PHP 8 using this doc https://linuxize.com/post/how-to-install-php-8-on-ubuntu-20-04/

I got

user@PC:~$ sudo apt install php8.0-cli
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 php8.0-cli : Depends: libpcre2-8-0 (>= 10.38) but 10.34-7 is to be installed
E: Unable to correct problems, you have held broken packages.

so I cannot test it here. can you write the wiki topic like these, please?


    18.1 LSP server for Python
    18.2 LSP server for CSS/SCSS/LESS
    18.3 LSP server for Nim
    18.4 LSP server for Rust
    18.5 LSP server for AutoHotkey
    18.6 LSP server for JavaScript/ReactJS
    18.7 LSP servers for C/C++
    18.8 LSP server for Red

https://wiki.freepascal.org/CudaText_plugins

veksha commented 2 years ago

On Ubuntu 20 I cannot install PHP 8 using this doc

try XAMPP https://www.apachefriends.org/download.html

can you write the wiki topic like these, please?

of course

Alexey-T commented 2 years ago

Installed XAMP, now can run php using fullpath. but server cannot run!

user@PC:~$ /opt/lampp/bin/php /home/user/repos/php-language-server/bin/php-language-server.php  --tcp-server=127.0.0.1:12345
PHP Fatal error:  Uncaught Error: Class "LanguageServer\StderrLogger" not found in /home/user/repos/php-language-server/bin/php-language-server.php:18
Stack trace:
#0 {main}
  thrown in /home/user/repos/php-language-server/bin/php-language-server.php on line 18

using latest GH version of php-server.

DUOLabs333 commented 2 years ago

@johntor What do you mean "install a plugin"? Don't you still have to start the server?

DUOLabs333 commented 2 years ago

@Alexey-T You need to use composer, there seems to be dependencies you are missing.

DUOLabs333 commented 2 years ago

php composer.phar update should work, within the project folder.

Alexey-T commented 2 years ago

php composer.phar update should work, within the project folder.

In what project folder? in the folder of php-language-server it don't work:

user@PC:~/repos/php-language-server$ php composer.phar update
Could not open input file: composer.phar
DUOLabs333 commented 2 years ago

Well, you have to install it. It should be available in whatever repo you use, eg apt-get install compsoer, or pacman install composer. Then just use composer update in the project directory.

DUOLabs333 commented 2 years ago

Hmm, you are going to have to do it manually (I'm not sure why it's doing that, but I'm not going to try and debug it) --- follow this: https://getcomposer.org/download/

Alexey-T commented 2 years ago

Composer installed (after I call 'apt install jsonlint') Now I call 'composer update' and got this

Screenshot from 2022-06-15 16-05-57

DUOLabs333 commented 2 years ago

You have to upgrade your php. Can you try installing from apt again.

Alexey-T commented 2 years ago

Ok, tried that - I need PHP 7.3 (from my screnshot) and I run sudo apt install php7.3-cli and got APT error

The following packages have unmet dependencies:
 php7.3-cli : Depends: libpcre2-8-0 (>= 10.38) but 10.34-7 is to be installed
DUOLabs333 commented 2 years ago

You actually need at least 7.4, can you install libpcre2-8-0 separately?

Alexey-T commented 2 years ago

Installed PHP 7.4! Now this error in Composer

Screenshot from 2022-06-15 16-13-49

DUOLabs333 commented 2 years ago

Try apt install php7.4-xml (this part of the reason I do not like php, as composer is third-party, so it can't cover all needs).

Alexey-T commented 2 years ago

I got next error (soemthing about missing PHP extension 'mbstring'?) . I give up with Composer. I cannot test it. Maybe will test on Win10 later.

DUOLabs333 commented 2 years ago

You also need apt-get install php7.4-mbstring. Yeah, php is a whole thing.

veksha commented 2 years ago

sorry, a forgot about all dependencies. make notes of all your steps, Alexey! (for wiki) I used Muon package manager in Lubuntu to search for php dom and others dependencies.

Alexey-T commented 2 years ago

my steps are needed for wiki? but they are failed steps. i even cannot run the server!

DUOLabs333 commented 2 years ago

There's a step-by-step process to getting it to work.

Alexey-T commented 2 years ago

does this error tell us, that I must use PHP8? it is the same when I run PHP7.4 and PHP8.

user@PC:~$ cd ~/repos/php-language-server/bin/
user@PC:~/repos/php-language-server/bin$ php php-language-server.php 
PHP Fatal error:  Uncaught Error: Class 'LanguageServer\StderrLogger' not found in /home/user/repos/php-language-server/bin/php-language-server.php:18
Stack trace:
#0 {main}
  thrown in /home/user/repos/php-language-server/bin/php-language-server.php on line 18
DUOLabs333 commented 2 years ago

Huh, this actually is an opened issue on the old server: https://github.com/felixfbecker/vscode-php-intellisense/issues/440

veksha commented 2 years ago

my steps are needed for wiki? but they are failed steps. i even cannot run the server!

i think it's just

  1. install php8,
  2. git clone server,
  3. compose update inside server folder
  4. install few php extensions (search in your package manager) and that is all.
veksha commented 2 years ago

Class 'LanguageServer\StderrLogger is in this file : do you have it? image

DUOLabs333 commented 2 years ago

You may also have to composer run-script --working-dir=$WORKDIR parse-stubs

Alexey-T commented 2 years ago

@veksha yes, I have this file - we use the same GH repo with you.

veksha commented 2 years ago

make sure you have read Installation section of readme: https://github.com/zobo/php-language-server#installation composer update and composer run-script --working-dir=vendor/felixfbecker/language-server parse-stubs are mentioned there.

Alexey-T commented 2 years ago

Thanks. I will try it on Win10 - where I will get XAMPP or just PHP8. my Ubuntu config is not good for that

veksha commented 2 years ago

if all go well composer update should run script parse-stubs automatically (i think)

Alexey-T commented 2 years ago

(Updated the LSP plugin in addons)

veksha commented 2 years ago

autocompletion is working actually. it was not working because i opened .php file that is outside of current Cud project directory. In Cuda_LSP config there is a parameter named root_dir_source. For zobo's server to index .php files they must be inside this dir.

In Cud's Project manager you must save your project file to your php project location. otherwise the root_dir will be wrong.

image

veksha commented 2 years ago

diagnostics work too.

image

they will not work if the file is outside of current workspace.

Alexey-T commented 2 years ago

good, that it works. Please write me to support (at ) uvviewsoft.com so I can send you the donation

Alexey-T commented 2 years ago

I wrote help text, pls check, https://wiki.freepascal.org/CudaText_plugins#LSP_server_for_PHP

veksha commented 2 years ago
{
    "name": "PHP",
    "lexers": {
        "PHP": "php"
    },
    "cmd_unix": ["php", "folder_of_server/bin/php-language-server.php", "--tcp-server=127.0.0.1:12345"],    
    "cmd_windows": ["php.exe", "folder_of_server\\bin\\php-language-server.php", "--tcp-server=127.0.0.1:12345"],    
    "tcp_port": 12345
}

if tcp_port is specified cmd_windows and other cmd_* are ignored. see https://github.com/Alexey-T/CudaText/issues/4186

it is better to change this in wiki to: "you must start php-language-server from terminal" until issue is resolved.

Alexey-T commented 2 years ago

Edited the wiki part. OK now?

veksha commented 2 years ago

https://github.com/Alexey-T/CudaText/issues/4186#issuecomment-1157274977

CudaText-addons commented 2 years ago

Updated the wiki. we have solved the issue now. @johntor

veksha commented 2 years ago

server installation steps for Ubuntu 20.04.4 and PHP 7.4.3

  1. install php, php-dom extension and composer
  2. clone https://github.com/zobo/php-language-server
  3. run composer update inside php-language-server directory
  4. run php bin/php-language-server.php and ensure you see no errors.
  5. configure cudatext LSP_client ...

so php-dom extension is the only needed for this server to work. and it must be installed before you run composer update.

EDIT: then I just upgraded to php8.1 and server still works ok.

Alexey-T commented 2 years ago

Where php-dom is described? found https://iqcode.com/code/php/install-php-dom-extension-ubuntu which tells it's "php-xml" !