Coder Social home page Coder Social logo

hvyindustries / crane Goto Github PK

View Code? Open in Web Editor NEW
240.0 17.0 25.0 10.19 MB

PHP Intellisense/code-completion for VS Code

Home Page: https://hvy.io/crane

License: Other

TypeScript 94.60% PHP 5.40%
php code-completion intellisense vs-code productivity plugin productivity-booster

crane's Introduction

Crane - PHP code-completion for VS Code

Crane is a productivity enhancement extension for Visual Studio Code that provides code-completion for PHP. It has zero dependencies and largely works with projects of any size. It is still in development, and as such there may be bugs and/or missing features.

Please report any bugs that you find in our issue tracker on GitHub.

Follow @HvyIndustries on Twitter for updates!

How To Get Started

  1. Install Crane by pressing F1 in VS Code, then typing ext install crane
  2. Open a PHP project
  3. Check the status bar at the bottom and watch Crane parse all the PHP files it finds
  • Optionally, install the PHP Stubs to get code-completion for the built in PHP classes by pressing F1 in VS Code, then typing crane php stubs and selecting the appropriate option from the list.

For the best development experience, make sure you have the PHP linter enabled in your user settings, and set it to run onType instead of onSave!

You can also set php.suggest.basic to false to disable VS Code's built-in php code completion and avoid duplicate suggestions.

Demo


What's new in v0.3.7 (latest release)

  • Fix issue with including file on Linux

What's new in v0.3.7

  • Disabled bug report link to avoid misleading users into thinking there is a bug
  • Upgraded php-parser to 2.0.6 to fix some crashes and freezing
  • Added a special case for suggesting php opening tags (<?php)

What's new in v0.3.5

  • Bug fixes
  • Remote error reporting to help us find and fix bugs faster

What's new in v0.3.4

  • Significant performance improvements when requesting suggestions (up to 7,500% faster)

What's new in v0.3.3

  • Document symbol provider - view top level symbols in the current file
  • Workspace symbol provider - view top level symbols throughout the workspace
  • Performance improvements

What's new in v0.3.2

  • Added go to definition on classes, traits & interfaces
  • Fix several bugs introduced in v0.3.1
    • Namespace insert text should be prefixed with a backslash (Thanks @TheColorRed for pointing out this mistake!)
    • Crane no longer adds the fully qualified namespace to a class if the class is in the same namespace
    • Fixed issue where there were no suggestions for properties and methods defined in traits
  • Disabled Crane suggestions when typing on a single line comment
  • Bug report link now prefills basic information including vscode version, crane version and platform (win/linux/macos)

Current Features

  • Code-completion (work in progress)
    • For user created code
    • Optionally for built-in PHP functions and classes (such as PDO)
  • Go to definition on classes, interfaces and traits
  • Peek definition on classes, interfaces and traits
  • Document & workspace symbol providers

Planned Features:

  • Find references
  • Signature provider to show method parameter suggestions
  • Hover provider to show information about symbol under the cursor
  • Full go-to/Peek definition on variables, methods, properties, etc
  • PhpDoc support (both for reading and writing documentation)

User Feedback

Another total must have for PHP developers using Visual Studio Code.
Jan Hajek

Essential extension for every PHP developer, just install :)
Marcelo Rodrigo

Essential to every PHP developer, recommended!
Gabriel Coronado

That's the tweet I've been waiting for since the first public release of VS Code. Thanks.
Bruno Baketaric

omg omg omg omg omg
Rich Perez

👌👌👌 super awesome.
яєαℓιѕт נανѕтαн

Known Issues

  • If you get duplicate suggestions for variables, etc. you can disable VS Code's built-in php code-completion by setting php.suggest.basic to false in your settings.
  • There can be strange behaviour when working with PHP and HTML in the same file.
  • If you have a syntax error in a file, you may not get a full list of suggestions for that file.
  • Go to definition only works on classes, traits and interfaces

Links

Please report any bugs you find!

"HVY", "HVY Industries" and "Hvy Industries" are trading names of JCKD (UK) Ltd

Icon by http://icons8.com/

crane's People

Contributors

ichiriac avatar nevadascout avatar thecolorred 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crane's Issues

Peek Definition Provider

hello think put peek at the latest version. It would be very, very useful apart from putting on behalf of the class you can open and edit .. with that and solving the serious problem of freezing wow and apart from going to the definition
editingevolved_references

editingevolved_ctrlhover

vscode engine version set too high

Hello again,

I was trying to play a little with your newest version, so I forked the repo and tried it. VSCode gave me an error on all lines import {...} from 'vscode';, and refused to run for debugging.

I figured out that your version requirement of the vscode engine is a little too high (0.11.x doesn't exist yet), so the vscode module doesn't download the vscode typings definition.

Going back to 0.10.x and redo a npm install vscode fixed the problem, and I was able to run the extension with my modifications.

Hope this helps,

Cheers

Document Symbol Provider

VS Code specific feature - when typing @ in the command palette, we should show a list of symbols available (classes, traits, methods, etc) in the current document

Deleting a file does not remove suggestions

If you delete a PHP file after it has been parsed, then the suggestions created from that file remain.

We need to watch the workspace and when a file is deleted, remove it from the tree.

Hover Provider (basic implementation)

When hovering over a symbol, variable or member, we should display information about it.

As much info as possible should be taken from phpdoc comments

Requires #12

  • Classes / interfaces / traits
  • Class instance variables
  • Functions / properties on $this
  • Functions / properties on instance variables
  • Parameters
  • Constants -> plus their values (if simple)

Type definitions for 3rd party classes installed from Composer

When importing a class with composer, it would be nice to have intellisense suggestions for those classes.

We need a way that users can define an "interface" for a class with its properties and methods -- and their access modifier.

As of #35, PDO should be the first custom type definition.


Blocked by #1 (class instance variables have no suggestions)

Go to definition Provider

When pressing F12 on a symbol, the editor should navigate to it's definition.

Build a symbol cache from the treebuilder with the symbol and it's filepath, line and character number for quick access.

  • Class / interface / trait names (namespace aware)
  • Global functions
  • Properties / methods
  • Local variables

Triggered by

  • F12
  • Ctrl+Click

Need to ensure that class inheritance/structure is followed

it doesn't work

// Whether php validation is enabled or not.
"php.validate.enable": true,
// Points to the php executable.
"php.validate.executablePath":"D:/wamp/bin/php/php5.5.12/php.exe",
// Whether the linter is run on save or on type.
"php.validate.run": "onType"

i set the value,but it still doesn't work.
why?

Watch for filesystem changes to rebuild suggestions

If I delete a php file containing a class, that class will still show up in suggestions.

We need to watch the workspace folder for php file changes and rebuild the suggestions list for any changed files.

Include:

  • Create
  • Delete
  • Edit

Locks Up Editor

I just installed this extension, and ever since my editor has stopped responding. Nothing in particular is causing this, but it is after it "Processes the files" it happens.

Here are the cases that I have had when this happens:

  • Typed $ and it locked
  • Went to the bathroom, came back and it was locked

Build suggestions even if there are parse errors

Currently the parser throws an exception if it encounters a parser error in the file meaning no AST is returned.

This should be changed so that any AST generated up to the point of the parse error should be returned anyway.

Refactor/Rename Symbol

We should be able to Refactor/Rename a symbol by right clicking or pressing F2 on a symbol. It should then allow us to replace all the related symbols in the project (based on scope).

  • Class / interface / trait
  • Variable
  • Property
  • Method
  • Constant
  • Function

Note: this is closely linked to / depends on #6

Suggest filenames/folders when trying to include a file

When typing include or require we should offer folder and filename suggestions.

For example, typing

require "E

Should suggest ExampleClass.php and ExampleFolder/ (assuming they are in the same folder as the file we're editing)

Support PHPDoc comments

PHPDoc comments on methods, properties, etc should be displayed in the intellisense as extra information.

This feature depends on php-parser adding support for comments.

Type hinting should be included:

/**
 * @var string
 */
$test = "test";

Update the treebuilder to store the last doc comment that we find, and then if symbol definition, check the doc comment is the line above the symbol and apply information as required.

  • Description/summary
  • @var
  • @param
  • @return
  • @throws
  • @deprecated

This first pass will enable code completion to use the phpdoc comment typings, but only on top level variables.

Eg.

/** @var SomeClass */
$test = $otherObject;
$test->
//      ^ works here

$test->prop->
//            ^ won't work here yet

Build suggestions even if there is a syntax error

Currently, we cannot build intellisense suggestions if there is a syntax error in the file being worked on, making suggestions very unreliable at the point.

This is a major problem; we should be able to ignore the error and build up as many suggestions as possible.

This will enable:

  • Building suggestions on type (instead of on save)
  • Building suggestions when opening suggestions (currently having $this-> without calling a method or property is deemed a synax error)

Freezing Bug

I installed this extension to VS CODE, then it started to freeze. And I have to restart VS code every time.
I have this issue with combination of VS 1.1.0 an this extension. It worked perfectly on previous build. Without the extension I don't have any freezing problem.

Find all references

We should be able to find all references of a symbol in the workspace.

For example, everywhere that we're referencing a certain property on a class

have some suggestion on variables completion.

  1. when complete the variables name i often need to type a "$" first to do that,i think this can be improved.
  2. Inside a class,for example here is a variable $date, if i type "$this->" ,there wont be "date".instead,when i also type a "$" first,"$date" comes . lol...
  3. im a php beginner,and now im learning a framework called Phalcon,i copied the source code of phalcon to the workspace,and i found this Extension can identify some classes, but some functions inside those classes cant support well...On the other hand ,if i imported those source code in Eclipse,it can Autocomplete very well. anyway ,better nothing.haha...

anyway~~thanks 4 ur effort.hope this extension can be better and better

Duplicate variable suggestions

Testing with the latest version of CodeIgniter (3.0.6), I've discovered that there are duplicate variable suggestions, which are also being flagged as parameters even though they are not available in scope.

(This is unrelated to #10)

Debug option

Enable debug mode in user/workspace settings and log everything out to a file.

  • File parsing (success/error)

Update main project readme

The readme is now fairly outdated as several new features and bug fixes have been made since it was originally written.

Handle namespaced code

The parser might fall over if a file contains a namespace... Need to double check this

Clean up the way the current item finds words at the cursor

The code is doing a strange validation to get a string to see if it is part of the current class. Workbench has a built in function to get the current word where the cursor is, this could make the code cleaner with smaller if statements. Where this:

if (expression.lastIndexOf("$this", 0) === 0 ||
    expression.lastIndexOf("($this", 0) === 0 ||
    expression.lastIndexOf("if($this", 0) === 0 ||
    expression.lastIndexOf("elseif($this", 0) === 0 ||
    expression.lastIndexOf("!$this", 0) === 0)
{

would become this:

if(expression == '$this'){

Performance Optimisation

For large projects, the performance of Crane can be pretty shocking.

We need to review the extension and improve the performance as much as possible.

  • Handle file errors
  • Resolve issue with loading too many files at once
  • Parsing large projects efficiently
  • Profile for memory leaks delay until 0.2
  • Other improvements delay until 0.2

http://stackoverflow.com/a/30087518/492298
https://hacks.mozilla.org/2012/11/tracking-down-memory-leaks-in-node-js-a-node-js-holiday-season/
https://strongloop.com/node-js/node-js-performance-tips/

Can't type dollar symbol $ when on french keyboard layout

Hello,

Currently running on Ubuntu 14.04 , with keyboard layout set on "Français" ( French AZERTY ).

Whenever I press the dollar-symbol $ key, it's a semicolon ; which appear instead.

It's the only key that cause trouble. Moreover this bug only occur on PHP files, I can properly type the dollar $ anywhere else.

Rebuild object tree on certain key presses + on save

The delayer that kicks off object tree construction is often not fired if you're typing quickly (intentionally).

To counter this, when typing a ; or } we should rebuild the object tree for the document, as it's likely that the syntax will be valid.

Also try to build the tree on file save

Import identifier from other namespace

Hello,

I would love to see the ability to import use statements for classes or functions in other namespaces. Ideally, after typing the name of a class, you would hit a hotkey and it would grab the fully-qualified class name and alphabetically add it at the top of the file.

Cache object tree for each project to speed up load times

My suggestion is to generate a simple hash of the workspace directory and use that as the folder name in %APPDATA% on windows and ~/.crane on OSX/Linux. For example:

Workspace folder: C:/users/ns/projects/myproject/
Generated hash of the folder string: uef5vbrtfeo8

Cache folder system:

%APPDATA%
    \ crane
       \ uef5vbrtfeo8
         \ tree.cache
       \ nyf9psbtd9rg
         \ tree.cache

Each workspace that has something to store in the cache gets a separate folder inside the crane directory to store the cache files in.

This prevents needing to update the gitignore and keeps the workspace folder clean. This is especially important because some git tools update diffs whenever any file in a workspace changes, and if we're constantly modifying cache files then this could cause an issue.

Let's add a new command (Rebuild Sources) -- both a command from the palette and a keyboard shortcut Ctrl + Shift + R (?)

I also think this should be enabled by default. Using a folder other than the project workspace to store the cache files makes this less of an issue.

Class autoloading support

Testing with the latest version of CodeIgniter, there are no class level suggestions due to the following code in the controller constructor:

class CI_Controller
{
    private static $instance;

    public function __construct()
    {
        self::$instance =& $this;

        // Assign all the class objects that were instantiated by the
        // bootstrap file (CodeIgniter.php) to local class variables
        // so that CI can run as one big super object.
        foreach (is_loaded() as $var => $class)
        {
            $this->$var =& load_class($class);
        }

        $this->load =& load_class('Loader', 'core');
        $this->load->initialize();
        log_message('info', 'Controller Class Initialized');
    }
}

Handle PHP with inline HTML

Need to investigate if a php file with html in it still offers code suggestions.

As a side note to this, we should show suggestions in .phtml, .phps and any other valid php files.

Ignore lines containing parse errors when building suggestions

With the change in #29 (build suggestions even if there are parse errors), suggestion generation is a lot more reliable.

However, it is still not as reliable as it could be. If there is a parse error on line 4, but a variable is defined on line 5, then trying to load suggestions on line 6 will not show the variable from line 5.

This could be solved, by ignoring any lines that have parse errors on them. This would allow building suggestions for the entire file regardless of how many errors there are.

This may introduce some unexpected behaviour, so care should be taken when implementing this feature.

Class instance variables have no suggestions

When declaring a variable like $instance = new MyClass() we should offer completion suggestions when typing $instance->

  • simple case ($instance = new MyClass())
  • parameter type hinting (function(MyClass $class) { })
  • results of type hinted functions (function something() : MyClass { })
  • class properties ($this->prop = new MyClass()) moved to #68
  • obscure edge cases ((new MyClass)->myProperty()) moved to #68

Branch: feature/signatureHelp
First pass merged in #67

No class-level suggestions being shown

Instead of words ( Is it necessary to enable indexing or something for correct behavior?)

In class file i expect member metods
and variables instead of native PHP functions ...

VS Code freezes and crashes for no reason

bug hello , lower the extension and makes the visual studio code freezes and restarts all the time .. I was interested in trying it but in the end for those problems and everything worked uninstall normal again. Should check that mistake because it is very annoying and frustrating when programming in php

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.