TysonAndre / vscode-php-phan

Phan - PHP Static Analysis for VS Code
Other
24 stars 4 forks source link

Visual annoyance: Hover is switching between "pages" #78

Open rogermartensson opened 4 years ago

rogermartensson commented 4 years ago

Not sure how I should describe this. Please change subject to something better. I do like my hover but this is pretty annoying. I hope you can find a way to make it stop. :)

here is a GIF showing what is happening.

hoverissue

TysonAndre commented 4 years ago

You may need to disable hover from other extensions - A shorter one without @param is provided by Phan - the one I see in the screenshot doesn't look like Phan.

To disable hover from phan, set phan.enableHover to false.

This is also a known problem when phan.analyzedProjectDirectory is an array with more than one project. I'm not sure how to fix that in vscode, but if you figure out how, let me know.

It's also possible that vs code is flickering because Phan's taking too long to generate hover text, causing vs code to start new requests, kill the language server, etc. Right now, Phan does a full analysis so it can properly generate hover text for $x->someMethod()

TysonAndre commented 4 years ago

See https://github.com/TysonAndre/vscode-php-phan/issues/70 - I haven't been able to figure out how to resolve this in the language client library I'm using, but external contributions are welcome.

What's the value of phan.analyzedProjectDirectory you're using?

rogermartensson commented 4 years ago

analyzedProjectDirectory is an array to multiple directories.

I did some testing with editor.hover.delay and when I reached about 3 seconds (3000 ms) the "flickering" stopped. So you might be on to something there with your thought about "taking too long". But I think a hover delay of 3 seconds is way too long. :-)

It's like it keeps redrawing the Hover over and over again, even if everything that should be shown is there.

Maybe there is a way for the server to signal a "Phan is checking..." message to the client so it gets a quick response and when Phan has a message to show it can update the Hover? That type of "flicker"/update is more understandable.

TysonAndre commented 4 years ago

Related to https://github.com/phan/phan/issues/3252

analyzedProjectDirectory is an array to multiple directories.

The fact that there are multiple directories is the cause of it, I assume the 3 seconds working is just a timing coincidence and may change in the future.

Speeding up Phan's hover response may very well just make the flickering faster.

The actual problem is that Phan is sending hover requests to both servers. I think the other server would respond with null in that case, but I'm not 100% sure.

https://code.visualstudio.com/api/references/vscode-api#RelativePattern

I wasn't initially able to figure out how to limit hover suggestions to the workspace corresponding to a given Phan folder, but it looks like I can use a RelativePattern (to the phan project directory) in a DocumentSelector to do that.

https://github.com/microsoft/vscode-languageserver-node/blob/master/client/src/client.ts mentions it's using that for registerHoverProvider, and other things - https://code.visualstudio.com/api/references/document-selector

    protected registerLanguageProvider(options: HoverRegistrationOptions): [Disposable, HoverProvider] {
        const provider: HoverProvider = {
            provideHover: (document, position, token) => {
                const client = this._client;
                const provideHover: ProvideHoverSignature = (document, position, token) => {
                    return client.sendRequest(HoverRequest.type, client.code2ProtocolConverter.asTextDocumentPositionParams(document, position), token).then(
                        client.protocol2CodeConverter.asHover,
                        (error) => {
                            client.logFailedRequest(HoverRequest.type, error);
                            return Promise.resolve(null);
                        }
                    );
                };
                const middleware = client.clientOptions.middleware!;
                return middleware.provideHover
                    ? middleware.provideHover(document, position, token, provideHover)
                    : provideHover(document, position, token);
            }
        };
        return [Languages.registerHoverProvider(options.documentSelector!, provider), provider];
TysonAndre commented 4 years ago

See documentSelectors in https://github.com/TysonAndre/vscode-php-phan/blob/master/src/extension.ts , if anyone wants to try to fix this. It might take me a few days to have time to implement and test this