Code Monkey home page Code Monkey logo

vscode-php-phan's Introduction

PHP Phan (Analyzer)

Latest Release Installs Rating Build Status Minimum PHP Version Gitter

5.1.0 (2022-11-01)

  • Update Phan from 5.1.0 to 5.4.1
  • See Phan's NEWS for more details.

5.0.0 (2021-08-10)

  • Update Phan from 4.0.7 to 5.1.0
  • See Phan's NEWS for more details.

The full changelog can be found at NEWS.md

Troubleshooting

General troubleshooting advice:

  • By setting phan.enableDebugLog to true (and restarting Phan), you can get extra debug output. Enabling debug output will slow down this extension.

  • After any changes to the phan settings, the language server must be restarted.

  • VSCode has a built in debugger at "Help" > "Toggle Developer Tools" ( "Console" tab) This will let you see this extension's Phan's debug output.

Installing from source

This can be installed locally with the following method:

npm install
npm run build
node node_modules/.bin/vsce package

The generated VSIX file can be used locally with the steps from https://stackoverflow.com/a/38866913

Local changes can also be run locally by checking out vscode-php-phan, running npm install, then running your changes in an Extension Development Host with . See https://code.visualstudio.com/api/get-started/your-first-extension for more details.

Credits

This VS Code extension and many parts of the language server protocol implementation are based on PHP IntelliSense

This uses Phan

vscode-php-phan's People

Contributors

dumbojetengine avatar felixfbecker avatar greenkeeper[bot] avatar greenkeeperio-bot avatar herbertpimentel avatar jens1o avatar mousetraps avatar tysonandre avatar tysonandre-tmg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vscode-php-phan's Issues

Can only see phan issues one file at the time in the PROBLEMS tab

I have two files in the same directory that is containing issues found by Phan.

When opening the first file the issues is show in the PROBLEMS tab at the bottom. Great!

I now open up the second file (two files opened at the same time). Now the issues from the
first file is removed from the tab and replaced with the issues from the now opened file.

checkValidAnalyzedProjectDirectory vs --config-file

Hi,

The extension checks if there is a config file in the defined phan.analyzedProjectDirectory (function checkValidAnalyzedProjectDirectory).

Phan supports the CLI argument -k/--config-file parameter to use an external config file. This option does not work in the extension and it is being ignored by the checkValidAnalyzedProjectDirectory validation.

Thanks, great extension!

Add an option to assume that the editor is the only source of changes to files?

E.g. don't traverse configured files in directory_list such as vendor/, etc, checking for changes to modification date or file size every time there is a change that needs to be analyzed.

Skipping this should bring down latency somewhat, especially without SSDs

  • Maybe re-check at most once per 60 seconds instead of every time.

This requires changes to the backend (only for language server, not for phan's earlier Daemon classes)

didOpen/didChange/didClose/rename/etc should be sufficient for most uses.

This may require refactoring the server to be able to check a single file against a list of inclusions and exclusions.


Switching between git branches would break this assumption.
Maybe didChangeWatchedFiles might help?

phan.analyzedProjectDirectory = './'?

I want specify project root as a relative path in .vscode\settings.json

{
    "phan.analyzedProjectDirectory": "./"
}

However it seems to be invalid for me:

image

How to debug the language server not starting

I'm helping a co-worker setup phan in their vscode editor, I can get the extension working on my machine but on his machine it sits on:
starting PHP Phan language server

where as mine will go:

[Extension Host] starting PHP Phan language server
console.ts:137 [Extension Host] starting Phan Language Server /usr/local/bin/php Array(12)
console.ts:137 [Extension Host] [vscode-icons] v9.7.0 activated!
console.ts:137 [Extension Host] PHP process connected

and work, we have tried uninstalling his other extensions and have compared out settings.json, his phan installation also works outside of vscode, how can I debug the starting of the language server?

Completion doesn't seem to be working for instance methods.

Test case:

<?php

class TestClass
{
	/** @var string */
	public $test = 'hi';

	public function anotherTest()
	{
		return true;
	}

	public function other()
	{
		return $this->|
	}
}

It's not showing anything in vscode when I type this out. I have gotten it to trigger local variable completion some times. It seems a bit random as to when it'll work, though.

Here is the terminal command it's running as:
php /home/ddecarmine/.vscode/extensions/tysonandre.php-phan-0.8.0/vendor/phan/phan/phan --language-server-verbose --language-server-completion-vscode --language-server-enable-completion --language-server-enable-hover --language-server-enable-go-to-definition --language-server-analyze-only-on-save --use-fallback-parser --language-server-tcp-connect=127.0.0.1:44861

It is running latest vscode extension version. Another thing is that I had to actually put "phan.enableCompletion": true, in my vscode settings.json file, otherwise it didn't actually set the --language-server-completion-vscode flag. In the release notes it says it's enabled by default now, though.

I am running vscode version 1.30.2

Simplify installation steps to try this out, and prompt to improve performance later.

  • ast, runkit_object_id (or php 7.2), and pcntl can have substitutes at the cost of performance.
    Use these substitutes by default when starting out, and prompt to improve performance later.
  • Caching asts in a tmp folder may improve performance if ast is unavailable (use a binary format such as igbinary if available to save space?)
  • Check for xdebug and restart without it silently

Full directory scan

Not sure if this can be done.

I would like to be able to do a full directory scan (or workspace) to be able to see all the problems in the PROBLEMS tab without needing to open up every file in the editor.

This is of course an expensive action so I think this is best implemented as a Command that a user can invoke if need.

This I guess would need some visual feedback. Like issue #66.

Extension stopped working

After the analyze on save branch being merged in, it doesn't seem to be working. I tried enabling debugging in the settings, but it's no longer showing in the extension Output tab. In the processlist it's showing up, though. When I run Phan manually it works.

This commit works for me just fine: 12b8bdd
After that it's broken.

In master this is what shows up for "phan" in my processlist:
php /home/ddecarmine/.vscode/extensions/TysonAndre.php-phan-0.0.9/vendor/phan/phan/phan --language-server-verbose --language-server-analyze-only-on-save --use-fallback-parser --language-server-tcp-connect=127.0.0.1:34873

Not sure how to help debug this. =\

Unable to use the extension with WSL2 (Windows Subsystem for Linux 2)

Current Behavior

  1. Unable to install the extension in a WSL2 ubuntu environment (there is no "install on remote" button, settings get ignored when connected to WSL2).
  2. When trying to use the extension in local using the wsl$ share the following error pops up:
ERROR: Unable to read file \\WSL$\UBUNTU-20.04\home\user\dev\SGN\app\Providers\EventServiceProvider.php: SplFileInfo->isReadable() is false, getPerms()=100666(octal)

Steps to Reproduce the Problem

  1. Try to use the extension while connected to a remote (WSL2) folder.

Specifications

  • Extension Version: 1.4.4
  • PHP Version: 8.0
  • Platform: Windows 10
  • Subsystem: Ubuntu 20.04

Look into user-friendlier ways to allow users to opt into using phan for trusted folders

(and by default, only start language servers corresponding to files/folders that are open)

I'd been discussing how this could be done in a user-friendly and safe way with the reporter of CVE-2021-31416

For current vscode versions:

I looked into how https://github.com/microsoft/vscode-maven/pull/526/files handled it since the Memento API is backed by a sqlite database in a global configuration database (in a user's home directory?), which is reasonable.

  • The first time phan opens a folder and finds a .phan/config.php, prompt the user if they want to trust the extension before executing anything (e.g. checking the php version, etc)

For future vscode versions

There's a feature being previewed right now.

microsoft/vscode#106488 is something along the lines of what I wanted to use for Phan, but it wasn't available when I first published this extension (with respect to phan configs and phan plugins being/invoking executable code by design, etc)

The trusted workspaces concept is intended to centralize and unify a security conscious decision required by a variety of VS Code features. The easiest existing example to understand of this decision is with the ESLint extension. The ESLint extension will try to use the eslint module in the current folder that is opened in VS Code and execute code from it. Since you may have checked out a random repository from the web, this could be dangerous if the repository contains a corrupt eslint module. Notice that ESLint is not trying to be malicious, but rather, the repository/corrupt module is taking advantage of this automatic code execution.

Related to #83

Default "phan.analyzedProjectDirectory" to project root

A nice improvement I find is to default the option "phan.analyzedProjectDirectory" to the main workspace root folder(or in case of a workspace with multi-folders environment search the first workspace folder that has .phan folder).

Another improvement is to make the path possibility to be relative to the main workspace root folder.

This improvement will help when the project is switched across, as a lot of times the .phan folder is placed anyway in the project root folder. Having always to change this is a pain, not too bad for me, but a lot for other people.

Thanks.

Visual annoyance: Hover is switching between "pages"

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

Add a "phan parsing..." text in the status bar.

Hi... my project takes about 10-15 seconds to be parsed by phan... It will be very nice if there was an indicator in status bar that will say when the phan is parsing(like PHP Sniffer: validating... ).

Thanks.

Got 'Called initialized on language server, currently a no-op' on a previously working project after some modification

Maybe this is more about phan itself again.

I have many Bedrock-enabled WordPress websites where I used to configure each plugin independently across different sites which resulted in a mess in my custom configuration in VSCode, so I went and tried to abstract my configuration to the site root and configure each directory to analyze there (may be not the best use case).

Setup:

<site-root-dir>
  .phan
    config.php
  dir1
  ...
  dirx

config.php has been created with phan's --init command, and it contains only one directory to analyze. It works fine when running it via cli.

VSCode settings' phan.analyzedProjectDirectory points to <site-root-dir> (above), I see no errors during startup:

[Extension Host] starting PHP Phan language server
[Extension Host] starting Phan Language Server
C:\php\php.exe 
Array(8)
0: "c:\Users\Adam_Marton\.vscode\extensions\tysonandre.php-phan-0.8.3\vendor\phan\phan\phan"
1: "--language-server-verbose"
2: "--language-server-allow-missing-pcntl"
3: "--allow-polyfill-parser"
4: "--language-server-completion-vscode"
5: "--language-server-enable-completion"
6: "--use-fallback-parser"
7: "--language-server-tcp-connect=127.0.0.1:51310"

But, when opening a file in the analyzed directory, I'll get the following message:

/C:/Users/Adam_Marton/AppData/Local/Programs/Microsoft VS Code/resources/app/out/vs/workbench/workbench.main.js:303
[Extension Host] Request:
{"Content-Length":"52"}
Data:
{"jsonrpc":"2.0","method":"initialized","params":{}}

Received message in coroutine: {"method":"initialized","params":{},"jsonrpc":"2.0"}
Called initialized on language server, currently a no-op
...
<here I get my custom VSCode settings back in JSON>

I saw that this comes straight from phan, but since it works fine in cli I posted this here instead.

I'm on Windows 10, VSCode is 1.30.2, PHP-Phan is 0.8.3.

Please let me know if you need more details.

Completion does not work in combination with other plugins providing similar functions

Suggested remediation: Disable completion in phan's settings or in the other plugin's settings

e.g. for https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client it looks like intelliphense's maintainers have encountered similar issues - disabling the individual features (hover, completion, etc.) of either phan/intelliphense may be enough to fix this

This extension may conflict with other PHP extensions which provide similar functionality. Should you experience duplicate suggestions, incorrect results and/or poor performance, try disabling other extensions first before reporting an issue. Disabling the built-in VSCode PHP Language Features is recommended. Please check the configuration section for language server options.

https://github.com/tysonandre/vscode-php-phan#completion

This is enabled by default. To disable this, add "phan.enableCompletion": false in your config.json settings.

This issue duplicates the findings in phan/phan#2651 (comment)

Call to undefined function Phan\LanguageServer\pcntl_signal()

Yes, there's a chance that this is an issue with Phan itself, but otherwise Phan runs really well on the very same machine/code base/everything.

Env:

  • Windows 10
  • php-ast: 1.0.0

Debug output:

[Extension Host] Starting accepting connections on the language server (pid=281540)
[Extension Host] Error: Call to undefined function Phan\LanguageServer\pcntl_signal() in C:\Users\<username>\.vscode\extensions\tysonandre.php-phan-0.6.2\vendor\phan\phan\src\Phan\LanguageServer\LanguageServer.php:248
Stack trace:
#0 C:\Users\<username>\.vscode\extensions\tysonandre.php-phan-0.6.2\vendor\phan\phan\src\Phan\Phan.php(227): Phan\LanguageServer\LanguageServer::run(Object(Phan\CodeBase), Object(Closure), Array)
#1 C:\Users\<username>\.vscode\extensions\tysonandre.php-phan-0.6.2\vendor\phan\phan\src\phan.php(41): Phan\Phan::analyzeFileList(Object(Phan\CodeBase), Object(Closure))
#2 C:\Users\<username>\.vscode\extensions\tysonandre.php-phan-0.6.2\vendor\phan\phan\phan(2): require_once('C:\\Users\\<username>')
#3 {main}

(Phan 1.1.2 crashed due to an uncaught Throwable)

config.php:

<?php
return [
    'target_php_version' => '7.2',
    'directory_list' => [
        'classes'
    ],
    "exclude_analysis_directory_list" => [
        'vendor/'
    ],
];

Both globally installed and the packaged version of Phan runs perfectly fine, I only get these exceptions within VSCode.

Please let me know if you need more information.

Thanks,
Adam

Finish remaining tasks for completion support from Phan

Add --language-server-enable-completion and upgrade to Phan 1.0.6+

Test that this works in various scenarios without issues

Disable completion support by default, initially.

  • Fix/work around edge cases with completions of properties and variables
  • enable completion by default

Please correct the VSCode Marketplace Project Config

@TysonAndre the extension page in the VSCode marketplace currently points almost everything to the phan repo instead of to this repo-->you almost certainly unintentionally add too much friction to locating this repo, thus dissuading other developers from contributing to your extension

Spawn per workspace

The extension should look for a .phan/config.php inside each opened workspace instead of analysing only one folder.

The multi-project analysis is a very important feature, e.g.: I can't configure just one path in a company we work with 5+ projects at the same time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.