php-language-server icon indicating copy to clipboard operation
php-language-server copied to clipboard

Symlinks not working

Open okrad opened this issue 7 years ago • 5 comments
trafficstars

Hi, in my project root directory I have a symlink to another directory with php files, but they are not indexed at all. In the output console I can see only files from the root directory (and its subdirectories) get indexed.

Is there something I should do to enable symlink following?

I'm on Ubuntu 17.10, vs code v. 1.19.2.

Thank you for the great work btw!

okrad avatar Jan 24 '18 08:01 okrad

@felixfbecker Any hope for symlinks support? Composer has them for some time now and the server doesn't seem to pick up any of the namespaces from locally linked dependencies. Tested with up to date nvim + autozimu/LanguageClient-neovim + this server.

Minimal case to test on:

$ cd ~/tmp
$ git clone https://github.com/cprn/php-language-server-symlinks-minimal-test-case.git
$ cd php-language-server-symlinks-minimal-test-case/myProject
$ composer install
$ php run.php
GULP!    # printing "GULP!" means autoload worked

The content of myProject should look like this:

.
├── ...
├── src
│   └── Drink.php
└── vendor
    ├── cg
    │   └── my-local-bundle -> ../../../myLocalBundle
    └── ...

Now open src/Drink.php and try to jump to Bundle\Bar definition. The client calls textDocument/definition method with position 12,4 and gets an empty set of results in response:

13:55:44 INFO writer-Some("php") src/rpcclient.rs:215 => Some("php") {"jsonrpc":"2.0","method":"textDocument/definition","params":{"bufnr":1,"filename":"/home/user/tmp/php-language-server-symlinks-minimal-test-case/myProject/src/Drink.php","gotoCmd":null,"handle":true,"languageId":"php","method":"textDocument/definition","position":{"character":12,"line":4},"textDocument":{"uri":"file:///home/user/tmp/php-language-server-symlinks-minimal-test-case/myProject/src/Drink.php"}},"id":2}
13:55:44 INFO reader-Some("php") src/rpcclient.rs:169 <= Some("php") {"result":[],"id":2,"jsonrpc":"2.0"}

cprn avatar Oct 18 '18 16:10 cprn

Happy to accept a PR

felixfbecker avatar Oct 18 '18 16:10 felixfbecker

Will try. Any recommendation on where to start debugging this? A tip on how to make the server spit some logs? Quick search revealed a reference to /var/log but it's only mentioned in a test file.

cprn avatar Oct 19 '18 09:10 cprn

The language server can log over $this->client->window->logMessage() (will appear in the editor output channel) and with fwrite('...', STDERR) (will appear on the console)

felixfbecker avatar Oct 19 '18 12:10 felixfbecker

I won't be sending a PR after all. I was testing a workaround for quite some time, it seemed to work well enough, but then I went on vacation, forgot about it and switched to a different langserver when I came back - removing my changes on the way, for that I'm sorry.

Having a quick look at the code now I'm pretty sure I changed the line 26 in FileSystemFilesfinder like so:

--- a/src/FilesFinder/FileSystemFilesFinder.php
+++ b/src/FilesFinder/FileSystemFilesFinder.php
@@ -24,7 +24,7 @@ class FileSystemFilesFinder implements FilesFinder
             foreach (new GlobIterator($glob) as $path) {
                 // Exclude any directories that also match the glob pattern
                 if (!is_dir($path)) {
-                    $uris[] = pathToUri($path);
+                    $uris[] = pathToUri(realpath($path));
                 }
 
                 yield timeout();

but I don't remember if that's all. I might have changed something in the GlobIterator dependency as well - that I cannot recall. I can recall, however, what I wanted to do before sending a PR was to abstract directories handling to a function that detects whether the $path points to a link that resolves to a directory and in that case recurrently instantiates a new GlobIterator to traverse it so that the final $uris array would include paths matching $glob in those directories as well - I still think it should be done.

Hopefully somebody will take it from here. Good luck!

cprn avatar Nov 22 '19 15:11 cprn