├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .vscode ├── extensions.json └── launch.json ├── .vscodeignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── Screenshot.png ├── jsconfig.json ├── logo.png ├── package-lock.json ├── package.json ├── src ├── cache.js ├── cache.spec.js ├── commands.js ├── extension.js ├── functionGroupsFacade.js ├── hints.js ├── middlewares.js ├── parameterExtractor.js ├── parser.js ├── parser.spec.js ├── pipeline.js ├── pipeline.spec.js ├── printer.js ├── providers │ ├── hover.js │ ├── regex.js │ ├── regex.spec.js │ └── signature.js ├── update.js ├── utils.js └── utils.spec.js ├── test ├── commands.test.js ├── examples │ ├── User.php │ ├── collapseHintsWhenEqual.php │ ├── collapseTypeWhenEqual.php │ ├── general.php │ ├── middlewares.php │ ├── providers.php │ ├── showDollarSign.php │ └── showFullType.php ├── functionGroupsFacade.test.js ├── hints.test.js ├── index.js ├── middlewares.test.js ├── parameterExtractor.test.js ├── providers.test.js ├── runTest.js ├── update.test.js └── utils.js └── webpack.config.js /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["plugin:chai-friendly/recommended"], 3 | "env": { 4 | "browser": false, 5 | "commonjs": true, 6 | "es6": true, 7 | "node": true, 8 | "mocha": true 9 | }, 10 | "parserOptions": { 11 | "ecmaVersion": 2019, 12 | "sourceType": "module" 13 | }, 14 | "rules": { 15 | "no-const-assign": "warn", 16 | "no-this-before-super": "warn", 17 | "no-undef": "error", 18 | "no-unreachable": "warn", 19 | "no-unused-vars": "warn", 20 | "constructor-super": "warn", 21 | "valid-typeof": "warn", 22 | "no-await-in-loop": "off", 23 | "no-restricted-syntax": "off" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | #VS Code 107 | .vscode-test/ 108 | *.vsix 109 | .DS_STORE 110 | .history/ 111 | .vscode/settings.json 112 | .vscode/snipsnap.code-snippets 113 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dbaeumer.vscode-eslint" 6 | ] 7 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that launches the extension inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": ["--extensionDevelopmentPath=${workspaceFolder}"], 14 | "outFiles": ["${workspaceFolder}/dist/**/*.js"], 15 | "preLaunchTask": "npm: webpack" 16 | }, 17 | { 18 | "name": "Extension Tests", 19 | "type": "extensionHost", 20 | "request": "launch", 21 | "runtimeExecutable": "${execPath}", 22 | "args": [ 23 | "--extensionDevelopmentPath=${workspaceFolder}", 24 | "--extensionTestsPath=${workspaceFolder}/test/index" 25 | ] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | test/** 4 | .gitignore 5 | vsc-extension-quickstart.md 6 | **/jsconfig.json 7 | **/*.map 8 | **/.eslintrc.json 9 | .history/** 10 | src/** 11 | node_modules/** 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## 2.0.0 4 | 5 | - Fixes [#21](https://github.com/mrchetan/phpstorm-parameter-hints-in-vscode/issues/21) - Bug on single line selection 6 | 7 | ## 1.4.0 8 | 9 | - Update Dependencies to latest versions 10 | - modify keybindings for PHP files 11 | 12 | ## 1.3.0 13 | 14 | - Update Dependencies to latest versions 15 | - Change some of default settings 16 | 17 | ## 1.2.1 18 | 19 | - 1.83.1 VsCode Extension API 20 | 21 | ## 1.2.0 22 | 23 | - Update Dependencies to latest versions 24 | 25 | ## 1.1.0 26 | 27 | - Update Dependencies to latest versions 28 | 29 | ## 1.0.0 30 | 31 | - Initial release and fixes. 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP Parameter Hint for Visual Studio Code 2 | 3 | [![VS Marketplace Version](https://vsmarketplacebadges.dev/version/MrChetan.phpstorm-parameter-hints-in-vscode.png?color=blue&style=?style=for-the-badge&logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=MrChetan.phpstorm-parameter-hints-in-vscode) 4 | [![Installs](https://vsmarketplacebadges.dev/installs-short/MrChetan.phpstorm-parameter-hints-in-vscode.png?color=blue&style=flat-square)](https://marketplace.visualstudio.com/items?itemName=MrChetan.phpstorm-parameter-hints-in-vscode) 5 | [![Rating](https://vsmarketplacebadges.dev/rating/MrChetan.phpstorm-parameter-hints-in-vscode.png?color=blue&style=flat-square)](https://marketplace.visualstudio.com/items?itemName=MrChetan.phpstorm-parameter-hints-in-vscode) 6 | 7 | ![PhpStorm Parameter Hints in VScode Screenshot](./Screenshot.png) 8 | 9 | Inserts parameter hints(type, name or both) into function calls to easily understand the parameter role. 10 | 11 | 12 | # Installation 13 | 14 | - Open VS Code and click on Extensions Icon in the Activity Bar. 15 | - Type **mrchetan.phpstorm-parameter-hints-in-vscode** 16 | - Install the Extension Pack. 17 | --- 18 | 19 | ## Settings 20 | 21 | | Name | Description | Default | 22 | | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | 23 | | `phpParameterHint.enabled` | Enable PHP Parameter Hint | true | 24 | | `phpParameterHint.margin` | Hints styling of margin CSS property | 2 | 25 | | `phpParameterHint.verticalPadding` | Top and bottom padding of the hints(px) | 1 | 26 | | `phpParameterHint.horizontalPadding` | Right and left padding of the hints(px) | 4 | 27 | | `phpParameterHint.fontWeight` | Hints styling of font-weight CSS property | "400" | 28 | | `phpParameterHint.borderRadius` | Hints styling of border-radius CSS property in px | 5 | 29 | | `phpParameterHint.opacity` | Hints styling of opacity CSS property | 0.4 | 30 | | `phpParameterHint.fontStyle` | Hints styling of font-style CSS property | "italic" | 31 | | `phpParameterHint.fontSize` | Hints styling of font size CSS property | 12 | 32 | | `phpParameterHint.onSave` | Create parameter hints on document save | true | 33 | | `phpParameterHint.saveDelay` | Delay in ms for on document save run | 250 | 34 | | `phpParameterHint.onChange` | Create parameter hints on document change | true | 35 | | `phpParameterHint.changeDelay` | Delay in ms for on document change run | 100 | 36 | | `phpParameterHint.textEditorChangeDelay` | Delay in ms for on active text editor change | 250 | 37 | | `phpParameterHint.php7` | True if php version is 7.0+, false otherwise | true | 38 | | `phpParameterHint.collapseHintsWhenEqual` | Collapse hint when variable name is the same as parameter name, keep the hint if the argument is passed by reference or if the splat operator is used | true | 39 | | `phpParameterHint.collapseTypeWhenEqual` | Collapse type when it is equal to the variable name | true | 40 | | `phpParameterHint.showFullType` | Show full type, including namespaces instead of the short name | false | 41 | | `phpParameterHint.hintOnlyLiterals` | Show hints only for literals | false | 42 | | `phpParameterHint.hintOnlyLine` | Show hints only for current line/selection | true | 43 | | `phpParameterHint.hintOnlyVisibleRanges` | Show hints only for visible ranges | false | 44 | | `phpParameterHint.hintTypeName` | Hint only name(0 - default) / Hint type and name(1) / Hint type(2) | 0 | 45 | | `phpParameterHint.showDollarSign` | Show dollar sign in front of parameter name | false | 46 | 47 | ## Commands 48 | 49 | | Name | Description | SHORTCUT | 50 | | -------------------------------------- | ----------------------------------------------------------- | ------------------------------- | 51 | | `phpParameterHint.toggle` | Hide / Show Hints | Key: CTRL + K H, Mac: CMD + K H | 52 | | `phpParameterHint.toggleOnChange` | Hide / Show Hints on text change | Key: CTRL + K O, Mac: CMD + K O | 53 | | `phpParameterHint.toggleOnSave` | Hide / Show Hints on document save | Key: CTRL + K S, Mac: CMD + K S | 54 | | `phpParameterHint.toggleLiterals` | Hide / Show Hints only for literals | Key: CTRL + K L, Mac: CMD + K L | 55 | | `phpParameterHint.toggleLine` | Hide / Show Hints only for current line/selection | Key: CTRL + K I, Mac: CMD + K I | 56 | | `phpParameterHint.toggleCollapse` | Hide / Show Hints when variable name matches parameter name | Key: CTRL + K C, Mac: CMD + K C | 57 | | `phpParameterHint.toggleTypeName` | Hint name(default), type and name or only type | Key: CTRL + K T, Mac: CMD + K T | 58 | | `phpParameterHint.toggleCollapseType` | Toggle collapsing type and name when they are equal | Key: CTRL + K Y, Mac: CMD + K Y | 59 | | `phpParameterHint.toggleFullType` | Hide / Show full type name(namespaces including) | Key: CTRL + K U, Mac: CMD + K U | 60 | | `phpParameterHint.toggleVisibleRanges` | Hide / Show Hints only in visible ranges | Key: CTRL + K R, Mac: CMD + K R | 61 | | `phpParameterHint.toggleDollarSign` | Hide / Show dollar sign in front of parameter name | Key: CTRL + K D, Mac: CMD + K D | 62 | 63 | ## Colors 64 | 65 | You can change the default foreground and background colors in the `workbench.colorCustomizations` property in user settings. 66 | 67 | | Name | Description | 68 | | --------------------------------- | ------------------------------------------- | 69 | | `phpParameterHint.hintForeground` | Specifies the foreground color for the hint | 70 | | `phpParameterHint.hintBackground` | Specifies the background color for the hint | 71 | 72 | 73 | **Enjoy Chetan's Extension Pack!** 74 | 75 | [Contact Mr Chetan](https://mrchetan.com/) 76 | -------------------------------------------------------------------------------- /Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrchetan/phpstorm-parameter-hints-in-vscode/7c34ff9608968e1c2cc49c8150e79db79953044e/Screenshot.png -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es2018", 5 | "checkJs": true /* Typecheck .js files. */, 6 | "lib": ["es6"] 7 | }, 8 | "exclude": ["node_modules"] 9 | } 10 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrchetan/phpstorm-parameter-hints-in-vscode/7c34ff9608968e1c2cc49c8150e79db79953044e/logo.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phpstorm-parameter-hints-in-vscode", 3 | "displayName": "PhpStorm Parameter Hints in VScode", 4 | "description": "PhpStorm parameter hint for VS Code", 5 | "version": "2.0.0", 6 | "publisher": "MrChetan", 7 | "engines": { 8 | "vscode": "^1.93.0" 9 | }, 10 | "sponsor": { 11 | "url": "https://github.com/sponsors/mr-chetan" 12 | }, 13 | "license": "MIT", 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/mrchetan/phpstorm-parameter-hints-in-vscode" 17 | }, 18 | "homepage": "https://github.com/mrchetan/phpstorm-parameter-hints-in-vscode", 19 | "bugs": { 20 | "url": "https://github.com/mrchetan/phpstorm-parameter-hints-in-vscode/issues" 21 | }, 22 | "icon": "logo.png", 23 | "categories": [ 24 | "Programming Languages", 25 | "Visualization", 26 | "Linters", 27 | "Education", 28 | "Other" 29 | ], 30 | "keywords": [ 31 | "PHP", 32 | "Language", 33 | "references", 34 | "parameter", 35 | "symbols", 36 | "PHP Extension", 37 | "PHPStorm", 38 | "PHPStorm Extension", 39 | "PHPStorm Parameter Hints", 40 | "PHPStorm Parameter Hints in VScode", 41 | "Parameter Hints in VS Code", 42 | "Parameter Hints", 43 | "parameter hint", 44 | "PHP parameter hint", 45 | "PHP parameter hints" 46 | ], 47 | "activationEvents": [ 48 | "onLanguage:php" 49 | ], 50 | "main": "./dist/extension.js", 51 | "contributes": { 52 | "commands": [ 53 | { 54 | "command": "phpParameterHint.toggle", 55 | "title": "PHP Parameter Hint: Hide / Show Hints" 56 | }, 57 | { 58 | "command": "phpParameterHint.toggleOnChange", 59 | "title": "PHP Parameter Hint: Hide / Show Hints on text change" 60 | }, 61 | { 62 | "command": "phpParameterHint.toggleOnSave", 63 | "title": "PHP Parameter Hint: Hide / Show Hints on document save" 64 | }, 65 | { 66 | "command": "phpParameterHint.toggleTypeName", 67 | "title": "PHP Parameter Hint: Hint name(default), type and name or only type" 68 | }, 69 | { 70 | "command": "phpParameterHint.toggleLiterals", 71 | "title": "PHP Parameter Hint: Hide / Show Hints only for literals" 72 | }, 73 | { 74 | "command": "phpParameterHint.toggleLine", 75 | "title": "PHP Parameter Hint: Hide / Show Hints only for current line" 76 | }, 77 | { 78 | "command": "phpParameterHint.toggleCollapse", 79 | "title": "PHP Parameter Hint: Hide / Show Hints when variable name matches parameter name" 80 | }, 81 | { 82 | "command": "phpParameterHint.toggleCollapseType", 83 | "title": "PHP Parameter Hint: Toggle collapsing type with parameter name when they are equal" 84 | }, 85 | { 86 | "command": "phpParameterHint.toggleFullType", 87 | "title": "PHP Parameter Hint: Toggle showing full type instead of short name" 88 | }, 89 | { 90 | "command": "phpParameterHint.toggleVisibleRanges", 91 | "title": "PHP Parameter Hint: Hide / Show Hints only in visible ranges" 92 | }, 93 | { 94 | "command": "phpParameterHint.toggleDollarSign", 95 | "title": "PHP Parameter Hint: Hide / Show dollar sign for parameter name" 96 | } 97 | ], 98 | "configuration": [ 99 | { 100 | "title": "PHP Parameter Hint", 101 | "properties": { 102 | "phpParameterHint.enabled": { 103 | "type": "boolean", 104 | "description": "Enable PHP Parameter Hint", 105 | "default": true 106 | }, 107 | "phpParameterHint.onSave": { 108 | "type": "boolean", 109 | "description": "Create parameter hints on document save", 110 | "default": true 111 | }, 112 | "phpParameterHint.saveDelay": { 113 | "type": "integer", 114 | "description": "Delay in ms for on document save run", 115 | "default": 250 116 | }, 117 | "phpParameterHint.onChange": { 118 | "type": "boolean", 119 | "description": "Create parameter hints on document change", 120 | "default": true 121 | }, 122 | "phpParameterHint.changeDelay": { 123 | "type": "integer", 124 | "description": "Delay in ms for on document change run", 125 | "default": 100 126 | }, 127 | "phpParameterHint.textEditorChangeDelay": { 128 | "type": "integer", 129 | "description": "Delay in ms for on active text editor change", 130 | "default": 250 131 | }, 132 | "phpParameterHint.collapseHintsWhenEqual": { 133 | "type": "boolean", 134 | "description": "Collapse hint when variable name is the same as parameter name, keep the hint if the argument is passed by reference or if the splat operator is used", 135 | "default": true 136 | }, 137 | "phpParameterHint.collapseTypeWhenEqual": { 138 | "type": "boolean", 139 | "description": "Collapse type when it is equal to the variable name", 140 | "default": true 141 | }, 142 | "phpParameterHint.showFullType": { 143 | "type": "boolean", 144 | "description": "Show full type, including namespaces instead of the short name", 145 | "default": false 146 | }, 147 | "phpParameterHint.hintOnlyLiterals": { 148 | "type": "boolean", 149 | "description": "Show hints only for literals", 150 | "default": false 151 | }, 152 | "phpParameterHint.hintTypeName": { 153 | "type": "number", 154 | "description": "Hint only name(0 - default) / Hint type and name(1) / Hint type(2)", 155 | "default": 0 156 | }, 157 | "phpParameterHint.hintOnlyLine": { 158 | "type": "boolean", 159 | "description": "Show hints only for current line", 160 | "default": true 161 | }, 162 | "phpParameterHint.hintOnlyVisibleRanges": { 163 | "type": "boolean", 164 | "description": "Show hints only for visibleRanges", 165 | "default": false 166 | }, 167 | "phpParameterHint.showDollarSign": { 168 | "type": "boolean", 169 | "description": "Show dollar sign for parameter name", 170 | "default": false 171 | }, 172 | "phpParameterHint.php7": { 173 | "type": "boolean", 174 | "description": "True if php version is 7.0+, false otherwise", 175 | "default": true 176 | }, 177 | "phpParameterHint.opacity": { 178 | "type": "number", 179 | "default": 0.4 180 | }, 181 | "phpParameterHint.borderRadius": { 182 | "type": "number", 183 | "default": 5 184 | }, 185 | "phpParameterHint.fontWeight": { 186 | "type": "number", 187 | "default": 400, 188 | "enum": [ 189 | 100, 190 | 200, 191 | 300, 192 | 400, 193 | 500, 194 | 600, 195 | 700, 196 | 800, 197 | 900 198 | ], 199 | "description": "Hints styling of font-weight CSS property" 200 | }, 201 | "phpParameterHint.fontStyle": { 202 | "type": "string", 203 | "default": "italic", 204 | "enum": [ 205 | "normal", 206 | "italic" 207 | ], 208 | "description": "Hints styling of font-style CSS property" 209 | }, 210 | "phpParameterHint.margin": { 211 | "type": "number", 212 | "default": 2, 213 | "description": "Hints styling of margin CSS property" 214 | }, 215 | "phpParameterHint.verticalPadding": { 216 | "type": "number", 217 | "default": 1, 218 | "description": "Top and bottom padding of the hints" 219 | }, 220 | "phpParameterHint.horizontalPadding": { 221 | "type": "number", 222 | "default": 4, 223 | "description": "Right and left padding of the hints" 224 | }, 225 | "phpParameterHint.fontSize": { 226 | "type": "number", 227 | "default": 12, 228 | "description": "Hints styling of font size CSS property" 229 | } 230 | } 231 | } 232 | ], 233 | "colors": [ 234 | { 235 | "id": "phpParameterHint.hintForeground", 236 | "description": "Specifies the foreground color for the hints", 237 | "defaults": { 238 | "dark": "#8D9BD6", 239 | "light": "#1a0000", 240 | "highContrast": "#8D9BD6" 241 | } 242 | }, 243 | { 244 | "id": "phpParameterHint.hintBackground", 245 | "description": "Specifies the background color for the hints", 246 | "defaults": { 247 | "dark": "#292D3E", 248 | "light": "#FFFFFF", 249 | "highContrast": "#292D3E" 250 | } 251 | } 252 | ], 253 | "keybindings": [ 254 | { 255 | "command": "phpParameterHint.toggle", 256 | "key": "ctrl+k h", 257 | "mac": "cmd+k h", 258 | "when": "editorFocus && resourceExtname == .php" 259 | }, 260 | { 261 | "command": "phpParameterHint.toggleOnChange", 262 | "key": "ctrl+k o", 263 | "mac": "cmd+k o", 264 | "when": "editorFocus && resourceExtname == .php" 265 | }, 266 | { 267 | "command": "phpParameterHint.toggleOnSave", 268 | "key": "ctrl+k s", 269 | "mac": "cmd+k s", 270 | "when": "editorFocus && resourceExtname == .php" 271 | }, 272 | { 273 | "command": "phpParameterHint.toggleTypeName", 274 | "key": "ctrl+k t", 275 | "mac": "cmd+k t", 276 | "when": "editorFocus && resourceExtname == .php" 277 | }, 278 | { 279 | "command": "phpParameterHint.toggleLiterals", 280 | "key": "ctrl+k l", 281 | "mac": "cmd+k l", 282 | "when": "editorFocus && resourceExtname == .php" 283 | }, 284 | { 285 | "command": "phpParameterHint.toggleLine", 286 | "key": "ctrl+k i", 287 | "mac": "cmd+k i", 288 | "when": "editorFocus && resourceExtname == .php" 289 | }, 290 | { 291 | "command": "phpParameterHint.toggleCollapse", 292 | "key": "ctrl+k c", 293 | "mac": "cmd+k c", 294 | "when": "editorFocus && resourceExtname == .php" 295 | }, 296 | { 297 | "command": "phpParameterHint.toggleCollapseType", 298 | "key": "ctrl+k y", 299 | "mac": "cmd+k y", 300 | "when": "editorFocus && resourceExtname == .php" 301 | }, 302 | { 303 | "command": "phpParameterHint.toggleFullType", 304 | "key": "ctrl+k u", 305 | "mac": "cmd+k u", 306 | "when": "editorFocus && resourceExtname == .php" 307 | }, 308 | { 309 | "command": "phpParameterHint.toggleVisibleRanges", 310 | "key": "ctrl+k r", 311 | "mac": "cmd+k r", 312 | "when": "editorFocus && resourceExtname == .php" 313 | }, 314 | { 315 | "command": "phpParameterHint.toggleDollarSign", 316 | "key": "ctrl+k d", 317 | "mac": "cmd+k d", 318 | "when": "editorFocus && resourceExtname == .php" 319 | } 320 | ] 321 | }, 322 | "scripts": { 323 | "test": "cross-env NODE_ENV=test mocha 'src/**/*.spec.js'", 324 | "coverage": "nyc --reporter=html npm run test", 325 | "test:vscode": "node test/runTest.js", 326 | "lint": "eslint ./src ./test", 327 | "vscode:prepublish": "webpack --mode production", 328 | "webpack": "webpack --mode development", 329 | "webpack-dev": "webpack --mode development --watch" 330 | }, 331 | "devDependencies": { 332 | "@types/node": "^22.5.4", 333 | "@types/vscode": "^1.93.0", 334 | "chai": "^5.2.0", 335 | "cross-env": "^7.0.3", 336 | "eslint": "^9.26.0", 337 | "eslint-plugin-chai-friendly": "^1.0.1", 338 | "glob": "^11.0.0", 339 | "mocha": "^11.2.2", 340 | "nyc": "^17.0.0", 341 | "sinon": "^20.0.0", 342 | "vscode-test": "^1.6.1", 343 | "webpack": "^5.99.8", 344 | "webpack-cli": "^6.0.1" 345 | }, 346 | "dependencies": { 347 | "fast-copy": "^3.0.2", 348 | "js-coroutines": "^2.4.36", 349 | "lodash.debounce": "^4.0.8", 350 | "lzutf8": "^0.6.3", 351 | "node-cache": "^5.1.2", 352 | "php-parser": "^3.1.5" 353 | }, 354 | "extensionDependencies": [ 355 | "bmewburn.vscode-intelephense-client" 356 | ] 357 | } 358 | -------------------------------------------------------------------------------- /src/cache.js: -------------------------------------------------------------------------------- 1 | const LZUTF8 = require('lzutf8'); 2 | const NodeCache = require('node-cache'); 3 | const { isDefined, getCopyFunc } = require('./utils'); 4 | 5 | const copy = getCopyFunc(); 6 | 7 | /** 8 | * Cache service for functions groups per uri 9 | */ 10 | class CacheService { 11 | constructor(cacheTimeInSecs = 60 * 10, checkIntervalInSecs = 60 * 1) { 12 | this.cacheTimeInSecs = cacheTimeInSecs; 13 | this.cache = new NodeCache({ 14 | stdTTL: cacheTimeInSecs, 15 | checkperiod: checkIntervalInSecs, 16 | useClones: false 17 | }); 18 | } 19 | 20 | // Remove all cached data 21 | removeAll() { 22 | this.cache.flushAll(); 23 | } 24 | 25 | /** 26 | * Cache the function groups per uri 27 | * 28 | * @param {string} uri 29 | * @param {string} text 30 | * @param {array} functionGroups 31 | */ 32 | setFunctionGroups(uri, text, functionGroups) { 33 | return new Promise(resolve => { 34 | LZUTF8.compressAsync(text, undefined, (result, error) => { 35 | if (isDefined(error) || !isDefined(result)) { 36 | // Fail silently without adding the data to cache 37 | resolve(); 38 | return; 39 | } 40 | 41 | const data = { 42 | compressedText: result, 43 | // @ts-ignore 44 | functionGroups: copy(functionGroups) 45 | }; 46 | this.cache.set(uri, data); 47 | resolve(); 48 | }); 49 | }); 50 | } 51 | 52 | /** 53 | * 54 | * @param {string} uri 55 | */ 56 | getFunctionGroups(uri) { 57 | const cachedData = this.cache.get(uri); 58 | 59 | if (isDefined(cachedData) && isDefined(cachedData.functionGroups)) { 60 | // If key exists, refresh TTL 61 | this.cache.ttl(uri, this.cacheTimeInSecs); 62 | // @ts-ignore 63 | return copy(cachedData.functionGroups); 64 | } 65 | 66 | return []; 67 | } 68 | 69 | /** 70 | * 71 | * @param {string} uri 72 | */ 73 | deleteFunctionGroups(uri) { 74 | this.cache.del(uri); 75 | } 76 | 77 | /** 78 | * Check if text from uri is the same as the cached text 79 | * @param {string} uri 80 | * @param {string} text 81 | */ 82 | isCachedTextValid(uri, text) { 83 | return new Promise(resolve => { 84 | if (!this.cache.has(uri)) { 85 | resolve(false); 86 | return; 87 | } 88 | 89 | const { compressedText } = this.cache.get(uri); 90 | 91 | if (!isDefined(compressedText)) { 92 | resolve(false); 93 | return; 94 | } 95 | 96 | LZUTF8.decompressAsync(compressedText, undefined, (cachedText, error) => { 97 | if (isDefined(error) || !isDefined(cachedText)) { 98 | resolve(false); 99 | return; 100 | } 101 | 102 | if (text !== cachedText) { 103 | resolve(false); 104 | return; 105 | } 106 | 107 | resolve(true); 108 | }); 109 | }); 110 | } 111 | } 112 | 113 | module.exports = { 114 | CacheService 115 | }; 116 | -------------------------------------------------------------------------------- /src/cache.spec.js: -------------------------------------------------------------------------------- 1 | const { describe, it } = require('mocha'); 2 | const { expect } = require('chai'); 3 | const sinon = require('sinon'); 4 | const { CacheService } = require('./cache'); 5 | 6 | describe('CacheService', () => { 7 | describe('set, get and delete', () => { 8 | it('should correctly execute all the operations', async () => { 9 | const cacheService = new CacheService(); 10 | const uri = 'uri'; 11 | const text = 'text'; 12 | const functionGroups = [1, 2, 3]; 13 | await cacheService.setFunctionGroups(uri, text, functionGroups); 14 | let retrievedFunctionGroups = cacheService.getFunctionGroups(uri); 15 | // Function groups are deep copied so it's not the same reference 16 | expect(retrievedFunctionGroups).to.not.equal(functionGroups); 17 | expect(retrievedFunctionGroups).to.deep.equal(functionGroups); 18 | cacheService.deleteFunctionGroups(uri); 19 | retrievedFunctionGroups = cacheService.getFunctionGroups(uri); 20 | expect(retrievedFunctionGroups).to.have.lengthOf(0); 21 | }); 22 | }); 23 | describe('TTL expire', () => { 24 | const clock = sinon.useFakeTimers({ 25 | shouldAdvanceTime: true 26 | }); 27 | after(() => { 28 | clock.restore(); 29 | }); 30 | it('should return empty array if TTL has expired', async () => { 31 | const ttlSeconds = 1; 32 | const expireCheckSeconds = 1; 33 | const cacheService = new CacheService(ttlSeconds, expireCheckSeconds); 34 | const uri = 'uri'; 35 | const text = 'text'; 36 | const functionGroups = [1, 2, 3]; 37 | await cacheService.setFunctionGroups(uri, text, functionGroups); 38 | 39 | // wait for cache to be deleted 40 | clock.tick(3000); // sinon uses milliseconds so 3 seconds 41 | const retrievedFunctionGroups = cacheService.getFunctionGroups(uri); 42 | expect(retrievedFunctionGroups).to.have.lengthOf(0); 43 | }); 44 | }); 45 | describe('check valid cached text', () => { 46 | it('should return true only if the text is the same as the cached text', async () => { 47 | const cacheService = new CacheService(); 48 | const uri = 'uri'; 49 | const text = 'text'; 50 | const functionGroups = [1, 2, 3]; 51 | await cacheService.setFunctionGroups(uri, text, functionGroups); 52 | // Successful retrieval 53 | let isValid = await cacheService.isCachedTextValid(uri, text); 54 | expect(isValid).to.be.true; 55 | // With different text 56 | const newText = 'text2'; 57 | isValid = await cacheService.isCachedTextValid(uri, newText); 58 | expect(isValid).to.be.false; 59 | // After cache is deleted 60 | cacheService.deleteFunctionGroups(uri); 61 | isValid = await cacheService.isCachedTextValid(uri, text); 62 | expect(isValid).to.be.false; 63 | }); 64 | }); 65 | describe('remove all cached data', () => { 66 | it('should return all existing cached data', async () => { 67 | const cacheService = new CacheService(); 68 | const uri1 = 'uri1'; 69 | const text1 = 'text1'; 70 | const uri2 = 'uri2'; 71 | const text2 = 'text2'; 72 | const functionGroups = [1, 2, 3]; 73 | await cacheService.setFunctionGroups(uri1, text1, functionGroups); 74 | await cacheService.setFunctionGroups(uri2, text2, functionGroups); 75 | cacheService.removeAll(); 76 | const retrievedFunctionGroups1 = cacheService.getFunctionGroups(uri1); 77 | expect(retrievedFunctionGroups1).to.have.lengthOf(0); 78 | const retrievedFunctionGroups2 = cacheService.getFunctionGroups(uri2); 79 | expect(retrievedFunctionGroups2).to.have.lengthOf(0); 80 | }); 81 | }); 82 | }); 83 | -------------------------------------------------------------------------------- /src/commands.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | 3 | // default = 'disabled' - only name 4 | const showTypeEnum = Object.freeze({ 0: 'disabled', 1: 'type and name', 2: 'type' }); 5 | 6 | class Commands { 7 | static registerCommands() { 8 | const messageHeader = 'PHP Parameter Hint: '; 9 | const hideMessageAfterMs = 3000; 10 | let message; 11 | 12 | // Command to hide / show hints 13 | vscode.commands.registerCommand('phpParameterHint.toggle', async () => { 14 | const currentState = vscode.workspace.getConfiguration('phpParameterHint').get('enabled'); 15 | message = `${messageHeader} Hints ${currentState ? 'disabled' : 'enabled'}`; 16 | 17 | await vscode.workspace 18 | .getConfiguration('phpParameterHint') 19 | .update('enabled', !currentState, true); 20 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 21 | }); 22 | 23 | // Command to toggle hinting on text change 24 | vscode.commands.registerCommand('phpParameterHint.toggleOnChange', async () => { 25 | const currentState = vscode.workspace.getConfiguration('phpParameterHint').get('onChange'); 26 | message = `${messageHeader} Hint on change ${currentState ? 'disabled' : 'enabled'}`; 27 | 28 | await vscode.workspace 29 | .getConfiguration('phpParameterHint') 30 | .update('onChange', !currentState, true); 31 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 32 | }); 33 | 34 | // Command to toggle hinting on document save 35 | vscode.commands.registerCommand('phpParameterHint.toggleOnSave', async () => { 36 | const currentState = vscode.workspace.getConfiguration('phpParameterHint').get('onSave'); 37 | message = `${messageHeader} Hint on save ${currentState ? 'disabled' : 'enabled'}`; 38 | 39 | await vscode.workspace 40 | .getConfiguration('phpParameterHint') 41 | .update('onSave', !currentState, true); 42 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 43 | }); 44 | 45 | // Command to toggle between showing param name, name and type and only type 46 | const showTypeKeys = Object.keys(showTypeEnum).map(key => parseInt(key, 10)); 47 | const minShowType = Math.min(...showTypeKeys); 48 | const maxShowType = Math.max(...showTypeKeys); 49 | vscode.commands.registerCommand('phpParameterHint.toggleTypeName', async () => { 50 | const currentShowState = vscode.workspace 51 | .getConfiguration('phpParameterHint') 52 | .get('hintTypeName'); 53 | const newShowState = currentShowState >= maxShowType ? minShowType : currentShowState + 1; 54 | message = `${messageHeader} Hint both name and type: ${showTypeEnum[newShowState]}`; 55 | 56 | await vscode.workspace 57 | .getConfiguration('phpParameterHint') 58 | .update('hintTypeName', newShowState, true); 59 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 60 | }); 61 | 62 | // Command to enable/disable hinting only literals 63 | vscode.commands.registerCommand('phpParameterHint.toggleLiterals', async () => { 64 | const currentState = vscode.workspace 65 | .getConfiguration('phpParameterHint') 66 | .get('hintOnlyLiterals'); 67 | message = `${messageHeader} Hint only literals ${currentState ? 'disabled' : 'enabled'}`; 68 | 69 | await vscode.workspace 70 | .getConfiguration('phpParameterHint') 71 | .update('hintOnlyLiterals', !currentState, true); 72 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 73 | }); 74 | 75 | // Command to enable/disable hinting only line/selection 76 | vscode.commands.registerCommand('phpParameterHint.toggleLine', async () => { 77 | const currentState = vscode.workspace 78 | .getConfiguration('phpParameterHint') 79 | .get('hintOnlyLine'); 80 | message = `${messageHeader} Hint only line/selection ${ 81 | currentState ? 'disabled' : 'enabled' 82 | }`; 83 | 84 | await vscode.workspace 85 | .getConfiguration('phpParameterHint') 86 | .update('hintOnlyLine', !currentState, true); 87 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 88 | }); 89 | 90 | // Command to enable/disable hinting only visible ranges 91 | vscode.commands.registerCommand('phpParameterHint.toggleVisibleRanges', async () => { 92 | const currentState = vscode.workspace 93 | .getConfiguration('phpParameterHint') 94 | .get('hintOnlyVisibleRanges'); 95 | message = `${messageHeader} Hint only visible ranges ${ 96 | currentState ? 'disabled' : 'enabled' 97 | }`; 98 | 99 | await vscode.workspace 100 | .getConfiguration('phpParameterHint') 101 | .update('hintOnlyVisibleRanges', !currentState, true); 102 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 103 | }); 104 | 105 | // Command to enable/disable collapsing hints when param name is equal to 106 | // variable name 107 | vscode.commands.registerCommand('phpParameterHint.toggleCollapse', async () => { 108 | const currentState = vscode.workspace 109 | .getConfiguration('phpParameterHint') 110 | .get('collapseHintsWhenEqual'); 111 | message = `${messageHeader} Collapse hints ${currentState ? 'disabled' : 'enabled'}`; 112 | 113 | await vscode.workspace 114 | .getConfiguration('phpParameterHint') 115 | .update('collapseHintsWhenEqual', !currentState, true); 116 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 117 | }); 118 | 119 | // Command to enable/disable collapsing type and parameter name when hinting 120 | // types is enabled and they are equal 121 | vscode.commands.registerCommand('phpParameterHint.toggleCollapseType', async () => { 122 | const currentState = vscode.workspace 123 | .getConfiguration('phpParameterHint') 124 | .get('collapseTypeWhenEqual'); 125 | message = `${messageHeader} Collapse type and parameter name ${ 126 | currentState ? 'disabled' : 'enabled' 127 | }`; 128 | 129 | await vscode.workspace 130 | .getConfiguration('phpParameterHint') 131 | .update('collapseTypeWhenEqual', !currentState, true); 132 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 133 | }); 134 | 135 | // Show full type, including namespaces instead of the short name 136 | vscode.commands.registerCommand('phpParameterHint.toggleFullType', async () => { 137 | const currentState = vscode.workspace 138 | .getConfiguration('phpParameterHint') 139 | .get('showFullType'); 140 | message = `${messageHeader} Show full type ${currentState ? 'disabled' : 'enabled'}`; 141 | 142 | await vscode.workspace 143 | .getConfiguration('phpParameterHint') 144 | .update('showFullType', !currentState, true); 145 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 146 | }); 147 | 148 | // Show dollar sign for parameter name 149 | vscode.commands.registerCommand('phpParameterHint.toggleDollarSign', async () => { 150 | const currentState = vscode.workspace 151 | .getConfiguration('phpParameterHint') 152 | .get('showDollarSign'); 153 | message = `${messageHeader} Show dollar sign for parameter name ${ 154 | currentState ? 'disabled' : 'enabled' 155 | }`; 156 | 157 | await vscode.workspace 158 | .getConfiguration('phpParameterHint') 159 | .update('showDollarSign', !currentState, true); 160 | vscode.window.setStatusBarMessage(message, hideMessageAfterMs); 161 | }); 162 | } 163 | } 164 | 165 | module.exports = { Commands, showTypeEnum }; 166 | -------------------------------------------------------------------------------- /src/extension.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const debounce = require('lodash.debounce'); 3 | const { Commands } = require('./commands'); 4 | const { printError } = require('./printer'); 5 | const { update } = require('./update'); 6 | const { onlyLiterals, onlySelection, onlyVisibleRanges } = require('./middlewares'); 7 | const { Pipeline } = require('./pipeline'); 8 | const { CacheService } = require('./cache'); 9 | const { FunctionGroupsFacade } = require('./functionGroupsFacade'); 10 | 11 | const hintDecorationType = vscode.window.createTextEditorDecorationType({}); 12 | const initialNrTries = 3; 13 | 14 | /** 15 | * This method is called when VSCode is activated 16 | * @param {vscode.ExtensionContext} context 17 | */ 18 | function activate(context) { 19 | let timeout; 20 | let activeEditor = vscode.window.activeTextEditor; 21 | const functionGroupsFacade = new FunctionGroupsFacade(new CacheService()); 22 | 23 | /** 24 | * Get the PHP code then parse it and create parameter hints 25 | */ 26 | async function updateDecorations() { 27 | timeout = undefined; 28 | 29 | if (!activeEditor || !activeEditor.document || activeEditor.document.languageId !== 'php') { 30 | return; 31 | } 32 | 33 | const { document: currentDocument } = activeEditor; 34 | const uriStr = currentDocument.uri.toString(); 35 | const isEnabled = vscode.workspace.getConfiguration('phpParameterHint').get('enabled'); 36 | 37 | if (!isEnabled) { 38 | activeEditor.setDecorations(hintDecorationType, []); 39 | 40 | return; 41 | } 42 | 43 | const text = currentDocument.getText(); 44 | let functionGroups = []; 45 | const hintOnChange = vscode.workspace.getConfiguration('phpParameterHint').get('onChange'); 46 | const hintOnlyLine = vscode.workspace.getConfiguration('phpParameterHint').get('hintOnlyLine'); 47 | const hintOnlyLiterals = vscode.workspace 48 | .getConfiguration('phpParameterHint') 49 | .get('hintOnlyLiterals'); 50 | const hintOnlyVisibleRanges = vscode.workspace 51 | .getConfiguration('phpParameterHint') 52 | .get('hintOnlyVisibleRanges'); 53 | 54 | try { 55 | functionGroups = await functionGroupsFacade.get(uriStr, text); 56 | } catch (err) { 57 | printError(err); 58 | 59 | if (hintOnChange || hintOnlyLine) { 60 | return; 61 | } 62 | } 63 | 64 | if (!functionGroups.length) { 65 | activeEditor.setDecorations(hintDecorationType, []); 66 | 67 | return; 68 | } 69 | 70 | const finalFunctionGroups = await new Pipeline() 71 | .pipe( 72 | [onlyLiterals, hintOnlyLiterals], 73 | [onlyVisibleRanges, activeEditor, hintOnlyVisibleRanges], 74 | [onlySelection, activeEditor, hintOnlyLine] 75 | ) 76 | .process(functionGroups); 77 | await update(activeEditor, finalFunctionGroups); 78 | } 79 | 80 | /** 81 | * Trigger updating decorations 82 | * 83 | * @param {number} delay integer 84 | */ 85 | function triggerUpdateDecorations(delay = 1000) { 86 | if (timeout) { 87 | clearTimeout(timeout); 88 | timeout = undefined; 89 | } 90 | 91 | timeout = setTimeout(updateDecorations, delay); 92 | } 93 | 94 | /** 95 | * Try creating hints multiple time on activation, in case intelephense 96 | * extension was not loaded at first 97 | * 98 | * @param {number} numberTries integer 99 | */ 100 | function tryInitial(numberTries) { 101 | if (!numberTries) { 102 | setTimeout(triggerUpdateDecorations, 4000); 103 | 104 | return; 105 | } 106 | 107 | const intelephenseExtension = vscode.extensions.getExtension( 108 | 'bmewburn.vscode-intelephense-client' 109 | ); 110 | 111 | if (!intelephenseExtension || !intelephenseExtension.isActive) { 112 | setTimeout(() => tryInitial(numberTries - 1), 2000); 113 | } else { 114 | setTimeout(triggerUpdateDecorations, 4000); 115 | } 116 | } 117 | 118 | vscode.workspace.onDidChangeConfiguration(event => { 119 | if (event.affectsConfiguration('phpParameterHint')) { 120 | triggerUpdateDecorations(); 121 | } 122 | }); 123 | vscode.window.onDidChangeActiveTextEditor( 124 | editor => { 125 | activeEditor = editor; 126 | if (activeEditor) { 127 | triggerUpdateDecorations( 128 | vscode.workspace.getConfiguration('phpParameterHint').get('textEditorChangeDelay') 129 | ); 130 | } 131 | }, 132 | null, 133 | context.subscriptions 134 | ); 135 | const handleVisibleRangesChange = debounce(() => { 136 | if ( 137 | activeEditor && 138 | vscode.workspace.getConfiguration('phpParameterHint').get('hintOnlyVisibleRanges') 139 | ) { 140 | triggerUpdateDecorations(0); 141 | } 142 | }, 333); 143 | vscode.window.onDidChangeTextEditorVisibleRanges( 144 | handleVisibleRangesChange, 145 | null, 146 | context.subscriptions 147 | ); 148 | vscode.window.onDidChangeTextEditorSelection( 149 | () => { 150 | if ( 151 | activeEditor && 152 | vscode.workspace.getConfiguration('phpParameterHint').get('hintOnlyLine') 153 | ) { 154 | triggerUpdateDecorations(0); 155 | } 156 | }, 157 | null, 158 | context.subscriptions 159 | ); 160 | vscode.workspace.onDidChangeTextDocument( 161 | debounce(event => { 162 | if ( 163 | activeEditor && 164 | event.document === activeEditor.document && 165 | vscode.workspace.getConfiguration('phpParameterHint').get('onChange') 166 | ) { 167 | triggerUpdateDecorations( 168 | vscode.workspace.getConfiguration('phpParameterHint').get('changeDelay') 169 | ); 170 | } 171 | }, 333), 172 | null, 173 | context.subscriptions 174 | ); 175 | vscode.workspace.onDidSaveTextDocument( 176 | document => { 177 | if ( 178 | activeEditor && 179 | activeEditor.document === document && 180 | vscode.workspace.getConfiguration('phpParameterHint').get('onSave') 181 | ) { 182 | triggerUpdateDecorations( 183 | vscode.workspace.getConfiguration('phpParameterHint').get('saveDelay') 184 | ); 185 | } 186 | }, 187 | null, 188 | context.subscriptions 189 | ); 190 | Commands.registerCommands(); 191 | 192 | if (activeEditor) { 193 | tryInitial(initialNrTries); 194 | } 195 | } 196 | 197 | module.exports = { 198 | activate 199 | }; 200 | -------------------------------------------------------------------------------- /src/functionGroupsFacade.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const Parser = require('./parser'); 3 | 4 | class FunctionGroupsFacade { 5 | constructor(cacheService) { 6 | this.cacheService = cacheService; 7 | } 8 | 9 | /** 10 | * @param {string} uri 11 | * @param {string} text 12 | */ 13 | async get(uri, text) { 14 | if (await this.cacheService.isCachedTextValid(uri, text)) { 15 | return this.cacheService.getFunctionGroups(uri); 16 | } 17 | 18 | this.cacheService.deleteFunctionGroups(uri); 19 | const isPhp7 = vscode.workspace.getConfiguration('phpParameterHint').get('php7'); 20 | const parser = new Parser(isPhp7); 21 | parser.parse(text); 22 | const { functionGroups } = parser; 23 | await this.cacheService.setFunctionGroups(uri, text, functionGroups); 24 | return functionGroups; 25 | } 26 | } 27 | 28 | module.exports = { 29 | FunctionGroupsFacade 30 | }; 31 | -------------------------------------------------------------------------------- /src/hints.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line no-unused-vars 2 | const { ThemeColor, workspace, Range } = require('vscode'); 3 | 4 | class Hints { 5 | /** 6 | * 7 | * @param {string} message 8 | * @param {Range} range 9 | */ 10 | static paramHint(message, range) { 11 | const config = workspace.getConfiguration('phpParameterHint'); 12 | 13 | return { 14 | range, 15 | renderOptions: { 16 | before: { 17 | opacity: config.get('opacity'), 18 | color: new ThemeColor('phpParameterHint.hintForeground'), 19 | contentText: message, 20 | backgroundColor: new ThemeColor('phpParameterHint.hintBackground'), 21 | margin: `0px ${config.get('margin') + 1}px 0px ${config.get( 22 | 'margin' 23 | )}px;padding: ${config.get('verticalPadding')}px ${config.get('horizontalPadding')}px;`, 24 | borderRadius: `${config.get('borderRadius')}px`, 25 | fontStyle: config.get('fontStyle'), 26 | fontWeight: `${config.get('fontWeight')};font-size:${config.get('fontSize')}px;` 27 | } 28 | } 29 | }; 30 | } 31 | } 32 | 33 | module.exports = Hints; 34 | -------------------------------------------------------------------------------- /src/middlewares.js: -------------------------------------------------------------------------------- 1 | const { Position, Range } = require('vscode'); 2 | 3 | /* eslint-disable no-param-reassign */ 4 | const literals = [ 5 | 'boolean', 6 | 'number', 7 | 'string', 8 | 'magic', 9 | 'nowdoc', 10 | 'array', 11 | 'null', 12 | 'encapsed', 13 | 'nullkeyword' 14 | ]; 15 | 16 | // Keep only arguments that are literals 17 | const onlyLiterals = (functionGroups, shouldApply) => { 18 | if (!shouldApply) { 19 | return functionGroups; 20 | } 21 | 22 | return functionGroups.filter(functionGroup => { 23 | functionGroup.args = functionGroup.args.filter(arg => literals.includes(arg.kind)); 24 | 25 | return functionGroup.args.length > 0; 26 | }); 27 | }; 28 | 29 | // Keep only arguments in current line/selection 30 | const onlySelection = (functionGroups, activeEditor, shouldApply) => { 31 | if (!shouldApply) { 32 | return functionGroups; 33 | } 34 | 35 | const currentSelection = activeEditor.selection; 36 | if (!currentSelection) { 37 | return functionGroups; 38 | } 39 | 40 | // Use a Set for efficient line lookups 41 | const selectedLines = new Set(); 42 | activeEditor.selections.forEach(selection => { 43 | for (let line = selection.start.line; line <= selection.end.line; line++) { 44 | selectedLines.add(line); 45 | } 46 | }); 47 | 48 | return functionGroups.filter(functionGroup => { 49 | functionGroup.args = functionGroup.args.filter(arg => selectedLines.has(arg.start.line)); 50 | return functionGroup.args.length > 0; 51 | }); 52 | }; 53 | 54 | const onlyVisibleRanges = (functionGroups, activeEditor, shouldApply) => { 55 | if (!shouldApply) { 56 | return functionGroups; 57 | } 58 | 59 | return functionGroups.filter(functionGroup => { 60 | functionGroup.args = functionGroup.args.filter(arg => { 61 | const { visibleRanges } = activeEditor; 62 | 63 | for (const range of visibleRanges) { 64 | const argRange = new Range( 65 | new Position(arg.start.line, arg.start.character), 66 | new Position(arg.end.line, arg.end.character) 67 | ); 68 | 69 | if (range.contains(argRange)) { 70 | return true; 71 | } 72 | } 73 | 74 | return false; 75 | }); 76 | 77 | return functionGroup.args.length > 0; 78 | }); 79 | }; 80 | 81 | module.exports = { onlyLiterals, onlySelection, onlyVisibleRanges }; 82 | -------------------------------------------------------------------------------- /src/parameterExtractor.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const { sameNamePlaceholder, isDefined } = require('./utils'); 3 | const { showTypeEnum } = require('./commands'); 4 | const signature = require('./providers/signature'); 5 | const hover = require('./providers/hover'); 6 | 7 | const isVariadic = label => 8 | label.substr(0, 3) === '...' || label.substr(0, 4) === '&...' || label.substr(0, 4) === '$...'; 9 | 10 | const getVariadic = label => { 11 | if (label.substr(0, 3) === '...') return '...'; 12 | if (label.substr(0, 4) === '&...') return '&...'; 13 | return '$...'; 14 | }; 15 | 16 | const getNameAfterVariadic = label => { 17 | const nameAfterVariadic = 18 | label.substr(0, 3) === '...' ? label.slice(3) : label.replace('...', ''); 19 | 20 | return nameAfterVariadic === '$' ? '' : nameAfterVariadic; 21 | }; 22 | 23 | const filterOnlyTypeLabels = args => 24 | args 25 | .map(label => { 26 | const labels = label.split(' '); 27 | 28 | if (labels.length > 1) { 29 | /** 30 | * Keep the splat operator for rest param even when 31 | * not showing param name to be able to correctly decorate the arguments 32 | */ 33 | return isVariadic(labels[1]) ? `${labels[0]} ${getVariadic(labels[1])}`.trim() : labels[0]; 34 | } 35 | 36 | return ''; 37 | }) 38 | .filter(label => label !== ''); 39 | 40 | const resolveTypeHint = (showTypeState, args, showTypes) => { 41 | const newArgs = args.map(arg => { 42 | // eslint-disable-next-line prefer-const 43 | let [type, label] = arg.split(' '); 44 | 45 | if (!isDefined(label)) { 46 | return type; 47 | } 48 | 49 | let finalType = type; 50 | const showFullType = vscode.workspace.getConfiguration('phpParameterHint').get('showFullType'); 51 | 52 | if (!showFullType) { 53 | /** 54 | * Keep only the short name of the type 55 | * stripping away any namespace 56 | */ 57 | const splittedType = type.split('\\'); 58 | finalType = splittedType[splittedType.length - 1]; 59 | } 60 | 61 | if (type.indexOf('?') === 0 && finalType.indexOf('|null') === -1) { 62 | // If param is optional and this is not already set 63 | finalType = `${finalType}|null`; 64 | } 65 | 66 | finalType = finalType.replace('?', ''); 67 | 68 | if (finalType[0] === '\\') { 69 | finalType = finalType.slice(1); 70 | } 71 | 72 | const collapseTypeWhenEqual = vscode.workspace 73 | .getConfiguration('phpParameterHint') 74 | .get('collapseTypeWhenEqual'); 75 | const cleanLabel = label.slice(1); // without dollar sign 76 | 77 | if (collapseTypeWhenEqual && label[0] === '$' && finalType === cleanLabel) { 78 | return showTypes === 'type' ? `${finalType} ${label}` : `${label}`; 79 | } 80 | 81 | return `${finalType} ${label}`; 82 | }); 83 | 84 | return showTypeState === 'type' ? filterOnlyTypeLabels(newArgs) : newArgs; 85 | }; 86 | 87 | const createHintText = (arg, collapseHintsWhenEqual) => { 88 | if (collapseHintsWhenEqual && arg.name.indexOf('$') === -1) { 89 | if (arg.name === sameNamePlaceholder) { 90 | return null; 91 | } 92 | 93 | return `${arg.name.replace(sameNamePlaceholder, '').trim()}:`; 94 | } 95 | 96 | const showDollarSign = vscode.workspace 97 | .getConfiguration('phpParameterHint') 98 | .get('showDollarSign'); 99 | 100 | return `${arg.name.replace('$', showDollarSign ? '$' : '').replace('& ', '&')}:`; 101 | }; 102 | 103 | /** 104 | * Get the parameter name 105 | * 106 | * @param {Map>} functionDictionary 107 | * @param {Object} functionGroup 108 | * @param {vscode.TextEditor} editor 109 | */ 110 | const getHints = async (functionDictionary, functionGroup, editor) => { 111 | const finalHints = []; 112 | let args = []; 113 | const collapseHintsWhenEqual = vscode.workspace 114 | .getConfiguration('phpParameterHint') 115 | .get('collapseHintsWhenEqual'); 116 | const hintTypeName = vscode.workspace.getConfiguration('phpParameterHint').get('hintTypeName'); 117 | const showTypes = showTypeEnum[hintTypeName]; 118 | 119 | // If parameters group is memoized, simply return it 120 | if (functionGroup.name && functionDictionary.has(functionGroup.name)) { 121 | args = functionDictionary.get(functionGroup.name); 122 | } else { 123 | // First try to get the args from the Signature provider 124 | args = await signature.getArgs( 125 | editor, 126 | functionGroup.args[0].start.line, 127 | functionGroup.args[0].start.character, 128 | showTypes 129 | ); 130 | 131 | if (!args.length) { 132 | // Fallback on Hover provider 133 | args = await hover.getArgs(editor, functionGroup.line, functionGroup.character, showTypes); 134 | } 135 | 136 | if (args.length && showTypes !== 'disabled') { 137 | args = resolveTypeHint(showTypes, args, showTypes); 138 | } 139 | 140 | // Memoise parameters group for this function 141 | if (functionGroup.name && args && args.length) { 142 | functionDictionary.set(functionGroup.name, args); 143 | } 144 | } 145 | 146 | if (args && args.length) { 147 | // Check if there is a rest parameter and return the parameter names in array-like style 148 | let hasRestParameter = false; 149 | let restParameterIndex = -1; 150 | let restParameterName = ''; 151 | let restParameterType = ''; 152 | const argsLength = args.length; 153 | // If there is a rest parameter, set it's details 154 | const setHasRest = (index, name, type = '') => { 155 | hasRestParameter = true; 156 | restParameterIndex = index; 157 | restParameterName = name; 158 | restParameterType = type; 159 | }; 160 | 161 | args = args.map((arg, index) => { 162 | if (showTypes === 'disabled') { 163 | if (isVariadic(arg)) { 164 | setHasRest(index, getNameAfterVariadic(arg)); 165 | 166 | return `${restParameterName}[0]`; 167 | } 168 | } else { 169 | let [type, name] = arg.split(' '); 170 | 171 | if (!isDefined(name)) { 172 | name = type; 173 | type = ''; 174 | } 175 | 176 | if (showTypes === 'type') { 177 | if (isVariadic(name)) { 178 | /** 179 | * If the variadic params are set by reference, 180 | * set it as param name to show the reference on the following params 181 | */ 182 | const reference = name.indexOf('&') === 0 ? '&' : ''; 183 | setHasRest(index, reference, type); 184 | 185 | return `${type ? `${`${type} ${reference}`.trim()}[0]` : ''}`; 186 | } 187 | } else if (isVariadic(name)) { 188 | setHasRest(index, getNameAfterVariadic(name), type); 189 | const argLabel = `${type ? `${type} ` : ''}${restParameterName}`.trim(); 190 | 191 | return `${argLabel}[0]`; 192 | } 193 | } 194 | 195 | return arg; 196 | }); 197 | 198 | args = args.filter(arg => arg !== ''); 199 | let groupArgsCount = 0; 200 | 201 | // Construct the final params hints 202 | for ( 203 | let index = functionGroup.args[0].key; 204 | index < functionGroup.args[functionGroup.args.length - 1].key + 1; 205 | index += 1 206 | ) { 207 | if (index === argsLength && !hasRestParameter) { 208 | break; 209 | } 210 | 211 | const groupArg = functionGroup.args[groupArgsCount]; 212 | const arg = args[index] || ''; 213 | const finalArg = {}; 214 | const groupArgStart = new vscode.Position(groupArg.start.line, groupArg.start.character); 215 | const groupArgEnd = new vscode.Position(groupArg.end.line, groupArg.end.character); 216 | 217 | finalArg.range = new vscode.Range(groupArgStart, groupArgEnd); 218 | finalArg.name = arg; 219 | 220 | // If key is bigger than the arguments length, check if there was a rest 221 | // parameter before and name it appropriately 222 | if (index >= argsLength) { 223 | const argLabel = `${ 224 | showTypes === 'disabled' ? '' : `${restParameterType} ` 225 | }${restParameterName}`.trim(); 226 | finalArg.name = `${argLabel}[${index - restParameterIndex}]`; 227 | } 228 | 229 | /** 230 | * If collapse hints is enabled, 231 | * don't show the parameter name if it matches 232 | * with the variable name 233 | */ 234 | if (collapseHintsWhenEqual && groupArg.name) { 235 | const squareBracketIndex = finalArg.name.indexOf('['); 236 | const whereSquareBracket = 237 | squareBracketIndex === -1 ? finalArg.name.length : squareBracketIndex; 238 | const lastDollarSignIndex = finalArg.name.lastIndexOf('$'); 239 | const firstDollarSignIndex = finalArg.name.indexOf('$'); 240 | 241 | if ( 242 | finalArg.name.substring(lastDollarSignIndex + 1, whereSquareBracket) === groupArg.name 243 | ) { 244 | finalArg.name = 245 | finalArg.name.substring(0, firstDollarSignIndex) + 246 | sameNamePlaceholder + 247 | finalArg.name.substring(whereSquareBracket); 248 | } 249 | } 250 | 251 | groupArgsCount += 1; 252 | const hintText = createHintText(finalArg, collapseHintsWhenEqual); 253 | 254 | if (hintText !== null) { 255 | const hint = { 256 | text: hintText, 257 | range: finalArg.range 258 | }; 259 | finalHints.push(hint); 260 | } 261 | } 262 | 263 | return finalHints; 264 | } 265 | 266 | throw new Error('No arguments'); 267 | }; 268 | 269 | module.exports = getHints; 270 | -------------------------------------------------------------------------------- /src/parser.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-expressions */ 2 | const engine = require('php-parser'); 3 | const { removeShebang } = require('./utils'); 4 | 5 | class Parser { 6 | /** 7 | * Is php 7.0+ 8 | * @param {boolean} isPhp7 9 | */ 10 | constructor(isPhp7 = true) { 11 | this.functionGroups = []; 12 | // @ts-ignore 13 | // eslint-disable-next-line new-cap 14 | this.parser = new engine({ 15 | parser: { 16 | extractDoc: true, 17 | php7: isPhp7 18 | }, 19 | ast: { 20 | withPositions: true, 21 | withSource: true 22 | }, 23 | lexer: { 24 | short_tags: true, 25 | asp_tags: true, 26 | all_tokens: true, 27 | comment_tokens: true 28 | } 29 | }); 30 | } 31 | 32 | /** 33 | * @param {string} text 34 | */ 35 | parse(text) { 36 | this.functionGroups = []; 37 | const astRoot = this.parser.parseCode(removeShebang(text)); 38 | this.crawl(astRoot); 39 | } 40 | 41 | crawl(ast) { 42 | if (['call', 'new'].includes(ast.kind)) { 43 | try { 44 | this.parseArguments(ast); 45 | // eslint-disable-next-line no-empty 46 | } catch (err) {} 47 | } 48 | 49 | try { 50 | // eslint-disable-next-line no-unused-vars 51 | Object.entries(ast).forEach(([_, node]) => { 52 | if (node instanceof Object) { 53 | try { 54 | this.crawl(node); 55 | // eslint-disable-next-line no-empty 56 | } catch (err) {} 57 | } 58 | }); 59 | // eslint-disable-next-line no-empty 60 | } catch (err) {} 61 | } 62 | 63 | parseArguments(obj) { 64 | const expressionLoc = obj.what.offset ? obj.what.offset.loc.start : obj.what.loc.end; 65 | const functionGroup = { 66 | name: '', 67 | args: [], 68 | line: parseInt(expressionLoc.line, 10) - 1, 69 | character: parseInt(expressionLoc.column, 10) 70 | }; 71 | 72 | if (obj.what && obj.what.kind === 'classreference') { 73 | functionGroup.name = obj.what.name; 74 | } 75 | 76 | obj.arguments.forEach((arg, index) => { 77 | let argument = arg; 78 | 79 | while (argument.kind === 'bin' && argument.left) { 80 | argument = argument.left; 81 | } 82 | 83 | const startLoc = argument.loc.start; 84 | const endLoc = argument.loc.end; 85 | let argKind = argument.kind || ''; 86 | 87 | if ( 88 | argument.kind && 89 | argument.kind === 'identifier' && 90 | argument.name.name && 91 | argument.name.name === 'null' 92 | ) { 93 | argKind = 'null'; 94 | } 95 | 96 | functionGroup.args.push({ 97 | key: index, 98 | start: { 99 | line: parseInt(startLoc.line, 10) - 1, 100 | character: parseInt(startLoc.column, 10) 101 | }, 102 | end: { 103 | line: parseInt(endLoc.line, 10) - 1, 104 | character: parseInt(endLoc.column, 10) 105 | }, 106 | name: argument.name || '', 107 | kind: argKind 108 | }); 109 | }); 110 | 111 | if (functionGroup.args.length && obj.what && obj.what.kind !== 'variable') { 112 | this.functionGroups.push(functionGroup); 113 | } 114 | } 115 | } 116 | 117 | module.exports = Parser; 118 | -------------------------------------------------------------------------------- /src/parser.spec.js: -------------------------------------------------------------------------------- 1 | const { describe, it } = require('mocha'); 2 | const { expect } = require('chai'); 3 | const Parser = require('./parser'); 4 | 5 | describe('Parser', () => { 6 | const parser = new Parser(true); 7 | 8 | describe('parse', () => {}); 9 | it('should correctly parse and store the function groups from text', () => { 10 | // with function groups 11 | const text = ` { 55 | // without function groups 56 | const text = ` { 64 | // with html 65 | const text = ` 66 |

List:

67 | `; 68 | parser.parse(text); 69 | const { functionGroups } = parser; 70 | const expectedFunctionGroups = [ 71 | { 72 | name: '', 73 | args: [ 74 | { 75 | key: 0, 76 | start: { 77 | line: 1, 78 | character: 31 79 | }, 80 | end: { 81 | line: 1, 82 | character: 35 83 | }, 84 | name: '', 85 | kind: 'string' 86 | }, 87 | { 88 | key: 1, 89 | start: { 90 | line: 1, 91 | character: 37 92 | }, 93 | end: { 94 | line: 1, 95 | character: 46 96 | }, 97 | name: '', 98 | kind: 'array' 99 | } 100 | ], 101 | line: 1, 102 | character: 30 103 | } 104 | ]; 105 | expect(functionGroups).to.have.lengthOf(1); 106 | expect(functionGroups).to.deep.equal(expectedFunctionGroups); 107 | }); 108 | it('should save all the function groups from the text', () => { 109 | // with multiple function groups 110 | const text = ` { 189 | const text = ` { 194 | parser.parse(text); 195 | }).to.throw(); 196 | }); 197 | it('should correctly parse the text and save the function groups when php short tags are used', () => { 198 | // with short tags 199 | const text = ` 200 |

Name:

201 |

Age:

202 | `; 203 | parser.parse(text); 204 | const { functionGroups } = parser; 205 | const expectedFunctionGroups = [ 206 | { 207 | name: '', 208 | args: [ 209 | { 210 | key: 0, 211 | start: { 212 | line: 1, 213 | character: 25 214 | }, 215 | end: { 216 | line: 1, 217 | character: 34 218 | }, 219 | name: '', 220 | kind: 'string' 221 | } 222 | ], 223 | line: 1, 224 | character: 24 225 | }, 226 | { 227 | name: '', 228 | args: [ 229 | { 230 | key: 0, 231 | start: { 232 | line: 2, 233 | character: 26 234 | }, 235 | end: { 236 | line: 2, 237 | character: 29 238 | }, 239 | name: '', 240 | kind: 'unary' 241 | } 242 | ], 243 | line: 2, 244 | character: 25 245 | } 246 | ]; 247 | expect(functionGroups).to.have.lengthOf(2); 248 | expect(functionGroups).to.deep.equal(expectedFunctionGroups); 249 | }); 250 | }); 251 | -------------------------------------------------------------------------------- /src/pipeline.js: -------------------------------------------------------------------------------- 1 | const { isDefined } = require('./utils'); 2 | 3 | /** 4 | * Pipeline class used to apply middlewares in a pipe style 5 | */ 6 | class Pipeline { 7 | constructor() { 8 | this.steps = []; 9 | } 10 | 11 | /** 12 | * Each argument can be a function or an array with the step function being 13 | * the first element and the rest of the elements are the additional args that 14 | * will be passed to the function. 15 | * They must be set in the order set by the parameters of the function 16 | * definition, the value being processed by the pipe wil be set as the first 17 | * arg when the function is called. 18 | * 19 | * @param {(Function|(any)[])[]} steps 20 | */ 21 | pipe(...steps) { 22 | steps.forEach(step => { 23 | if (!isDefined(step)) return; 24 | 25 | let finalStep; 26 | 27 | if (Array.isArray(step)) { 28 | finalStep = step; 29 | } else { 30 | finalStep = [step]; 31 | } 32 | 33 | this.steps.push(finalStep); 34 | }); 35 | 36 | return this; 37 | } 38 | 39 | /** 40 | * Clear existing pipes 41 | */ 42 | clear() { 43 | this.steps = []; 44 | return this; 45 | } 46 | 47 | /** 48 | * The value to be processed by the pipeline 49 | * 50 | * @param {any} value 51 | * @param {boolean} clearAfter the pipes after computing the value 52 | */ 53 | async process(value, clearAfter = false) { 54 | let currentValue = value; 55 | for (const [step, ...additionalArgs] of this.steps) { 56 | currentValue = await step(currentValue, ...additionalArgs); 57 | } 58 | 59 | if (clearAfter) { 60 | this.clear(); 61 | } 62 | 63 | return currentValue; 64 | } 65 | } 66 | 67 | module.exports = { 68 | Pipeline 69 | }; 70 | -------------------------------------------------------------------------------- /src/pipeline.spec.js: -------------------------------------------------------------------------------- 1 | const { describe, it } = require('mocha'); 2 | const { expect } = require('chai'); 3 | const { Pipeline } = require('./pipeline'); 4 | 5 | const double = x => x * 2; 6 | 7 | describe('Pipeline', () => { 8 | describe('with pipes', () => { 9 | it('should correctly execute all the pushed functions', async () => { 10 | const addAsync = async (x, toAdd) => x + toAdd; 11 | const negateAsync = x => new Promise(resolve => setTimeout(() => resolve(-x), 1)); 12 | const pipeline = new Pipeline(); 13 | const initial = 1; 14 | const expected = -3; 15 | const result = await pipeline.pipe(double, [addAsync, 1], negateAsync).process(initial); 16 | expect(result).to.equal(expected); 17 | }); 18 | }); 19 | 20 | describe('without pipes', () => { 21 | it('should return the initial result when there are no pipes', async () => { 22 | let pipeline = new Pipeline(); 23 | const initial = 1; 24 | const expected = 1; 25 | let result = await pipeline.process(initial); 26 | expect(result).to.equal(expected); 27 | 28 | pipeline = new Pipeline(); 29 | result = await pipeline.pipe(undefined).process(initial); 30 | expect(result).to.equal(expected); 31 | }); 32 | }); 33 | describe('clear pipes', () => { 34 | it('should remove all existing pipes', async () => { 35 | const pipeline = new Pipeline(); 36 | const initial = 1; 37 | let result = await pipeline 38 | .pipe(double) 39 | .clear() 40 | .process(initial); 41 | expect(result).to.equal(initial); 42 | await pipeline.pipe(double).process(initial, true); 43 | result = await pipeline.process(initial); 44 | expect(result).to.equal(initial); 45 | }); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /src/printer.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | 3 | const channel = vscode.window.createOutputChannel('PHP Parameter Hint'); 4 | 5 | /** 6 | * Print an error 7 | * @param {string} err 8 | */ 9 | const printError = err => { 10 | channel.appendLine(`${new Date().toLocaleString()} Error: ${err}`); 11 | }; 12 | 13 | module.exports = { 14 | printError 15 | }; 16 | -------------------------------------------------------------------------------- /src/providers/hover.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const { printError } = require('../printer'); 3 | const { getDocRegex, getDefRegex } = require('./regex'); 4 | const { isDefined } = require('../utils'); 5 | 6 | const getArgs = async (editor, line, character, showTypes) => { 7 | let argsDef = []; 8 | let args = []; 9 | const regExDoc = getDocRegex(showTypes); 10 | const regExDef = getDefRegex(showTypes); 11 | 12 | try { 13 | const hoverCommand = await vscode.commands.executeCommand( 14 | 'vscode.executeHoverProvider', 15 | editor.document.uri, 16 | new vscode.Position(line, character) 17 | ); 18 | 19 | if (hoverCommand) { 20 | for (const hover of hoverCommand) { 21 | if (args.length) { 22 | break; 23 | } 24 | 25 | for (const content of hover.contents) { 26 | if (args.length) { 27 | break; 28 | } 29 | 30 | const paramMatches = content.value.match(regExDoc); 31 | 32 | if (Array.isArray(paramMatches) && paramMatches.length) { 33 | args = [ 34 | ...new Set( 35 | paramMatches 36 | .map(label => { 37 | if (!isDefined(label)) { 38 | return label; 39 | } 40 | 41 | if (showTypes === 'disabled' && label.split(' ').length > 1) { 42 | return label 43 | .split(' ')[1] 44 | .replace('`', '') 45 | .trim(); 46 | } 47 | 48 | return label.replace('`', '').trim(); 49 | }) 50 | .filter(label => isDefined(label) && label !== '') 51 | ) 52 | ]; 53 | } 54 | 55 | // If no parameters annotations found, try a regEx that takes the 56 | // parameters from the function definition in hover content 57 | if (!argsDef.length) { 58 | argsDef = [...new Set(content.value.match(regExDef))]; 59 | } 60 | } 61 | } 62 | 63 | if (!args || !args.length) { 64 | args = argsDef; 65 | } 66 | } 67 | } catch (err) { 68 | printError(err); 69 | return []; 70 | } 71 | 72 | return args; 73 | }; 74 | 75 | module.exports = { 76 | getArgs 77 | }; 78 | -------------------------------------------------------------------------------- /src/providers/regex.js: -------------------------------------------------------------------------------- 1 | // Regex to extract param name/type from function definition 2 | const regExDef = /(?<=\(.*)((\.\.\.)?(&)?\$[a-zA-Z0-9_]+)(?=.*\))/gims; 3 | 4 | // Capture the types as well 5 | const regExDefWithTypes = /(?<=\([^(]*)([^,]*(\.\.\.)?(&)?\$[a-zA-Z0-9_]+)(?=.*\))/gims; 6 | 7 | // Regex to extract param name/type from function doc 8 | const regExDoc = /(?<=@param_ )(?:.*?)((\.\.\.)?(&)?\$[a-zA-Z0-9_]+)/gims; 9 | // Capture the types as well 10 | const regExDocWithTypes = /(?<=@param_ )(([^$])+(\.\.\.)?($)?\$[a-zA-Z0-9_]+)/gims; 11 | 12 | const getDocRegex = showTypes => { 13 | if (showTypes === 'disabled') { 14 | return regExDoc; 15 | } 16 | 17 | return regExDocWithTypes; 18 | }; 19 | 20 | const getDefRegex = showTypes => { 21 | if (showTypes === 'disabled') { 22 | return regExDef; 23 | } 24 | 25 | return regExDefWithTypes; 26 | }; 27 | 28 | module.exports = { 29 | getDocRegex, 30 | getDefRegex 31 | }; 32 | -------------------------------------------------------------------------------- /src/providers/regex.spec.js: -------------------------------------------------------------------------------- 1 | const { describe, it } = require('mocha'); 2 | const { expect } = require('chai'); 3 | const { getDocRegex, getDefRegex } = require('./regex'); 4 | 5 | describe('regexp for documentation', () => { 6 | describe('with data types included', () => { 7 | const regExDocTypes = getDocRegex('types'); 8 | 9 | it('should extract the type and name', () => { 10 | const extractedTypeAndNameArr = new RegExp(regExDocTypes.source, 'gims').exec( 11 | '@param_ `\\Models\\User $user`' 12 | ); 13 | expect(extractedTypeAndNameArr).to.have.lengthOf(5); 14 | expect(extractedTypeAndNameArr[1]).to.equal('`\\Models\\User $user'); 15 | }); 16 | it('should return the correct representation when the argument is variadic', () => { 17 | const extractedTypeAndNameArr = new RegExp(regExDocTypes.source, 'gims').exec( 18 | '@param_ `int ...$numbers`' 19 | ); 20 | expect(extractedTypeAndNameArr).to.have.lengthOf(5); 21 | expect(extractedTypeAndNameArr[1]).to.equal('`int ...$numbers'); 22 | }); 23 | it('should extract the correct representation when the argument is passed by reference', () => { 24 | const extractedTypeAndNameArr = new RegExp(regExDocTypes.source, 'gims').exec( 25 | '@param_ `string &$glue`' 26 | ); 27 | expect(extractedTypeAndNameArr).to.have.lengthOf(5); 28 | expect(extractedTypeAndNameArr[1]).to.equal('`string &$glue'); 29 | }); 30 | it('should correctly extract all the params when there are multiple', () => { 31 | const extractedTypeAndNameMatchArr = '@param_ `string $glue` \n @param_ `int ...$numbers`'.match( 32 | new RegExp(regExDocTypes.source, 'gims') 33 | ); 34 | expect(extractedTypeAndNameMatchArr).to.have.lengthOf(2); 35 | expect(extractedTypeAndNameMatchArr[0]).to.equal('`string $glue'); 36 | expect(extractedTypeAndNameMatchArr[1]).to.equal('`int ...$numbers'); 37 | }); 38 | }); 39 | describe('without data types', () => { 40 | const regExDoc = getDocRegex('disabled'); 41 | 42 | it('should extract only the parameter name', () => { 43 | const extractedNameArr = new RegExp(regExDoc.source, 'gims').exec('@param_ `string $glue`'); 44 | expect(extractedNameArr).to.have.lengthOf(4); 45 | expect(extractedNameArr[1]).to.equal('$glue'); 46 | }); 47 | it('should extract the correct representation when the argument is variadic', () => { 48 | const extractedNameArr = new RegExp(regExDoc.source, 'gims').exec( 49 | '@param_ `int ...$numbers`' 50 | ); 51 | expect(extractedNameArr).to.have.lengthOf(4); 52 | expect(extractedNameArr[1]).to.equal('...$numbers'); 53 | }); 54 | it('should extract the correct representation when the argument is passed by reference', () => { 55 | const extractedNameArr = new RegExp(regExDoc.source, 'gims').exec('@param_ `User &$user`'); 56 | expect(extractedNameArr).to.have.lengthOf(4); 57 | expect(extractedNameArr[1]).to.equal('&$user'); 58 | }); 59 | it('should correctly extract all the params when there are multiple', () => { 60 | const extractedNameMatchArr = '@param_ `string $glue` \n @param_ `int ...$numbers`'.match( 61 | new RegExp(regExDoc.source, 'gims') 62 | ); 63 | expect(extractedNameMatchArr).to.have.lengthOf(2); 64 | expect(extractedNameMatchArr[0]).to.equal('`string $glue'); 65 | expect(extractedNameMatchArr[1]).to.equal('`int ...$numbers'); 66 | }); 67 | }); 68 | }); 69 | 70 | describe('regexp for function definition', () => { 71 | describe('with data types included', () => { 72 | const regExDefTypes = getDefRegex('types'); 73 | 74 | it('should extract the type and name', () => { 75 | const extractedTypeAndNameArr = 'function join(string $glue = "", array $pieces)'.match( 76 | new RegExp(regExDefTypes.source, 'gims') 77 | ); 78 | expect(extractedTypeAndNameArr).to.have.lengthOf(2); 79 | expect(extractedTypeAndNameArr[0]).to.equal('string $glue'); 80 | expect(extractedTypeAndNameArr[1]).to.equal(' array $pieces'); 81 | }); 82 | it('should return the correct representation when the argument is variadic', () => { 83 | const extractedTypeAndNameArr = 'function join(int ...$numbers)'.match( 84 | new RegExp(regExDefTypes.source, 'gims') 85 | ); 86 | expect(extractedTypeAndNameArr).to.have.lengthOf(1); 87 | expect(extractedTypeAndNameArr[0]).to.equal('int ...$numbers'); 88 | }); 89 | it('should extract the correct representation when the argument is passed by reference and when there are multiple parameters', () => { 90 | const extractedTypeAndNameArr = 'function join(string &$glue = "", array &$pieces)'.match( 91 | new RegExp(regExDefTypes.source, 'gims') 92 | ); 93 | expect(extractedTypeAndNameArr).to.have.lengthOf(2); 94 | expect(extractedTypeAndNameArr[0]).to.equal('string &$glue'); 95 | expect(extractedTypeAndNameArr[1]).to.equal(' array &$pieces'); 96 | }); 97 | }); 98 | 99 | describe('without data types', () => { 100 | const regExDef = getDefRegex('disabled'); 101 | 102 | it('should extract only the parameter name', () => { 103 | const extractedNameArr = 'function join($glue = "", $pieces)'.match( 104 | new RegExp(regExDef.source, 'gims') 105 | ); 106 | expect(extractedNameArr).to.have.lengthOf(2); 107 | expect(extractedNameArr[0]).to.equal('$glue'); 108 | expect(extractedNameArr[1]).to.equal('$pieces'); 109 | }); 110 | it('should extract the correct representation when the argument is variadic', () => { 111 | const extractedNameArr = 'function join(...$numbers)'.match( 112 | new RegExp(regExDef.source, 'gims') 113 | ); 114 | expect(extractedNameArr).to.have.lengthOf(1); 115 | expect(extractedNameArr[0]).to.equal('...$numbers'); 116 | }); 117 | it('should extract the correct representation when the argument is passed by reference', () => { 118 | const extractedNameArr = 'function join(&$glue)'.match(new RegExp(regExDef.source, 'gims')); 119 | expect(extractedNameArr).to.have.lengthOf(1); 120 | expect(extractedNameArr[0]).to.equal('&$glue'); 121 | }); 122 | }); 123 | }); 124 | -------------------------------------------------------------------------------- /src/providers/signature.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const { printError } = require('../printer'); 3 | const { getDocRegex } = require('./regex'); 4 | 5 | const getArgs = async (editor, line, character, showTypes) => { 6 | let signature; 7 | const signatureHelp = await vscode.commands.executeCommand( 8 | 'vscode.executeSignatureHelpProvider', 9 | editor.document.uri, 10 | new vscode.Position(line, character) 11 | ); 12 | 13 | if (signatureHelp) { 14 | [signature] = signatureHelp.signatures; 15 | } 16 | 17 | if (signature && signature.parameters) { 18 | try { 19 | return signature.parameters.map(parameter => { 20 | const regExDoc = getDocRegex(showTypes); 21 | /** 22 | * If there is a phpDoc for the parameter, use it as the doc 23 | * provides more types 24 | */ 25 | if (parameter.documentation && parameter.documentation.value) { 26 | const docLabel = new RegExp(regExDoc.source, 'gims') 27 | .exec(parameter.documentation.value)[1] 28 | .replace('`', '') 29 | .trim(); 30 | 31 | /** 32 | * Doc wrongfully shows variadic param type as array so we remove it 33 | */ 34 | return docLabel.indexOf('[]') !== -1 && docLabel.indexOf('...') !== -1 35 | ? docLabel.replace('[]', '') 36 | : docLabel; 37 | } 38 | 39 | // Fallback to label 40 | const splittedLabel = parameter.label.split(' '); 41 | 42 | if (showTypes === 'disabled') { 43 | return splittedLabel[0]; 44 | } 45 | 46 | /** 47 | * For cases with default param, like: '$glue = ""', 48 | * take only the param name 49 | */ 50 | return splittedLabel[0].indexOf('$') !== -1 51 | ? splittedLabel[0] 52 | : splittedLabel.slice(0, 2).join(' '); 53 | }); 54 | } catch (err) { 55 | printError(err); 56 | return []; 57 | } 58 | } 59 | 60 | return []; 61 | }; 62 | 63 | module.exports = { 64 | getArgs 65 | }; 66 | -------------------------------------------------------------------------------- /src/update.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | // const { singleton } = require('js-coroutines'); 3 | const getHints = require('./parameterExtractor'); 4 | const { printError } = require('./printer'); 5 | const Hints = require('./hints'); 6 | const { pause } = require('./utils'); 7 | 8 | const hintDecorationType = vscode.window.createTextEditorDecorationType({}); 9 | const slowAfterNrParam = 300; 10 | const showParamsOnceEvery = 100; 11 | let runId = 0; 12 | 13 | /** 14 | * The function that creates the new decorations, if the number of arguments 15 | * is bigger than slowAfterNrParam, then the update of the decorations will be 16 | * called once every showParamsOnceEvery 17 | * 18 | * When the function is called, the last call it's interrupted 19 | * 20 | * @param {vscode.TextEditor} activeEditor 21 | * @param {array} functionGroups 22 | */ 23 | async function update(activeEditor, functionGroups) { 24 | runId = Date.now(); 25 | const currentRunId = runId; 26 | const shouldContinue = () => runId === currentRunId; 27 | const argumentsLen = functionGroups.reduce((accumulator, currentGroup) => { 28 | return accumulator + currentGroup.args.length; 29 | }, 0); 30 | let nrArgs = 0; 31 | const phpDecorations = []; 32 | const functionGroupsLen = functionGroups.length; 33 | const functionDictionary = new Map(); 34 | 35 | for (let index = 0; index < functionGroupsLen; index += 1) { 36 | if (!shouldContinue()) { 37 | return null; 38 | } 39 | 40 | const functionGroup = functionGroups[index]; 41 | let hints; 42 | 43 | try { 44 | hints = await getHints(functionDictionary, functionGroup, activeEditor); 45 | } catch (err) { 46 | printError(err); 47 | } 48 | 49 | if (hints && hints.length) { 50 | for (const hint of hints) { 51 | const decorationPHP = Hints.paramHint(hint.text, hint.range); 52 | phpDecorations.push(decorationPHP); 53 | nrArgs += 1; 54 | 55 | if (argumentsLen > slowAfterNrParam) { 56 | if (nrArgs % showParamsOnceEvery === 0) { 57 | activeEditor.setDecorations(hintDecorationType, phpDecorations); 58 | // Continue on next event loop iteration 59 | await pause(10); 60 | 61 | if (!shouldContinue()) { 62 | return null; 63 | } 64 | } 65 | } 66 | } 67 | } 68 | } 69 | 70 | await pause(10); 71 | 72 | if (!shouldContinue()) { 73 | return null; 74 | } 75 | 76 | activeEditor.setDecorations(hintDecorationType, phpDecorations); 77 | return phpDecorations; 78 | } 79 | 80 | module.exports = { 81 | update 82 | }; 83 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | const copy = require('fast-copy'); 2 | 3 | const sameNamePlaceholder = '%'; 4 | 5 | /** 6 | * 7 | * @param {any} value 8 | */ 9 | const isDefined = value => typeof value !== 'undefined'; 10 | 11 | /** 12 | * 13 | * @param {string} code 14 | */ 15 | const removeShebang = code => { 16 | const codeArr = code.split('\n'); 17 | 18 | if (codeArr[0].substr(0, 2) === '#!') { 19 | codeArr[0] = ''; 20 | } 21 | 22 | return codeArr.join('\n'); 23 | }; 24 | 25 | const getCopyFunc = () => { 26 | return copy.default; 27 | }; 28 | 29 | /** 30 | * 31 | * @param {number} time in ms 32 | */ 33 | const pause = (time = 0) => new Promise(resolve => setTimeout(resolve, time)); 34 | 35 | module.exports = { 36 | removeShebang, 37 | sameNamePlaceholder, 38 | isDefined, 39 | getCopyFunc, 40 | pause 41 | }; 42 | -------------------------------------------------------------------------------- /src/utils.spec.js: -------------------------------------------------------------------------------- 1 | const { describe, it } = require('mocha'); 2 | const { expect } = require('chai'); 3 | const { isDefined, removeShebang, getCopyFunc } = require('./utils'); 4 | 5 | describe('isDefined', () => { 6 | it('should return a boolean indicating whether the passed argument is defined', () => { 7 | const hint = 'user:'; 8 | expect(isDefined(undefined)).to.be.false; 9 | expect(isDefined(hint)).to.be.true; 10 | }); 11 | }); 12 | 13 | describe('removeShebang', () => { 14 | it('should remove the shebang if it exists', () => { 15 | const withShebang = { 16 | input: `#!\n { 29 | it('should return the default export only when process.env is not "test"', () => { 30 | expect(() => { 31 | const copy = getCopyFunc(); 32 | const values = [1, 2, 3]; 33 | // @ts-ignore 34 | const clonedValues = copy(values); 35 | expect(values).to.deep.equal(clonedValues); 36 | expect(values).to.not.equal(clonedValues); 37 | }).to.not.throw(); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /test/commands.test.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const path = require('path'); 3 | const { describe, it, before, after } = require('mocha'); 4 | const { expect } = require('chai'); 5 | const { sleep, examplesFolderPath } = require('./utils'); 6 | 7 | describe('commands', () => { 8 | before(async () => { 9 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}general.php`)); 10 | const document = await vscode.workspace.openTextDocument(uri); 11 | await vscode.window.showTextDocument(document); 12 | await sleep(500); // wait for file to be completely functional 13 | }); 14 | after(async () => { 15 | await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); 16 | }); 17 | 18 | describe('toggleTypeName', () => { 19 | after(async () => { 20 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 0, true); 21 | await sleep(1000); 22 | }); 23 | it('should cycle between available options', async () => { 24 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 0, true); 25 | await sleep(1000); 26 | let hintTypeName = vscode.workspace.getConfiguration('phpParameterHint').get('hintTypeName'); 27 | expect(hintTypeName).to.equal(0); 28 | await vscode.commands.executeCommand('phpParameterHint.toggleTypeName'); 29 | await sleep(1000); 30 | hintTypeName = vscode.workspace.getConfiguration('phpParameterHint').get('hintTypeName'); 31 | expect(hintTypeName).to.equal(1); 32 | await vscode.commands.executeCommand('phpParameterHint.toggleTypeName'); 33 | await sleep(1000); 34 | hintTypeName = vscode.workspace.getConfiguration('phpParameterHint').get('hintTypeName'); 35 | expect(hintTypeName).to.equal(2); 36 | await vscode.commands.executeCommand('phpParameterHint.toggleTypeName'); 37 | await sleep(1000); 38 | hintTypeName = vscode.workspace.getConfiguration('phpParameterHint').get('hintTypeName'); 39 | expect(hintTypeName).to.equal(0); 40 | }); 41 | }); 42 | describe('switchable commands', async () => { 43 | const switchableCommandsTable = [ 44 | { 45 | name: 'toggle', 46 | valueName: 'enabled', 47 | default: true 48 | }, 49 | { 50 | name: 'toggleOnChange', 51 | valueName: 'onChange', 52 | default: false 53 | }, 54 | { 55 | name: 'toggleOnSave', 56 | valueName: 'onSave', 57 | default: true 58 | }, 59 | { 60 | name: 'toggleLiterals', 61 | valueName: 'hintOnlyLiterals', 62 | default: false 63 | }, 64 | { 65 | name: 'toggleLine', 66 | valueName: 'hintOnlyLine', 67 | default: false 68 | }, 69 | { 70 | name: 'toggleVisibleRanges', 71 | valueName: 'hintOnlyVisibleRanges', 72 | default: false 73 | }, 74 | { 75 | name: 'toggleCollapse', 76 | valueName: 'collapseHintsWhenEqual', 77 | default: false 78 | }, 79 | { 80 | name: 'toggleCollapseType', 81 | valueName: 'collapseTypeWhenEqual', 82 | default: false 83 | }, 84 | { 85 | name: 'toggleFullType', 86 | valueName: 'showFullType', 87 | default: false 88 | }, 89 | { 90 | name: 'toggleDollarSign', 91 | valueName: 'showDollarSign', 92 | default: false 93 | } 94 | ]; 95 | after(async () => { 96 | for (const command of switchableCommandsTable) { 97 | await vscode.workspace 98 | .getConfiguration('phpParameterHint') 99 | .update(command.valueName, command.default, true); 100 | } 101 | await sleep(1000); 102 | }); 103 | 104 | for (const command of switchableCommandsTable) { 105 | describe(command.name, () => { 106 | it(`should enable/disable ${command.valueName}`, async () => { 107 | await vscode.workspace 108 | .getConfiguration('phpParameterHint') 109 | .update(command.valueName, true, true); 110 | await sleep(1000); 111 | let value = vscode.workspace.getConfiguration('phpParameterHint').get(command.valueName); 112 | expect(value).to.equal(true); 113 | await vscode.commands.executeCommand(`phpParameterHint.${command.name}`); 114 | await sleep(1000); 115 | value = vscode.workspace.getConfiguration('phpParameterHint').get(command.valueName); 116 | expect(value).to.equal(false); 117 | await vscode.commands.executeCommand(`phpParameterHint.${command.name}`); 118 | await sleep(1000); 119 | value = vscode.workspace.getConfiguration('phpParameterHint').get(command.valueName); 120 | expect(value).to.equal(true); 121 | }); 122 | }); 123 | } 124 | }); 125 | }); 126 | -------------------------------------------------------------------------------- /test/examples/User.php: -------------------------------------------------------------------------------- 1 | { 10 | /** @type {vscode.TextEditor} */ 11 | let editor; 12 | 13 | before(async () => { 14 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}general.php`)); 15 | const document = await vscode.workspace.openTextDocument(uri); 16 | editor = await vscode.window.showTextDocument(document); 17 | await sleep(500); // wait for file to be completely functional 18 | }); 19 | after(async () => { 20 | await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); 21 | }); 22 | 23 | describe('get', () => { 24 | it('should return the correct function groups', async () => { 25 | const functionGroupsFacade = new FunctionGroupsFacade(new CacheService()); 26 | const functionGroups = await functionGroupsFacade.get( 27 | editor.document.uri.toString(), 28 | editor.document.getText() 29 | ); 30 | const expectedFunctionGroups = [ 31 | { 32 | name: '', 33 | args: [ 34 | { 35 | key: 0, 36 | start: { 37 | line: 12, 38 | character: 10 39 | }, 40 | end: { 41 | line: 12, 42 | character: 14 43 | }, 44 | name: '', 45 | kind: 'string' 46 | }, 47 | { 48 | key: 1, 49 | start: { 50 | line: 12, 51 | character: 16 52 | }, 53 | end: { 54 | line: 12, 55 | character: 25 56 | }, 57 | name: '', 58 | kind: 'array' 59 | } 60 | ], 61 | line: 12, 62 | character: 9 63 | }, 64 | { 65 | name: '', 66 | args: [ 67 | { 68 | key: 0, 69 | start: { 70 | line: 13, 71 | character: 9 72 | }, 73 | end: { 74 | line: 13, 75 | character: 10 76 | }, 77 | name: '', 78 | kind: 'number' 79 | }, 80 | { 81 | key: 1, 82 | start: { 83 | line: 13, 84 | character: 12 85 | }, 86 | end: { 87 | line: 13, 88 | character: 13 89 | }, 90 | name: '', 91 | kind: 'number' 92 | }, 93 | { 94 | key: 2, 95 | start: { 96 | line: 13, 97 | character: 15 98 | }, 99 | end: { 100 | line: 13, 101 | character: 16 102 | }, 103 | name: '', 104 | kind: 'number' 105 | } 106 | ], 107 | line: 13, 108 | character: 8 109 | } 110 | ]; 111 | 112 | expect(functionGroups).to.have.lengthOf(2); 113 | expect(functionGroups).to.deep.equal(expectedFunctionGroups); 114 | }); 115 | }); 116 | }); 117 | -------------------------------------------------------------------------------- /test/hints.test.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const path = require('path'); 3 | const { describe, it, before, after } = require('mocha'); 4 | const { expect } = require('chai'); 5 | const sinon = require('sinon'); 6 | const { sleep, examplesFolderPath } = require('./utils'); 7 | const { FunctionGroupsFacade } = require('../src/functionGroupsFacade'); 8 | const { CacheService } = require('../src/cache'); 9 | const getHints = require('../src/parameterExtractor'); 10 | const Hints = require('../src/hints'); 11 | 12 | describe('hints', () => { 13 | /** @type {{text: string, range: vscode.Range}} */ 14 | let hint; 15 | 16 | before(async () => { 17 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}general.php`)); 18 | const document = await vscode.workspace.openTextDocument(uri); 19 | const editor = await vscode.window.showTextDocument(document); 20 | await sleep(500); // wait for file to be completely functional 21 | const [functionGroup] = await new FunctionGroupsFacade(new CacheService()).get( 22 | editor.document.uri.toString(), 23 | editor.document.getText() 24 | ); 25 | [hint] = await getHints(new Map(), functionGroup, editor); 26 | }); 27 | after(async () => { 28 | sinon.restore(); 29 | await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); 30 | }); 31 | 32 | it('should have the correct range', () => { 33 | const { range } = Hints.paramHint(hint.text, hint.range); 34 | expect(range.start.line).to.equal(hint.range.start.line); 35 | expect(range.start.character).to.equal(hint.range.start.character); 36 | expect(range.end.line).to.equal(hint.range.end.line); 37 | expect(range.end.character).to.equal(hint.range.end.character); 38 | }); 39 | it('should have the correct css props', () => { 40 | const stub = sinon.stub(vscode.workspace, 'getConfiguration'); 41 | const getStub = sinon.stub(); 42 | stub.withArgs('phpParameterHint').returns({ 43 | get: getStub, 44 | has: sinon.fake(), 45 | inspect: sinon.fake(), 46 | update: sinon.fake() 47 | }); 48 | const expectedOpacity = 0.5; 49 | const expectedFontStyle = 'bold'; 50 | const expectedFontWeight = 500; 51 | const expectedFontSize = 13; 52 | const expectedBorderRadius = 6; 53 | const expectedVerticalPadding = 2; 54 | const expectedHorizontalPadding = 5; 55 | const expectedMargin = 3; 56 | const expectedColor = { 57 | id: 'phpParameterHint.hintForeground' 58 | }; 59 | const expectedBackgroundColor = { 60 | id: 'phpParameterHint.hintBackground' 61 | }; 62 | 63 | getStub 64 | .withArgs('opacity') 65 | .returns(expectedOpacity) 66 | .withArgs('fontStyle') 67 | .returns(expectedFontStyle) 68 | .withArgs('fontWeight') 69 | .returns(expectedFontWeight) 70 | .withArgs('fontSize') 71 | .returns(expectedFontSize) 72 | .withArgs('borderRadius') 73 | .returns(expectedBorderRadius) 74 | .withArgs('verticalPadding') 75 | .returns(expectedVerticalPadding) 76 | .withArgs('horizontalPadding') 77 | .returns(expectedHorizontalPadding) 78 | .withArgs('margin') 79 | .returns(expectedMargin); 80 | 81 | const { 82 | renderOptions: { 83 | before: { 84 | opacity, 85 | contentText, 86 | color, 87 | backgroundColor, 88 | margin, 89 | fontStyle, 90 | fontWeight, 91 | borderRadius 92 | } 93 | } 94 | } = Hints.paramHint(hint.text, hint.range); 95 | expect(opacity).to.equal(expectedOpacity); 96 | expect(color).to.deep.equal(expectedColor); 97 | expect(backgroundColor).to.deep.equal(expectedBackgroundColor); 98 | expect(fontStyle).to.equal(expectedFontStyle); 99 | expect(fontWeight).to.equal(`${expectedFontWeight};font-size:${expectedFontSize}px;`); 100 | expect(contentText).to.equal(hint.text); 101 | expect(borderRadius).to.equal(`${expectedBorderRadius}px`); 102 | expect(opacity).to.equal(expectedOpacity); 103 | expect(margin).to.equal( 104 | `0px ${expectedMargin + 105 | 1}px 0px ${expectedMargin}px;padding: ${expectedVerticalPadding}px ${expectedHorizontalPadding}px;` 106 | ); 107 | }); 108 | }); 109 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const path = require('path'); 3 | const Mocha = require('mocha'); 4 | const glob = require('glob'); 5 | const { sleep, examplesFolderPath } = require('./utils'); 6 | 7 | function run() { 8 | process.env.NODE_ENV = 'test'; 9 | // Create the mocha test 10 | const mocha = new Mocha({ 11 | ui: 'tdd', 12 | color: true, 13 | timeout: '600s' 14 | }); 15 | 16 | const testsRoot = path.resolve(__dirname, '..'); 17 | 18 | return new Promise((c, e) => { 19 | glob('test/**/**.test.js', { cwd: testsRoot }, (err, files) => { 20 | if (err) { 21 | e(err); 22 | return; 23 | } 24 | 25 | // Add files to the test suite 26 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); 27 | mocha.rootHooks({ 28 | beforeAll: async () => { 29 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}general.php`)); 30 | const document = await vscode.workspace.openTextDocument(uri); 31 | await vscode.window.showTextDocument(document); 32 | await sleep(4000); // wait for file to be completely functional 33 | } 34 | }); 35 | 36 | try { 37 | // Run the mocha test 38 | mocha.run(failures => { 39 | if (failures > 0) { 40 | e(new Error(`${failures} tests failed.`)); 41 | } else { 42 | c(); 43 | } 44 | }); 45 | } catch (error) { 46 | // eslint-disable-next-line no-console 47 | console.error(error); 48 | e(error); 49 | } 50 | }); 51 | }); 52 | } 53 | 54 | module.exports = { 55 | run 56 | }; 57 | -------------------------------------------------------------------------------- /test/middlewares.test.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const path = require('path'); 3 | const { describe, it, before, afterEach, after } = require('mocha'); 4 | const { expect } = require('chai'); 5 | const { getCopyFunc } = require('../src/utils'); 6 | const { sleep, examplesFolderPath } = require('./utils'); 7 | const { FunctionGroupsFacade } = require('../src/functionGroupsFacade'); 8 | const { CacheService } = require('../src/cache'); 9 | const { onlyLiterals, onlySelection, onlyVisibleRanges } = require('../src/middlewares'); 10 | const { Pipeline } = require('../src/pipeline'); 11 | 12 | const copy = getCopyFunc(); 13 | 14 | describe('middlewares', () => { 15 | /** @type {vscode.TextEditor} */ 16 | let editor; 17 | let initialFunctionGroups; 18 | 19 | before(async () => { 20 | const functionGroupsFacade = new FunctionGroupsFacade(new CacheService()); 21 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}middlewares.php`)); 22 | const document = await vscode.workspace.openTextDocument(uri); 23 | editor = await vscode.window.showTextDocument(document); 24 | await sleep(500); // wait for file to be completely functional 25 | initialFunctionGroups = await functionGroupsFacade.get( 26 | editor.document.uri.toString(), 27 | editor.document.getText() 28 | ); 29 | }); 30 | 31 | describe('onlyLiterals', () => { 32 | it('should return only function groups and args with literals when called with should apply true', () => { 33 | // @ts-ignore 34 | const onlyLiteralsFunctionGroups = onlyLiterals(copy(initialFunctionGroups), true); 35 | const expectedFunctionGroups = [ 36 | { 37 | name: '', 38 | args: [ 39 | { 40 | key: 0, 41 | start: { 42 | line: 3, 43 | character: 5 44 | }, 45 | end: { 46 | line: 3, 47 | character: 9 48 | }, 49 | name: '', 50 | kind: 'string' 51 | } 52 | ], 53 | line: 3, 54 | character: 4 55 | }, 56 | { 57 | name: '', 58 | args: [ 59 | { 60 | key: 0, 61 | start: { 62 | line: 5, 63 | character: 24 64 | }, 65 | end: { 66 | line: 5, 67 | character: 35 68 | }, 69 | name: '', 70 | kind: 'string' 71 | } 72 | ], 73 | line: 5, 74 | character: 23 75 | }, 76 | { 77 | name: '', 78 | args: [ 79 | { 80 | key: 0, 81 | start: { 82 | line: 98, 83 | character: 32 84 | }, 85 | end: { 86 | line: 98, 87 | character: 45 88 | }, 89 | name: '', 90 | kind: 'string' 91 | } 92 | ], 93 | line: 98, 94 | character: 31 95 | } 96 | ]; 97 | expect(onlyLiteralsFunctionGroups).to.deep.equal(expectedFunctionGroups); 98 | }); 99 | it('should return the same function groups when called with should apply false', () => { 100 | // @ts-ignore 101 | const onlyLiteralsFunctionGroups = onlyLiterals(copy(initialFunctionGroups), false); 102 | expect(initialFunctionGroups).to.deep.equal(onlyLiteralsFunctionGroups); 103 | }); 104 | }); 105 | describe('onlySelection', () => { 106 | before(() => { 107 | const { range } = editor.document.lineAt(5); 108 | editor.selection = new vscode.Selection(range.start, range.end); 109 | editor.revealRange(range); 110 | }); 111 | it('should return hints only for current line/selection when called with should apply true', () => { 112 | // @ts-ignore 113 | const selectionFunctionGroups = onlySelection(copy(initialFunctionGroups), editor, true); 114 | const expectedFunctionGroups = [ 115 | { 116 | name: '', 117 | args: [ 118 | { 119 | key: 0, 120 | start: { 121 | line: 5, 122 | character: 24 123 | }, 124 | end: { 125 | line: 5, 126 | character: 35 127 | }, 128 | name: '', 129 | kind: 'string' 130 | } 131 | ], 132 | line: 5, 133 | character: 23 134 | } 135 | ]; 136 | expect(selectionFunctionGroups).to.deep.equal(expectedFunctionGroups); 137 | }); 138 | it('should return the same function groups when called with should apply false', () => { 139 | // @ts-ignore 140 | const selectionFunctionGroups = onlySelection(copy(initialFunctionGroups), editor, false); 141 | expect(selectionFunctionGroups).to.deep.equal(initialFunctionGroups); 142 | }); 143 | }); 144 | describe('onlyVisibleRanges', () => { 145 | it('should return hints only for visible ranges when called with should apply true', () => { 146 | const visibleRangesFunctionGroups = onlyVisibleRanges( 147 | // @ts-ignore 148 | copy(initialFunctionGroups), 149 | editor, 150 | true 151 | ); 152 | const expectedFunctionGroups = [ 153 | { 154 | name: '', 155 | args: [ 156 | { 157 | key: 0, 158 | start: { 159 | line: 3, 160 | character: 5 161 | }, 162 | end: { 163 | line: 3, 164 | character: 9 165 | }, 166 | name: '', 167 | kind: 'string' 168 | }, 169 | { 170 | key: 1, 171 | start: { 172 | line: 3, 173 | character: 11 174 | }, 175 | end: { 176 | line: 3, 177 | character: 19 178 | }, 179 | name: 'numbers', 180 | kind: 'variable' 181 | } 182 | ], 183 | line: 3, 184 | character: 4 185 | }, 186 | { 187 | name: '', 188 | args: [ 189 | { 190 | key: 0, 191 | start: { 192 | line: 5, 193 | character: 24 194 | }, 195 | end: { 196 | line: 5, 197 | character: 35 198 | }, 199 | name: '', 200 | kind: 'string' 201 | } 202 | ], 203 | line: 5, 204 | character: 23 205 | } 206 | ]; 207 | expect(visibleRangesFunctionGroups).to.deep.equal(expectedFunctionGroups); 208 | }); 209 | it('should return the same function groups when called with should apply false', () => { 210 | const visibleRangesFunctionGroups = onlyVisibleRanges( 211 | // @ts-ignore 212 | copy(initialFunctionGroups), 213 | editor, 214 | false 215 | ); 216 | expect(initialFunctionGroups).to.deep.equal(visibleRangesFunctionGroups); 217 | }); 218 | describe('', () => { 219 | before(async () => { 220 | const lastLine = editor.document.lineCount - 1; 221 | const { range } = editor.document.lineAt(lastLine); 222 | editor.selection = new vscode.Selection(range.start, range.end); 223 | editor.revealRange(range); 224 | await sleep(500); // wait for editor to scroll 225 | }); 226 | after(async () => { 227 | const { range } = editor.document.lineAt(0); 228 | editor.selection = new vscode.Selection(range.start, range.end); 229 | editor.revealRange(range); 230 | await sleep(500); // wait for editor to scroll 231 | }); 232 | 233 | it('should return the new function groups after visible ranges change', async () => { 234 | const visibleRangesFunctionGroups = onlyVisibleRanges( 235 | // @ts-ignore 236 | copy(initialFunctionGroups), 237 | editor, 238 | true 239 | ); 240 | const expectedFunctionGroups = [ 241 | { 242 | name: '', 243 | args: [ 244 | { 245 | key: 0, 246 | start: { 247 | line: 98, 248 | character: 32 249 | }, 250 | end: { 251 | line: 98, 252 | character: 45 253 | }, 254 | name: '', 255 | kind: 'string' 256 | } 257 | ], 258 | line: 98, 259 | character: 31 260 | } 261 | ]; 262 | expect(expectedFunctionGroups).to.deep.equal(visibleRangesFunctionGroups); 263 | }); 264 | }); 265 | }); 266 | describe('combination of middlewares', () => { 267 | const pipeline = new Pipeline(); 268 | 269 | afterEach(() => { 270 | pipeline.clear(); 271 | }); 272 | 273 | it('should return only literals and in visible ranges function groups', async () => { 274 | const onlyLiteralsAndVisibleRangesFunctionGroups = await pipeline 275 | .pipe([onlyLiterals, true], [onlyVisibleRanges, editor, true]) 276 | // @ts-ignore 277 | .process(copy(initialFunctionGroups)); 278 | const expectedFunctionGroups = [ 279 | { 280 | name: '', 281 | args: [ 282 | { 283 | key: 0, 284 | start: { 285 | line: 3, 286 | character: 5 287 | }, 288 | end: { 289 | line: 3, 290 | character: 9 291 | }, 292 | name: '', 293 | kind: 'string' 294 | } 295 | ], 296 | line: 3, 297 | character: 4 298 | }, 299 | { 300 | name: '', 301 | args: [ 302 | { 303 | key: 0, 304 | start: { 305 | line: 5, 306 | character: 24 307 | }, 308 | end: { 309 | line: 5, 310 | character: 35 311 | }, 312 | name: '', 313 | kind: 'string' 314 | } 315 | ], 316 | line: 5, 317 | character: 23 318 | } 319 | ]; 320 | expect(onlyLiteralsAndVisibleRangesFunctionGroups).to.deep.equal(expectedFunctionGroups); 321 | }); 322 | it('should return the same function groups when all middlewares are called with should apply false', async () => { 323 | const onlyLiteralsAndVisibleRangesFunctionGroups = await pipeline 324 | .pipe([onlyLiterals, false], [onlyVisibleRanges, editor, false]) 325 | // @ts-ignore 326 | .process(copy(initialFunctionGroups)); 327 | expect(onlyLiteralsAndVisibleRangesFunctionGroups).to.deep.equal(initialFunctionGroups); 328 | }); 329 | }); 330 | }); 331 | -------------------------------------------------------------------------------- /test/parameterExtractor.test.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const path = require('path'); 3 | const { describe, it, after, before } = require('mocha'); 4 | const { expect } = require('chai'); 5 | const { getCopyFunc } = require('../src/utils'); 6 | const { FunctionGroupsFacade } = require('../src/functionGroupsFacade'); 7 | const { CacheService } = require('../src/cache'); 8 | const getHints = require('../src/parameterExtractor'); 9 | const { sleep, examplesFolderPath } = require('./utils'); 10 | 11 | const copy = getCopyFunc(); 12 | 13 | describe('parameterExtractor', () => { 14 | describe('getHints', () => { 15 | const compareHints = (hints, expectedHints) => { 16 | hints.forEach((hintGroups, indexGroup) => { 17 | hintGroups.forEach((hint, index) => { 18 | expect(hint.text).to.deep.equal(expectedHints[indexGroup][index].text); 19 | expect(hint.range.start.line).to.deep.equal( 20 | expectedHints[indexGroup][index].range.start.line 21 | ); 22 | expect(hint.range.start.character).to.deep.equal( 23 | expectedHints[indexGroup][index].range.start.character 24 | ); 25 | expect(hint.range.end.line).to.deep.equal( 26 | expectedHints[indexGroup][index].range.end.line 27 | ); 28 | expect(hint.range.end.character).to.deep.equal( 29 | expectedHints[indexGroup][index].range.end.character 30 | ); 31 | }); 32 | }); 33 | }; 34 | 35 | describe('general', () => { 36 | let functionGroupsLen; 37 | let functionDictionary; 38 | let expectedNameHints; 39 | const { Range, Position } = vscode; 40 | let editor; 41 | let functionGroups; 42 | 43 | before(async () => { 44 | const functionGroupsFacade = new FunctionGroupsFacade(new CacheService()); 45 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}general.php`)); 46 | const document = await vscode.workspace.openTextDocument(uri); 47 | editor = await vscode.window.showTextDocument(document); 48 | await sleep(500); // wait for file to fully load 49 | functionGroups = await functionGroupsFacade.get( 50 | editor.document.uri.toString(), 51 | editor.document.getText() 52 | ); 53 | functionGroupsLen = functionGroups.length; 54 | functionDictionary = new Map(); 55 | 56 | expectedNameHints = [ 57 | [ 58 | { 59 | text: 'glue:', 60 | range: new Range(new Position(12, 10), new Position(12, 14)) 61 | }, 62 | { 63 | text: 'pieces:', 64 | range: new Range(new Position(12, 16), new Position(12, 25)) 65 | } 66 | ], 67 | [ 68 | { 69 | text: 'vars[0]:', 70 | range: new Range(new Position(13, 9), new Position(13, 10)) 71 | }, 72 | { 73 | text: 'vars[1]:', 74 | range: new Range(new Position(13, 12), new Position(13, 13)) 75 | }, 76 | { 77 | text: 'vars[2]:', 78 | range: new Range(new Position(13, 15), new Position(13, 16)) 79 | } 80 | ] 81 | ]; 82 | }); 83 | after(async () => { 84 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 0, true); 85 | await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); 86 | await sleep(500); 87 | }); 88 | 89 | const compare = (hints, expectedHints) => { 90 | expect(hints).to.have.lengthOf(2); 91 | expect(hints[0]).to.have.lengthOf(2); 92 | expect(hints[1]).to.have.lengthOf(3); 93 | 94 | compareHints(hints, expectedHints); 95 | }; 96 | 97 | it('should return name hints', async () => { 98 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 0, true); 99 | const hints = []; 100 | 101 | for (let index = 0; index < functionGroupsLen; index += 1) { 102 | const functionGroup = functionGroups[index]; 103 | try { 104 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 105 | // eslint-disable-next-line no-empty 106 | } catch (err) {} 107 | } 108 | 109 | compare(hints, expectedNameHints); 110 | }); 111 | it('should return type and name hints', async () => { 112 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 1, true); 113 | // @ts-ignore 114 | const expectedTypeAndNameHints = copy(expectedNameHints); 115 | expectedTypeAndNameHints[0][0].text = 'string glue:'; 116 | expectedTypeAndNameHints[0][1].text = 'array pieces:'; 117 | expectedTypeAndNameHints[1][0].text = 'int vars[0]:'; 118 | expectedTypeAndNameHints[1][1].text = 'int vars[1]:'; 119 | expectedTypeAndNameHints[1][2].text = 'int vars[2]:'; 120 | const hints = []; 121 | 122 | for (let index = 0; index < functionGroupsLen; index += 1) { 123 | const functionGroup = functionGroups[index]; 124 | try { 125 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 126 | // eslint-disable-next-line no-empty 127 | } catch (err) {} 128 | } 129 | 130 | compare(hints, expectedTypeAndNameHints); 131 | }); 132 | 133 | it('should return type hints', async () => { 134 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 2, true); 135 | // @ts-ignore 136 | const expectedTypeHints = copy(expectedNameHints); 137 | expectedTypeHints[0][0].text = 'string:'; 138 | expectedTypeHints[0][1].text = 'array:'; 139 | expectedTypeHints[1][0].text = 'int[0]:'; 140 | expectedTypeHints[1][1].text = 'int[1]:'; 141 | expectedTypeHints[1][2].text = 'int[2]:'; 142 | const hints = []; 143 | 144 | for (let index = 0; index < functionGroupsLen; index += 1) { 145 | const functionGroup = functionGroups[index]; 146 | try { 147 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 148 | // eslint-disable-next-line no-empty 149 | } catch (err) {} 150 | } 151 | 152 | compare(hints, expectedTypeHints); 153 | }); 154 | }); 155 | describe('showDollarSign', () => { 156 | let functionGroupsLen; 157 | let functionDictionary; 158 | let expectedHints; 159 | const { Range, Position } = vscode; 160 | let editor; 161 | let functionGroups; 162 | 163 | before(async () => { 164 | const functionGroupsFacade = new FunctionGroupsFacade(new CacheService()); 165 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}showDollarSign.php`)); 166 | const document = await vscode.workspace.openTextDocument(uri); 167 | editor = await vscode.window.showTextDocument(document); 168 | await sleep(500); // wait for file to fully load 169 | functionGroups = await functionGroupsFacade.get( 170 | editor.document.uri.toString(), 171 | editor.document.getText() 172 | ); 173 | functionGroupsLen = functionGroups.length; 174 | functionDictionary = new Map(); 175 | 176 | expectedHints = [ 177 | [ 178 | { 179 | text: 'str:', 180 | range: new Range(new Position(2, 16), new Position(2, 21)) 181 | } 182 | ] 183 | ]; 184 | }); 185 | after(async () => { 186 | await vscode.workspace 187 | .getConfiguration('phpParameterHint') 188 | .update('showDollarSign', false, true); 189 | await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); 190 | await sleep(500); 191 | }); 192 | 193 | const compare = (hints, expected) => { 194 | expect(hints).to.have.lengthOf(1); 195 | expect(hints[0]).to.have.lengthOf(1); 196 | compareHints(hints, expected); 197 | }; 198 | 199 | it('should return hints with parameter name without the dollar sign', async () => { 200 | await vscode.workspace 201 | .getConfiguration('phpParameterHint') 202 | .update('showDollarSign', false, true); 203 | const hints = []; 204 | 205 | for (let index = 0; index < functionGroupsLen; index += 1) { 206 | const functionGroup = functionGroups[index]; 207 | try { 208 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 209 | // eslint-disable-next-line no-empty 210 | } catch (err) {} 211 | } 212 | 213 | compare(hints, expectedHints); 214 | }); 215 | it('should return hints with parameter name with dollar sign', async () => { 216 | await vscode.workspace 217 | .getConfiguration('phpParameterHint') 218 | .update('showDollarSign', true, true); 219 | const hints = []; 220 | // @ts-ignore 221 | const expectedDollarHints = copy(expectedHints); 222 | expectedDollarHints[0][0].text = '$str:'; 223 | 224 | for (let index = 0; index < functionGroupsLen; index += 1) { 225 | const functionGroup = functionGroups[index]; 226 | try { 227 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 228 | // eslint-disable-next-line no-empty 229 | } catch (err) {} 230 | } 231 | 232 | compare(hints, expectedDollarHints); 233 | }); 234 | }); 235 | describe('showFullType', () => { 236 | let functionGroupsLen; 237 | let functionDictionary; 238 | let expectedHints; 239 | const { Range, Position } = vscode; 240 | let editor; 241 | let functionGroups; 242 | 243 | before(async () => { 244 | const functionGroupsFacade = new FunctionGroupsFacade(new CacheService()); 245 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}showFullType.php`)); 246 | const document = await vscode.workspace.openTextDocument(uri); 247 | editor = await vscode.window.showTextDocument(document); 248 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 2, true); // hint only type 249 | await sleep(500); // wait for file to fully load 250 | functionGroups = await functionGroupsFacade.get( 251 | editor.document.uri.toString(), 252 | editor.document.getText() 253 | ); 254 | functionGroupsLen = functionGroups.length; 255 | functionDictionary = new Map(); 256 | 257 | expectedHints = [ 258 | [ 259 | { 260 | text: 'User:', 261 | range: new Range(new Position(8, 8), new Position(8, 18)) 262 | } 263 | ] 264 | ]; 265 | }); 266 | after(async () => { 267 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 0, true); 268 | await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); 269 | await vscode.workspace 270 | .getConfiguration('phpParameterHint') 271 | .update('showFullType', false, true); 272 | await sleep(500); 273 | }); 274 | 275 | const compare = (hints, expected) => { 276 | expect(hints).to.have.lengthOf(1); 277 | expect(hints[0]).to.have.lengthOf(1); 278 | compareHints(hints, expected); 279 | }; 280 | 281 | it('should return hints with short type', async () => { 282 | await vscode.workspace 283 | .getConfiguration('phpParameterHint') 284 | .update('showFullType', false, true); 285 | const hints = []; 286 | 287 | for (let index = 0; index < functionGroupsLen; index += 1) { 288 | const functionGroup = functionGroups[index]; 289 | try { 290 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 291 | // eslint-disable-next-line no-empty 292 | } catch (err) {} 293 | } 294 | 295 | compare(hints, expectedHints); 296 | }); 297 | it('should return hints with full type', async () => { 298 | await vscode.workspace 299 | .getConfiguration('phpParameterHint') 300 | .update('showFullType', true, true); 301 | const hints = []; 302 | // @ts-ignore 303 | const expectedFullTypeHints = copy(expectedHints); 304 | expectedFullTypeHints[0][0].text = 'Models\\User:'; 305 | 306 | for (let index = 0; index < functionGroupsLen; index += 1) { 307 | const functionGroup = functionGroups[index]; 308 | try { 309 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 310 | // eslint-disable-next-line no-empty 311 | } catch (err) {} 312 | } 313 | 314 | compare(hints, expectedFullTypeHints); 315 | }); 316 | }); 317 | describe('collapseHintsWhenEqual', () => { 318 | let functionGroupsLen; 319 | let functionDictionary; 320 | let expectedHints; 321 | const { Range, Position } = vscode; 322 | let editor; 323 | let functionGroups; 324 | 325 | before(async () => { 326 | const functionGroupsFacade = new FunctionGroupsFacade(new CacheService()); 327 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}collapseHintsWhenEqual.php`)); 328 | const document = await vscode.workspace.openTextDocument(uri); 329 | editor = await vscode.window.showTextDocument(document); 330 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 0, true); // hint only parameter name 331 | await sleep(500); // wait for file to fully load 332 | functionGroups = await functionGroupsFacade.get( 333 | editor.document.uri.toString(), 334 | editor.document.getText() 335 | ); 336 | functionGroupsLen = functionGroups.length; 337 | functionDictionary = new Map(); 338 | 339 | expectedHints = [ 340 | [ 341 | { 342 | text: 'string:', 343 | range: new Range(new Position(3, 16), new Position(3, 23)) 344 | } 345 | ] 346 | ]; 347 | }); 348 | after(async () => { 349 | await vscode.workspace 350 | .getConfiguration('phpParameterHint') 351 | .update('collapseHintsWhenEqual', false, true); 352 | await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); 353 | await sleep(500); 354 | }); 355 | 356 | const compare = (hints, expected) => { 357 | expect(hints).to.have.lengthOf(1); 358 | expect(hints[0]).to.have.lengthOf(1); 359 | compareHints(hints, expected); 360 | }; 361 | 362 | it('should return the hint', async () => { 363 | await vscode.workspace 364 | .getConfiguration('phpParameterHint') 365 | .update('collapseHintsWhenEqual', false, true); 366 | const hints = []; 367 | 368 | for (let index = 0; index < functionGroupsLen; index += 1) { 369 | const functionGroup = functionGroups[index]; 370 | try { 371 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 372 | // eslint-disable-next-line no-empty 373 | } catch (err) {} 374 | } 375 | 376 | compare(hints, expectedHints); 377 | }); 378 | it('should not return the hint because the var name matches the parameter name', async () => { 379 | await vscode.workspace 380 | .getConfiguration('phpParameterHint') 381 | .update('collapseHintsWhenEqual', true, true); 382 | const hints = []; 383 | 384 | for (let index = 0; index < functionGroupsLen; index += 1) { 385 | const functionGroup = functionGroups[index]; 386 | try { 387 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 388 | // eslint-disable-next-line no-empty 389 | } catch (err) {} 390 | } 391 | 392 | expect(hints).to.have.lengthOf(1); 393 | expect(hints[0]).to.have.lengthOf(0); 394 | }); 395 | }); 396 | describe('collapseTypeWhenEqual', () => { 397 | let functionGroupsLen; 398 | let functionDictionary; 399 | let expectedHints; 400 | const { Range, Position } = vscode; 401 | let editor; 402 | let functionGroups; 403 | 404 | before(async () => { 405 | const functionGroupsFacade = new FunctionGroupsFacade(new CacheService()); 406 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}collapseTypeWhenEqual.php`)); 407 | const document = await vscode.workspace.openTextDocument(uri); 408 | editor = await vscode.window.showTextDocument(document); 409 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 1, true); // hint type and name 410 | await sleep(500); // wait for file to fully load 411 | functionGroups = await functionGroupsFacade.get( 412 | editor.document.uri.toString(), 413 | editor.document.getText() 414 | ); 415 | functionGroupsLen = functionGroups.length; 416 | functionDictionary = new Map(); 417 | 418 | expectedHints = [ 419 | [ 420 | { 421 | text: 'string string:', 422 | range: new Range(new Position(3, 16), new Position(3, 23)) 423 | } 424 | ] 425 | ]; 426 | }); 427 | after(async () => { 428 | await vscode.workspace.getConfiguration('phpParameterHint').update('hintTypeName', 0, true); // hint type and name 429 | await vscode.workspace 430 | .getConfiguration('phpParameterHint') 431 | .update('collapseTypeWhenEqual', false, true); // hint type and name 432 | await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); 433 | await sleep(500); 434 | }); 435 | 436 | const compare = (hints, expected) => { 437 | expect(hints).to.have.lengthOf(1); 438 | expect(hints[0]).to.have.lengthOf(1); 439 | compareHints(hints, expected); 440 | }; 441 | 442 | it('should return the hint with both type and name', async () => { 443 | await vscode.workspace 444 | .getConfiguration('phpParameterHint') 445 | .update('collapseTypeWhenEqual', false, true); 446 | const hints = []; 447 | 448 | for (let index = 0; index < functionGroupsLen; index += 1) { 449 | const functionGroup = functionGroups[index]; 450 | try { 451 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 452 | // eslint-disable-next-line no-empty 453 | } catch (err) {} 454 | } 455 | 456 | compare(hints, expectedHints); 457 | }); 458 | it('should return the hint only with parameter name because it matches with the type', async () => { 459 | await vscode.workspace 460 | .getConfiguration('phpParameterHint') 461 | .update('collapseTypeWhenEqual', true, true); 462 | const hints = []; 463 | // @ts-ignore 464 | const expectedCollapseTypeHints = copy(expectedHints); 465 | expectedCollapseTypeHints[0][0].text = 'string:'; 466 | 467 | for (let index = 0; index < functionGroupsLen; index += 1) { 468 | const functionGroup = functionGroups[index]; 469 | try { 470 | hints.push(await getHints(functionDictionary, functionGroup, editor)); 471 | // eslint-disable-next-line no-empty 472 | } catch (err) {} 473 | } 474 | 475 | compare(hints, expectedCollapseTypeHints); 476 | }); 477 | }); 478 | }); 479 | }); 480 | -------------------------------------------------------------------------------- /test/providers.test.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const path = require('path'); 3 | const { describe, it, before, after } = require('mocha'); 4 | const { expect } = require('chai'); 5 | const { sleep, examplesFolderPath } = require('./utils'); 6 | const { FunctionGroupsFacade } = require('../src/functionGroupsFacade'); 7 | const { CacheService } = require('../src/cache'); 8 | const signature = require('../src/providers/signature'); 9 | const hover = require('../src/providers/hover'); 10 | 11 | describe('providers', () => { 12 | /** @type {vscode.TextEditor} */ 13 | let editor; 14 | let functionGroups; 15 | 16 | before(async () => { 17 | const functionGroupsFacade = new FunctionGroupsFacade(new CacheService()); 18 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}providers.php`)); 19 | const document = await vscode.workspace.openTextDocument(uri); 20 | editor = await vscode.window.showTextDocument(document); 21 | await sleep(500); // wait for file to be completely functional 22 | functionGroups = await functionGroupsFacade.get( 23 | editor.document.uri.toString(), 24 | editor.document.getText() 25 | ); 26 | }); 27 | after(async () => { 28 | await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); 29 | }); 30 | 31 | const getArgs = async (provider, showType) => { 32 | /** @type {array} */ 33 | const args = await Promise.all( 34 | functionGroups.map(functionGroup => { 35 | const line = provider === signature ? functionGroup.args[0].start.line : functionGroup.line; 36 | const character = 37 | provider === signature ? functionGroup.args[0].start.character : functionGroup.character; 38 | return provider.getArgs(editor, line, character, showType); 39 | }) 40 | ); 41 | 42 | // @ts-ignore 43 | return args.flat(); 44 | }; 45 | const providers = [ 46 | { 47 | name: 'signature', 48 | func: signature 49 | }, 50 | { 51 | name: 'hover', 52 | func: hover 53 | } 54 | ]; 55 | 56 | for (const provider of providers) { 57 | describe(provider.name, () => { 58 | it('should return only parameters names', async () => { 59 | const args = await getArgs(provider.func, 'disabled'); 60 | const expectedArgs = ['$glue', '$pieces', '$name', '...$ages']; 61 | expect(args).to.deep.equal(expectedArgs); 62 | }); 63 | it('should return parameters names and types', async () => { 64 | let args = await getArgs(provider.func, 'type and name'); 65 | const expectedArgs = ['string $glue', 'array $pieces', 'string $name', 'mixed ...$ages']; 66 | expect(args).to.deep.equal(expectedArgs); 67 | args = await getArgs(provider.func, 'type'); 68 | expect(args).to.deep.equal(expectedArgs); 69 | }); 70 | }); 71 | } 72 | }); 73 | -------------------------------------------------------------------------------- /test/runTest.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | const path = require('path'); 3 | const cp = require('child_process'); 4 | const { 5 | runTests, 6 | resolveCliPathFromVSCodeExecutablePath, 7 | downloadAndUnzipVSCode 8 | } = require('vscode-test'); 9 | 10 | async function main() { 11 | try { 12 | // The folder containing the Extension Manifest package.json 13 | // Passed to `--extensionDevelopmentPath` 14 | const extensionDevelopmentPath = path.resolve(__dirname, '../'); 15 | 16 | // The path to the extension test runner script 17 | // Passed to --extensionTestsPath 18 | const extensionTestsPath = path.resolve(__dirname, './index'); 19 | const vscodeExecutablePath = await downloadAndUnzipVSCode('insiders'); 20 | const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath); 21 | 22 | // Use cp.spawn / cp.exec for custom setup 23 | cp.spawnSync(cliPath, ['--install-extension', 'bmewburn.vscode-intelephense-client'], { 24 | encoding: 'utf-8', 25 | stdio: 'inherit' 26 | }); 27 | 28 | // Download VS Code, unzip it and run the integration test 29 | await runTests({ 30 | vscodeExecutablePath, 31 | extensionDevelopmentPath, 32 | extensionTestsPath 33 | }); 34 | } catch (err) { 35 | console.error(err); 36 | console.error('Failed to run tests'); 37 | process.exit(1); 38 | } 39 | } 40 | 41 | main(); 42 | -------------------------------------------------------------------------------- /test/update.test.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | const path = require('path'); 3 | const { describe, it, before, after } = require('mocha'); 4 | const { expect } = require('chai'); 5 | const { sleep, examplesFolderPath } = require('./utils'); 6 | const { FunctionGroupsFacade } = require('../src/functionGroupsFacade'); 7 | const { CacheService } = require('../src/cache'); 8 | const { update } = require('../src/update'); 9 | 10 | describe('update', () => { 11 | /** @type {vscode.TextEditor} */ 12 | let editor; 13 | let functionGroups; 14 | const expectedDecorations = [ 15 | { 16 | range: new vscode.Range(new vscode.Position(12, 10), new vscode.Position(12, 14)), 17 | renderOptions: { 18 | before: { 19 | opacity: 0.4, 20 | color: { 21 | id: 'phpParameterHint.hintForeground' 22 | }, 23 | contentText: 'glue:', 24 | backgroundColor: { 25 | id: 'phpParameterHint.hintBackground' 26 | }, 27 | margin: '0px 3px 0px 2px;padding: 1px 4px;', 28 | borderRadius: '5px', 29 | fontStyle: 'italic', 30 | fontWeight: '400;font-size:12px;' 31 | } 32 | } 33 | }, 34 | { 35 | range: new vscode.Range(new vscode.Position(12, 16), new vscode.Position(12, 25)), 36 | renderOptions: { 37 | before: { 38 | opacity: 0.4, 39 | color: { 40 | id: 'phpParameterHint.hintForeground' 41 | }, 42 | contentText: 'pieces:', 43 | backgroundColor: { 44 | id: 'phpParameterHint.hintBackground' 45 | }, 46 | margin: '0px 3px 0px 2px;padding: 1px 4px;', 47 | borderRadius: '5px', 48 | fontStyle: 'italic', 49 | fontWeight: '400;font-size:12px;' 50 | } 51 | } 52 | }, 53 | { 54 | range: new vscode.Range(new vscode.Position(13, 9), new vscode.Position(13, 10)), 55 | renderOptions: { 56 | before: { 57 | opacity: 0.4, 58 | color: { 59 | id: 'phpParameterHint.hintForeground' 60 | }, 61 | contentText: 'vars[0]:', 62 | backgroundColor: { 63 | id: 'phpParameterHint.hintBackground' 64 | }, 65 | margin: '0px 3px 0px 2px;padding: 1px 4px;', 66 | borderRadius: '5px', 67 | fontStyle: 'italic', 68 | fontWeight: '400;font-size:12px;' 69 | } 70 | } 71 | }, 72 | { 73 | range: new vscode.Range(new vscode.Position(13, 12), new vscode.Position(13, 13)), 74 | renderOptions: { 75 | before: { 76 | opacity: 0.4, 77 | color: { 78 | id: 'phpParameterHint.hintForeground' 79 | }, 80 | contentText: 'vars[1]:', 81 | backgroundColor: { 82 | id: 'phpParameterHint.hintBackground' 83 | }, 84 | margin: '0px 3px 0px 2px;padding: 1px 4px;', 85 | borderRadius: '5px', 86 | fontStyle: 'italic', 87 | fontWeight: '400;font-size:12px;' 88 | } 89 | } 90 | }, 91 | { 92 | range: new vscode.Range(new vscode.Position(13, 15), new vscode.Position(13, 16)), 93 | renderOptions: { 94 | before: { 95 | opacity: 0.4, 96 | color: { 97 | id: 'phpParameterHint.hintForeground' 98 | }, 99 | contentText: 'vars[2]:', 100 | backgroundColor: { 101 | id: 'phpParameterHint.hintBackground' 102 | }, 103 | margin: '0px 3px 0px 2px;padding: 1px 4px;', 104 | borderRadius: '5px', 105 | fontStyle: 'italic', 106 | fontWeight: '400;font-size:12px;' 107 | } 108 | } 109 | } 110 | ]; 111 | 112 | before(async () => { 113 | const uri = vscode.Uri.file(path.join(`${examplesFolderPath}general.php`)); 114 | const document = await vscode.workspace.openTextDocument(uri); 115 | editor = await vscode.window.showTextDocument(document); 116 | await sleep(500); // wait for file to be completely functional 117 | functionGroups = await new FunctionGroupsFacade(new CacheService()).get( 118 | editor.document.uri.toString(), 119 | editor.document.getText() 120 | ); 121 | }); 122 | after(async () => { 123 | await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); 124 | }); 125 | 126 | it('should return the correct decorations', async () => { 127 | const decorations = await update(editor, functionGroups); 128 | expect(decorations).to.deep.equal(expectedDecorations); 129 | }); 130 | it('should cancel the first call and return null when a second one is made and the first one has not finished', async () => { 131 | const [firstDecorations, secondDecorations] = await Promise.all([ 132 | update(editor, functionGroups), 133 | update(editor, functionGroups) 134 | ]); 135 | expect(firstDecorations).to.be.null; 136 | expect(secondDecorations).to.deep.equal(expectedDecorations); 137 | }); 138 | }); 139 | -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | const sleep = ms => { 4 | return new Promise(resolve => { 5 | setTimeout(resolve, ms); 6 | }); 7 | }; 8 | 9 | const examplesFolderPath = path.join(`${__dirname}/examples/`); 10 | 11 | module.exports = { 12 | sleep, 13 | examplesFolderPath 14 | }; 15 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | const path = require('path'); 4 | 5 | /** @type {import('webpack').Configuration} */ 6 | const config = { 7 | target: 'node', 8 | entry: './src/extension.js', 9 | output: { 10 | path: path.resolve(__dirname, 'dist'), 11 | filename: 'extension.js', 12 | libraryTarget: 'commonjs2', 13 | devtoolModuleFilenameTemplate: '../[resource-path]' 14 | }, 15 | devtool: 'source-map', 16 | externals: { 17 | vscode: 'commonjs vscode' 18 | }, 19 | resolve: { 20 | extensions: ['.js'] 21 | } 22 | }; 23 | module.exports = config; 24 | --------------------------------------------------------------------------------