1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-13 17:57:37 +01:00
Commit Graph

222 Commits

Author SHA1 Message Date
Alexandru Pătrănescu
8c0a5b7059
Remove the trailing comma for function call as minimum support version is 7.1 (#5201) 2021-02-12 17:00:58 -05:00
Joe Hoyle
4077de2c93
Add completions for functions (#5128)
* Add completions for functions

Provide autocompletions in the LSP for all global functions and functions from namespaces used in the current context.

* Uncomment code

* PHPCS

* Simplify functions map

Co-authored-by: Matthew Brown <github@muglug.com>

* Switch to storing lowercase function string in array key

* Fix spacing

Co-authored-by: Matthew Brown <github@muglug.com>
2021-02-12 16:59:47 -05:00
Matt Brown
c9ff1eee63 Fix syntax issue in PHP 7.2
Fixes #5206
2021-02-12 11:09:41 -05:00
Joe Hoyle
a3dcc52e9a
Track references on global variables (#5122)
* Track references on global variables

Add global type references to the type map, and fix up unused detection on global variables.

* Add null assertions

* PHPCS
2021-01-28 18:58:02 -05:00
Joe Hoyle
5759472168
Add constant fetch to reference map (#5115)
* Add constant fetch to reference map

To support showing constant types on hover of constant references, we need to add them to the ref map.

* Fix root constants

* PHPCBF
2021-01-28 11:18:28 -05:00
Joe Hoyle
c946242683
Completions for array keys and type literals (#5105)
* Add completions for known array keys

* Use dynamic gap value

* Provide completions for known type contexts

* Fix formatting

* Remove trailing comma

* PHPCS fixes

* Remove support for literal floats

* Fix test for floats
2021-01-26 21:34:46 -05:00
Joe Hoyle
531cd36767
Support completions on class references (#5085)
* Support compleitions on class references

This provides completions on class references (as opposed to initiated objects via the type map), so you can do `MyClass::` and get completitions for static methods and constants etc.

* Only provide completions for references that don't exist
2021-01-24 13:29:21 -05:00
Bruce Weirdan
d659957b88
Resolve class aliases when accessing properties (#5068)
* Resolve class aliases when accessing properties

* Moved Properties::getClasslikeStorage() to ClassLikes::getStorageFor()
2021-01-21 19:38:17 -05:00
orklah
09fb141e49
Document lowercase-string when possible (#4904)
* document lowercase-string

* fix missing strtolower
2020-12-29 11:42:12 +00:00
orklah
2bf25d5f50
Emit an issue when returning a Stringable object when a string is expected (#4657)
* Emit an issue when returning a Stringable object when a string is expected

* Fix issue in Psalm codebase
2020-11-24 00:18:24 -05:00
Matt Brown
4aef96bbac Use lists everywhere for args 2020-10-28 12:45:26 -04:00
orklah
ceaaa39ec3
improve phpdoc (#4352) 2020-10-17 12:36:44 -04:00
Matt Brown
4488d5fb1f Use more accurate arguments count 2020-10-14 18:51:15 -04:00
Matt Brown
516141a380 Rename ControlFlowGraph to more appropriate DataFlowGraph 2020-10-13 16:49:03 -04:00
orklah
10f2966dcb
return types (#4311)
* return types

* remove willReturn for void methods
2020-10-12 15:02:52 -04:00
Matt Brown
fb604bfacb 4.x - move class constants into their own storage object 2020-10-05 09:50:32 -04:00
Brown
da65a4327f Move taint graph functionality into its own object 2020-09-25 00:37:40 -04:00
Brown
56cddd16bf Rename TaintGraph to ControlFlowGraph because it’s about to do more 2020-09-20 23:59:52 -04:00
Brown
abb9502921 Rename Taint object to TaintGraph 2020-09-20 18:27:02 -04:00
orklah
ead107fa9e
More return types (#4173)
* add native return types

* redundant phpdoc
2020-09-12 11:24:05 -04:00
orklah
8c7423505a
add native param types (#4137)
* add native param types

* redundant phpdoc

* add more param types and adds "?" to nullable types

* remove redundant phpdoc

* add more param types and remove redundant phpdoc

* add more param types and remove redundant phpdoc
2020-09-06 19:36:47 -04:00
orklah
f66d57f19d
add native return types (#4116)
* add native return types

* remove redundant phpdoc
2020-09-04 16:26:33 -04:00
orklah
73f6fcde48
Short list syntax (#4102)
* Short list syntax

* revert unrelated CS
2020-09-02 00:17:41 -04:00
orklah
6d36f8f5cc
Nullable strings (#4096) 2020-09-01 09:19:50 -04:00
Matthew Brown
73321339a3 Bump nikic/php-parser 2020-08-09 16:23:43 -04:00
Brown
76bd5b6278 Refactor type comparison 2020-07-21 19:40:35 -04:00
Brown
d950ddfff6 Fix adding sink method 2020-07-16 16:04:17 -04:00
Brown
d1e62f1413 Add programattic sink method
Ref #3828
2020-07-16 16:02:26 -04:00
Joe Hoyle
d1ca68e57a
Fix offset calculation in getReferenceAtPosition (#3783)
* Fix calculation of getPositionFromOffse

* Add test for testGetSymbolPositionRange

* Fix code formatting.
2020-07-09 16:24:51 -04:00
Brown
dc83c2e2fc Add annotation for taint sources 2020-06-21 00:58:56 -04:00
Brown
21e567832f Add API method for adding custom taint sources 2020-06-18 00:16:19 -04:00
Joe Hoyle
b9311f62fb
Support global functions in getSymbolInformation and getSymbolLocation (#3477)
* Support global functions in getSymbolInformation and getSymbolLocation

Currently codebase-wide defined function are not found in `Codebase::getSymbolLocation` or `Codebase::getSymbolInformation`. This means hovers via the LSP on functions not in the current file, or "go to definition" do not work for non-locally defined functions.

It looks to me that this might have been an oversight, as methods do support this.

For stubbed functions, "go to definition" will open the stub file, which is also quite hadny.

* No need to catch expections, they are already in a try block.

* Add empty checks returning null

Co-authored-by: Matthew Brown <github@muglug.com>
2020-06-08 11:20:54 -04:00
Brown
118b700436 Simplify sink mapping for internal calls 2020-05-25 13:10:06 -04:00
Joe Hoyle
588be3b269
Fix getSymbolInformation() for symbols containing ":" (#3400)
Currently a Symbol like `10-15:array{foo: string}` will return ` string}`, as the regex does not specify a string-start caret.
2020-05-19 10:15:13 -04:00
Brown
111303d913 Add non-empty-lowercase-string type 2020-05-15 10:18:05 -04:00
Brown
8f57d0c738 Fix #3204 - normalise function ids where possible 2020-04-20 21:38:35 -04:00
Bruce Weirdan
5be4cc2582
Expose queueClassLikeForScanning (#3070) 2020-04-05 17:25:47 -04:00
Brown
1c8581f4db Add more fields to API existence checks 2020-03-28 21:39:44 -04:00
Brown
4ced26bec2 Fix #3024 - replay errors in --diff --diff-methods mode 2020-03-26 14:22:06 -04:00
Brown
971ae50bea Do prep work for #3024 - improve handling of absent class references 2020-03-26 12:35:27 -04:00
Matthew Brown
9556e9ad69 Disable enclosing method/function return type inference
cc @ragboyjr – this makes Psalm unstable, as method return types cannot change midway through analysis (as it means results would be dependent on file analysis order)
2020-03-16 11:45:49 -04:00
Matthew Brown
43189b3d55 Allow types to be traversed 2020-03-14 23:54:51 -04:00
RJ Garcia
a220d08d9f
Refactor Codebase.php to use MethodIdentifier::wrap (#2972)
Signed-off-by: RJ Garcia <rj@bighead.net>
2020-03-14 19:10:20 -04:00
RJ Garcia
2de3e27f10
Initial inferred Closure Returns (#2945)
- Added detection for when we can infer
  closure types from parent fn return types
- Implemented functionality for infering types of
  returned closures
- Added ability to infer type of return from typed
  closures
- Added a new getFunctionLikeStorage method in
  Codebase to support easily getting a function
  despite being a method, closure, or function
- Added some utilities to the MethodIdentifier
  to facilitate creating MethodIdentifier's from
  string method references

Closes #2896

Signed-off-by: RJ Garcia <rj@bighead.net>
2020-03-14 14:51:43 -04:00
Matthew Brown
c0c878cc9d Don’t cache all traits 2020-03-02 22:27:54 -05:00
Matthew Brown
653353709a Use MethodIdentifier object instead of string 2020-02-14 20:54:26 -05:00
Matthew Brown
bd7f342491 Add constant definitions 2020-01-08 23:48:42 -05:00
Matthew Brown
9fa2db1b6c Move Union::getTypes to Union::getAtomicTypes 2020-01-04 12:20:26 -05:00
Brown
fb48db9163 Remove unused property 2020-01-03 13:10:24 -05:00
Matthew Brown
55c2f7faa2 Fix #2508 - don’t replace templated types with generic ones inside own function 2019-12-28 18:38:02 -05:00
Brown
0bcb7863f3 Use better system for storing inferred types and assertions 2019-11-25 11:44:54 -05:00
Matthew Brown
94d4b876ba Fix #2177 - mark variables in try block as potentially undefined 2019-11-09 12:25:30 -05:00
Brown
3cf16c8ef3 Add back arg 2019-11-07 09:56:27 -05:00
Brown
4f9cf54005 Use unaliased name for external hook 2019-11-04 10:13:12 -05:00
Brown
23fcbec584 Add a few more list types 2019-10-08 19:06:16 -04:00
Matthew Brown
0b4981f01b Fix #1551 - do better at inferring class constant types 2019-09-14 14:26:31 -04:00
Matthew Brown
2a5e0d8f39 Fix #1444 - track unused suppressions 2019-08-18 14:27:50 -04:00
Matthew Brown
b2c0993cdc Add framework for taint analysis to Psalm
Ref #611
2019-08-04 10:37:36 -04:00
Brown
f9d99498a6 Remove unused var 2019-07-31 17:30:31 -04:00
Matthew Brown
2f400381a5 Fix #1973 - bust method mutation cache when reloading language server 2019-07-28 10:05:51 -04:00
2e3s
f15cc7dd5b Mark private properties unused when referenced only in constructor (#1962)
* Mark private properties unused when referenced only in constructor

If a private property is used only in constructor then most likely
it's a dead code since there is no need to have the class property.
But such static properties can be accessed between the calls.

* Ignore the private property issue on alter

* Fix the related dead code psalm

* Add a missing condition into the test
2019-07-21 23:29:16 -04:00
Matthew Brown
8d63d5dc4e Add lookup for builtin functions 2019-07-18 23:30:44 -04:00
Matthew Brown
5583ae842e Refactor signature selection a little 2019-07-18 23:08:54 -04:00
Matthew Brown
74e1b521a5 Add support for completing builtin class names
Fixes #1863
2019-07-17 22:50:57 -04:00
Matthew Brown
da42be175f Apply PHPCS fixes
Fixes #1880
2019-07-05 16:27:53 -04:00
Tyson Andre
af52ad245a Remove unused variables (#1898) 2019-07-04 15:17:28 -04:00
Matthew Brown
df3d7e1d2c Make line endings mostly all the same 2019-07-03 16:58:27 -04:00
Brown
5c76b3c82d Fix #1888 - add go-to-variable 2019-07-01 18:48:33 -04:00
Brown
2e1493be73 Pop open signature help when filling in function in VS Code 2019-07-01 17:50:00 -04:00
Ilija Tovilo
67c3726254 Implement signature help - closes #1841 (#1862)
* Implement signature help - closes #1841

* Add explicit signature count

* [LSP] Do analysis for every signatureHelp request

See here: https://github.com/vimeo/psalm/pull/1862#issuecomment-507007346

* Don’t language server information when checking property for init

* Fix signature help for functions

* Add try-catch around signature help Functions::getStorage()
2019-07-01 15:54:32 -04:00
Matthew Brown
36e2ea6881 Fix #1822 - update use statements with classes 2019-06-30 11:12:50 -04:00
Matthew Brown
ca53019d6b Simplify class completion lookup
Ref #1822
2019-06-29 21:32:26 -04:00
LeSuisse
f29826b958 Fully qualify constants and function calls (#1849)
This should give a small performance boost.
Part of #1837.

The change is enforced via phpcs and can be autofixed
with phpcbf.
2019-06-26 16:52:29 -04:00
Ilija Tovilo
16768e363c Jump between parens when autocompleting method with parameters (#1839) 2019-06-24 07:51:12 -04:00
Ilija Tovilo
78588ced16 Only add newlines to function signature on hover (#1834)
Most editors do not render the newlines for autocompletions which makes
things look worse.
2019-06-22 15:59:16 -04:00
Brown
aa6677a177 Add autocompletion for some classes
Ref #1822
2019-06-21 17:10:35 -04:00
Ilija Tovilo
c74e196e3c Improve autocompletion by using CompletionItem::$detail for type info (#1831) 2019-06-21 17:09:01 -04:00
Josh Di Fabio
bbe5773fa1 LS Completion: Improve filtering
Set `filterText` to member name so that visibility
and 'function' are not used by the IDE when filtering
completion items as the user types.
2019-06-13 21:06:08 -04:00
Josh Di Fabio
cb864206a2 LS Completion: Sort items by visibility first 2019-06-13 21:06:08 -04:00
Josh Di Fabio
ca19353645 Fix bad array_merge logic 2019-06-13 21:06:08 -04:00
Josh Di Fabio
eab4adc6e1 LS Completion: Do not suggest static members when gap is -> 2019-06-13 21:06:08 -04:00
Brown
0ba535d179 Fix problem locating end of completion area 2019-06-12 13:43:35 -04:00
Josh Di Fabio
3db32f2274 Enable LS completion when whitespace follows known type
This change enables completion when there is whitespace following
a known type and an object access operator, e.g.:
    $foo
        ->bar()
        ->baz();
2019-06-12 09:17:50 -04:00
Brown
f309c755f8 Add ability to move classes 2019-06-05 08:50:24 -04:00
Matthew Brown
a9809ab28a Add property moving & renaming 2019-06-04 00:32:19 -04:00
Matthew Brown
2439a9f6a0 Allow instance method renaming, too 2019-06-02 12:02:39 -04:00
Matthew Brown
cc89b9254d Add initial ideas for moving static methods
Ref #1595
2019-06-01 00:56:54 -04:00
Ilija Tovilo
5a14e4b1cf Progress bar (#1709)
* Revert "Revert "Implement better progress""

This reverts commit 4302596654.

* Revert "Revert "Implement dots progress bar""

This reverts commit e41733d789.

* Revert "Revert "Switch to VoidProgress by default""

This reverts commit 304ffeb0a3.

* Revert "Revert "Pass success flag to progress""

This reverts commit 62a690ee4e.

* Improve socket communication

* Use an underscore

* Add means to disable progress

* Add extra newline before progress bar
2019-05-30 10:30:41 -04:00
Matthew Brown
4302596654 Revert "Implement better progress"
This reverts commit 042070d0fd.
2019-05-27 13:07:02 -04:00
Matthew Brown
304ffeb0a3 Revert "Switch to VoidProgress by default"
This reverts commit 63b46be361.
2019-05-27 13:04:38 -04:00
Ilija Tovilo
63b46be361 Switch to VoidProgress by default 2019-05-26 23:18:48 -04:00
Ilija Tovilo
042070d0fd Implement better progress 2019-05-26 23:18:48 -04:00
Brown
963d5bb901 Fix #1656 - allow chained call completion 2019-05-17 12:38:29 -04:00
Brown
a1c9ad501b Fix #1654 - understand templated completions 2019-05-17 12:11:27 -04:00
Josh Di Fabio
92ef851b9c LanguageServer: Handle late completion requests
Currently, Psalm Language Server is only able to handle completion
requests where the gap between a recent known type and the current
cursor position is exactly '->' or '::'. However, VS code often doesn't
send a completion request until an additional, third character has
been typed. This change allows Psalm to successfully serve
completion requests where an additional character has been typed.
2019-05-17 11:28:20 -04:00
Matthew Brown
a34692fca0 Prevent crash when a class definition cannot be located 2019-05-14 23:49:15 -04:00
Ilija Tovilo
2c36a10ac8 Fix #1622 - add allow-backwards-incompatible-changes flag to psalter
The flag prevents psalter from adding native return types
2019-05-13 17:59:31 -04:00
Brown
fea9faaec5 Allow psalter to be used in multithreaded mode 2019-04-17 13:15:06 -04:00
Matthew Brown
01f005290e Allow file path to be passed into methodExists 2019-04-17 00:17:49 -04:00
Brown
ff14f671b1 Add hopefully-more-portable method for evaluating method/property usage 2019-04-16 16:07:48 -04:00